MATES 3.0-rc2

org.mates.sim
Class Host

java.lang.Object
  extended byorg.mates.sim.Host

public class Host
extends java.lang.Object

Author:
Evan Sultanik

Field Summary
protected  java.awt.Color MOUSEOVER_COLOR
          The color of a host when the mouse is held over it in the GUI.
protected  java.awt.Color RADIO_RANGE_COLOR
          The color of a host's radio range when it is drawn in the GUI.
protected  java.awt.Color SELECTED_COLOR
          The color of a host when it is selected in the GUI.
 
Constructor Summary
Host(double x, double y, MobilityModel mobilityModel, Simulator simulator)
          Constructs a host without a name.
Host(double x, double y, Simulator simulator)
          Constructs a host.
Host(java.lang.String name, double x, double y, MobilityModel mobilityModel, Simulator simulator)
          Primary constructor.
Host(java.lang.String name, double x, double y, Simulator simulator)
          Constructs a host with a StaticMobilityModel and Position2D position.
Host(java.lang.String name, Position position, MobilityModel mobilityModel, Simulator simulator)
          Primary constructor.
 
Method Summary
 void addAgent(Agent agent)
          Adds an agent to this host.
 boolean equals(java.lang.Object o)
           
 Agent getAgent(UniqueID id)
          Returns an agent on this host.
 Agent getAgentByName(java.lang.String name)
          Returns an agent on this host.
 java.util.Enumeration getAgents()
          Returns an Enumeration of the agents currently on this host.
 java.awt.Color getColor()
          Returns the color of this host, if it is to be displayed graphically.
 CPUSchedulingModel getCPUSchedulingModel()
          Returns this host's CPU scheduling model;
 MobilityModel getMobilityModel()
          Returns this host's mobility model.
 java.lang.String getName()
          Returns the name of this host.
 java.util.Vector getNeighbors()
          Conveniance function that calls getSimulator().
 java.util.Vector getNeighborsICanHear()
          Conveniance function that calls getSimulator().
 Position getPosition()
          Returns the current position of this host.
 double getRadioRange()
          Returns the radio range of this host.
 Simulator getSimulator()
          Returns the simulator in which this host was created.
 UniqueID getUniqueID()
          Returns the unique identifier for this host.
 int hashCode()
           
 boolean isContaining(int pixel_x, int pixel_y)
          Returns true if a the graphical representation of this host (as defined by paint(java.awt.Graphics)) contains the pixel at coordinate (x, y).
 void iterate()
          Called once per simulator iteration, it is this function's responsibility to schedule processing time for each of the agents currently on this host, respecting the agents' priorities.
 void paint(java.awt.Graphics graphics)
          Paints this host to a graphics object.
 void paintRadioRange(java.awt.Graphics graphics, boolean mouseover, boolean selected)
          Paints the radio range for this host to a graphics object.
 void removeAgent(Agent agent)
          Removes an agent from this host.
 void setColor(java.awt.Color color)
          Sets the color that this host should be displayed if a graphical user interface is chosen.
 void setCPUSchedulingModel(CPUSchedulingModel model)
          Sets the CPU scheduling model of this host.
 void setMobilityModel(MobilityModel model)
          Sets the mobility model of this host.
 boolean setPosition(Position newPosition)
          Sets the position of this host.
 void setRadioRange(double radio_range)
          Sets the radio range for this host.
 void setRadioRangeToDefault()
          Sets this host's radio range to the default radio range as defined by the simulator.
 java.lang.String toString()
          Returns the name of the current host and/or its unique ID.
 void updateAgentPriority(Agent agent)
          An internal function for updating this host to the fact that one of its agents has updated its priority.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SELECTED_COLOR

protected java.awt.Color SELECTED_COLOR
The color of a host when it is selected in the GUI.


MOUSEOVER_COLOR

protected java.awt.Color MOUSEOVER_COLOR
The color of a host when the mouse is held over it in the GUI.


RADIO_RANGE_COLOR

protected java.awt.Color RADIO_RANGE_COLOR
The color of a host's radio range when it is drawn in the GUI.

Constructor Detail

Host

public Host(java.lang.String name,
            Position position,
            MobilityModel mobilityModel,
            Simulator simulator)
Primary constructor. Uses a DefaultCPUSchedulingModel.

Parameters:
name - a not-necessarily-unique name for this host. This is mostly for debugging and conveniance. This may be null.
position - the initial position of the host
mobilityModel - the mobility model this host will use
simulator - the simulator in which this host will live.

Host

public Host(java.lang.String name,
            double x,
            double y,
            MobilityModel mobilityModel,
            Simulator simulator)
Primary constructor. Uses a DefaultCPUSchedulingModel and Position2D position.

Parameters:
name - a not-necessarily-unique name for this host. This is mostly for debugging and conveniance. This may be null.
x - the initial x coordinate of the host
y - the initial y coordinate of the host
mobilityModel - the mobility model this host will use
simulator - the simulator in which this host will live.
See Also:
Host(String, Position, MobilityModel, Simulator)

Host

public Host(java.lang.String name,
            double x,
            double y,
            Simulator simulator)
Constructs a host with a StaticMobilityModel and Position2D position.

Parameters:
name - a not-necessarily-unique name for this host. This is mostly for debugging and conveniance. This may be null.
x - the initial x coordinate of the host
y - the initial y coordinate of the host
simulator - the simulator in which this host will live.
See Also:
Host(String, double, double, MobilityModel, Simulator)

Host

public Host(double x,
            double y,
            MobilityModel mobilityModel,
            Simulator simulator)
Constructs a host without a name. The name will default to the host's automatically-asigned unique identifier.

Parameters:
x - the initial x coordinate of the host
y - the initial y coordinate of the host
mobilityModel - the mobility model this host will use
simulator - the simulator in which this host will live.
See Also:
Host(String, double, double, MobilityModel, Simulator)

Host

public Host(double x,
            double y,
            Simulator simulator)
Constructs a host. The mobility model defaults to a StaticMobilityModel.

Parameters:
x - the initial x coordinate of the host
y - the initial y coordinate of the host
simulator - the simulator in which this host will live.
See Also:
Host(String, double, double, Simulator), Host(double, double, MobilityModel, Simulator), Host(String, double, double, MobilityModel, Simulator)
Method Detail

setPosition

public boolean setPosition(Position newPosition)
Sets the position of this host.

Returns:
true if the new position was valid.
See Also:
Simulator.isValidPosition(Position)

getPosition

public Position getPosition()
Returns the current position of this host.


iterate

public void iterate()
Called once per simulator iteration, it is this function's responsibility to schedule processing time for each of the agents currently on this host, respecting the agents' priorities.


getName

public java.lang.String getName()
Returns the name of this host.


getAgents

public java.util.Enumeration getAgents()
Returns an Enumeration of the agents currently on this host. This does not include any agents in transit to or from this host.


getRadioRange

public double getRadioRange()
Returns the radio range of this host.


setRadioRange

public void setRadioRange(double radio_range)
Sets the radio range for this host.

Parameters:
radio_range - the new radio range for this host.

setRadioRangeToDefault

public void setRadioRangeToDefault()
Sets this host's radio range to the default radio range as defined by the simulator. This is equivalent to setRadioRange(getSimulator().getDefaultRadioRange()).


getMobilityModel

public MobilityModel getMobilityModel()
Returns this host's mobility model.


setMobilityModel

public void setMobilityModel(MobilityModel model)
Sets the mobility model of this host.

Throws:
java.lang.NullPointerException - when model == null

getCPUSchedulingModel

public CPUSchedulingModel getCPUSchedulingModel()
Returns this host's CPU scheduling model;


setCPUSchedulingModel

public void setCPUSchedulingModel(CPUSchedulingModel model)
Sets the CPU scheduling model of this host.

Throws:
java.lang.NullPointerException - when model == null

addAgent

public void addAgent(Agent agent)
Adds an agent to this host. Note that this function will not set the Agent.host member variable. The effect of this function is that the agent will now be scheduled execution time during each call to iterate(). Also, the agent will not be added if agent.isAlive() returns false.


updateAgentPriority

public void updateAgentPriority(Agent agent)
An internal function for updating this host to the fact that one of its agents has updated its priority. In general, this function does not ever need to be called by the user; it is automatically called from Agent.setPriority(int).


setColor

public void setColor(java.awt.Color color)
Sets the color that this host should be displayed if a graphical user interface is chosen.


getColor

public java.awt.Color getColor()
Returns the color of this host, if it is to be displayed graphically. The dafault color is Color.black.


removeAgent

public void removeAgent(Agent agent)
Removes an agent from this host. Note that this function does not alter the Agent.host member variable.


getAgent

public Agent getAgent(UniqueID id)
Returns an agent on this host.

Returns:
an agent with the associated identifier, if that agent is currently on this host. Returns null if the agent is not present.

getAgentByName

public Agent getAgentByName(java.lang.String name)
Returns an agent on this host.

Returns:
an agent with the associated name, if that agent is currently on this host. Since agent names are not unique, this function will return the first match found. Returns null if the agent is not present.

getUniqueID

public UniqueID getUniqueID()
Returns the unique identifier for this host.

Returns:
the unique identifier for this host.

getNeighborsICanHear

public java.util.Vector getNeighborsICanHear()
Conveniance function that calls getSimulator().getTopology().getNeighborsHostCanHear(this).


getNeighbors

public java.util.Vector getNeighbors()
Conveniance function that calls getSimulator().getNeighbors(this).


getSimulator

public Simulator getSimulator()
Returns the simulator in which this host was created.


paint

public void paint(java.awt.Graphics graphics)
Paints this host to a graphics object. graphics is assumed to have the same dimensions as the domain. This implementation will paint a filled circle of color getColor() at this host's current coordinates. This function is used by TopologyVisualizer as a callback for whenever a host needs to be painted. This function will only work if the host's position is an instance of Position2D. If this is not the case, nothing will be painted. If another type of Position is to be used, one must extend this class and re-implement this function.


paintRadioRange

public void paintRadioRange(java.awt.Graphics graphics,
                            boolean mouseover,
                            boolean selected)
Paints the radio range for this host to a graphics object. graphics is assumed to have the same dimensions as the domain. This implementation will draw a circle according to getRadioRange(). The color of the circle will be set according to SELECTED_COLOR, MOUSEOVER_COLOR, and RADIO_RANGE_COLOR. This function is used by TopologyVisualizer as a callback for whenever a radio range needs to be painted. This function will only work if the host's position is an instance of Position2D. If this is not the case, nothing will be painted. If another type of Position is to be used, one must extend this class and re-implement this function.

Parameters:
mouseover - is true when the mouse is held over this host in the GUI.
selected - is true when this host is selected in the GUI.

toString

public java.lang.String toString()
Returns the name of the current host and/or its unique ID.


isContaining

public boolean isContaining(int pixel_x,
                            int pixel_y)
Returns true if a the graphical representation of this host (as defined by paint(java.awt.Graphics)) contains the pixel at coordinate (x, y). This function is used as a callback for determining a mouse-over when the graphical user interface is used. This function will only work if the host's position is an instance of Position2D. If this is not the case, false will always be returned. If another type of Position is to be used, one must extend this class and re-implement this function.


hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object o)

MATES 3.0-rc2

Submit a bug or request a feature
http://mates.sourceforge.net/

Copyright 2004 Evan Sultanik