public class Topology extends Properties implements ClockListener
Modifier and Type | Class and Description |
---|---|
class |
Topology.DefaultCommands |
static class |
Topology.RefreshMode |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COMMAND_SEPARATOR
The character used as command separator.
|
protected java.util.ArrayList<CommandListener> |
commandListeners |
protected java.util.ArrayList<java.lang.String> |
commands |
static double |
DEFAULT_COMMUNICATION_RANGE |
static int |
DEFAULT_HEIGHT |
static java.lang.String |
DEFAULT_NODE_MODEL_NAME
The name under which the default Node model is stored.
|
static double |
DEFAULT_SENSING_RANGE |
static int |
DEFAULT_WIDTH |
protected boolean |
defaultCommandsEnabled |
properties
Constructor and Description |
---|
Topology()
Creates a topology.
|
Topology(int width,
int height)
Creates a topology of given dimensions.
|
Modifier and Type | Method and Description |
---|---|
void |
addClockListener(ClockListener listener)
Registers the specified listener to the events of the clock.
|
void |
addClockListener(ClockListener listener,
int period)
Registers the specified listener to the events of the clock.
|
void |
addCommand(java.lang.String command)
Adds the specified action command to this
Topology . |
void |
addCommandListener(CommandListener al)
Registers the specified action listener to this
Topology . |
void |
addConnectivityListener(ConnectivityListener listener)
Registers the specified topology listener to this topology.
|
void |
addConnectivityListener(ConnectivityListener listener,
boolean directed)
Registers the specified connectivity listener to this topology.
|
void |
addLink(Link l)
Adds the specified link to this topology.
|
void |
addLink(Link l,
boolean silent)
Adds the specified link to this topology without notifying the listeners
(if silent is true).
|
void |
addMessageListener(MessageListener listener)
Registers the specified message listener to this topology.
|
void |
addMovementListener(MovementListener listener)
Registers the specified movement listener to this topology.
|
void |
addNode(double x,
double y)
Adds a new node to this topology at the specified location.
|
void |
addNode(double x,
double y,
Node n)
Adds the specified node to this topology at the specified location.
|
void |
addNode(Node n)
Adds the specified node to this topology.
|
void |
addSelectionListener(SelectionListener listener)
Registers the specified selection listener to this topology.
|
void |
addStartListener(StartListener listener)
Registers the specified start listener to this topology.
|
void |
addTopologyListener(TopologyListener listener)
Registers the specified topology listener to this topology.
|
void |
clear()
Removes all the nodes (and links) of this topology.
|
void |
clearLinks()
Removes all the links of this topology.
|
void |
clearMessages()
Removes all the ongoing messages in this topology.
|
void |
disableDefaultCommands()
Disables the set of default commands provided by the
Topology when using getCommands() . |
void |
disableWireless()
Disables this node's wireless capabilities.
|
void |
enableDefaultCommands()
Enables the set of default commands provided by the
Topology when using getCommands() . |
void |
enableWireless()
Enables this node's wireless capabilities.
|
void |
executeCommand(java.lang.String command)
Executes a command.
|
Node |
findNodeById(int id)
Returns the first node found with this ID.
|
java.lang.Class<? extends Clock> |
getClockModel()
Returns the clock model currently in use.
|
java.lang.Iterable<java.lang.String> |
getCommands()
Recompute the current list of commands.
|
double |
getCommunicationRange()
Returns the default communication range.
|
java.lang.Class<? extends Node> |
getDefaultNodeModel()
Returns the default node model,
all properties assigned to this virtual node will be given to further nodes created
without explicit model name.
|
FileManager |
getFileManager() |
int |
getHeight()
Returns the height of this topology.
|
Link |
getLink(Node n1,
Node n2)
Returns the undirected link shared the specified nodes, if any.
|
Link |
getLink(Node from,
Node to,
boolean directed)
Returns the link of the specified type between the specified nodes, if
any.
|
LinkResolver |
getLinkResolver()
Return the current LinkResolver.
|
java.util.List<Link> |
getLinks()
Returns a list containing all undirected links in this topology.
|
java.util.List<Link> |
getLinks(boolean directed)
Returns a list containing all links of the specified type in this
topology.
|
MessageEngine |
getMessageEngine()
Gets a reference on the message engine of this topology.
|
java.util.Set<java.lang.String> |
getModelsNames()
Returns the set registered node classes.
|
java.lang.Class<? extends Node> |
getNodeModel(java.lang.String modelName)
Returns the node class corresponding to that name.
|
java.util.List<Node> |
getNodes()
Returns a list containing all the nodes in this topology.
|
Topology.RefreshMode |
getRefreshMode()
Returns the current refresh mode (CLOCKBASED or EVENTBASED).
|
Scheduler |
getScheduler()
Gets a reference on the scheduler.
|
double |
getSensingRange()
Returns the default sensing range,
|
TopologySerializer |
getSerializer()
Provides a
TopologySerializer . |
int |
getTime()
Returns the current time (current round number)
|
int |
getTimeUnit()
Returns the global duration of a round in this topology (in millisecond).
|
int |
getWidth()
Returns the width of this topology.
|
boolean |
getWirelessStatus()
Returns true if wireless links are enabled.
|
boolean |
hasDirectedLinks()
Returns true if this topology has at least one directed link.
|
boolean |
isRunning()
Indicates whether the internal clock is currently running or in pause.
|
boolean |
isStarted() |
Node |
newInstanceOfModel(java.lang.String modelName)
Create a new instance of this type of node.
|
protected void |
notifyLinkAdded(Link l) |
protected void |
notifyLinkRemoved(Link l) |
protected void |
notifyNodeAdded(Node node) |
protected void |
notifyNodeRemoved(Node node) |
protected void |
notifyNodeSelected(Node node) |
void |
onClock()
Called periodically by the central scheduler.
|
void |
pause()
Pauses the clock (or increments the pause counter).
|
void |
removeAllCommands()
Removes all commands from this
Topology . |
void |
removeClockListener(ClockListener listener)
Unregisters the specified listener.
|
void |
removeCommand(java.lang.String command)
Removes the specified action command from this
Topology . |
void |
removeCommandListener(CommandListener al)
Unregisters the specified action listener to this
Topology . |
void |
removeConnectivityListener(ConnectivityListener listener)
Unregisters the specified connectivity listener from the 'undirected'
listeners.
|
void |
removeConnectivityListener(ConnectivityListener listener,
boolean directed)
Unregisters the specified connectivity listener from the listeners
of the specified type.
|
void |
removeLink(Link l)
Removes the specified link from this topology.
|
void |
removeMessageListener(MessageListener listener)
Unregisters the specified message listener for this topology.
|
void |
removeMovementListener(MovementListener listener)
Unregisters the specified movement listener for this topology.
|
void |
removeNode(Node n)
Removes the specified node from this topology.
|
void |
removeSelectionListener(SelectionListener listener)
Unregisters the specified selection listener for this topology.
|
void |
removeStartListener(StartListener listener)
Unregisters the specified selection listener for this topology.
|
void |
removeTopologyListener(TopologyListener listener)
Unregisters the specified topology listener.
|
void |
resetTime()
Reset the round number to 0.
|
void |
restart()
(Re)init the nodes through their onStart() method (and notifies StartListeners as well)
|
void |
resume()
Resumes the clock (or decrements the pause counter).
|
void |
selectNode(Node n)
|
void |
setClockModel(java.lang.Class<? extends Clock> clockModel)
Sets the clock model (to be instantiated automatically).
|
void |
setCommunicationRange(double communicationRange)
Sets the default communication range.
|
void |
setDefaultNodeModel(java.lang.Class<? extends Node> nodeClass)
Sets the default node model to the given node instance.
|
void |
setDimensions(int width,
int height)
Sets the topology dimensions as indicated.
|
void |
setFileManager(FileManager fileManager) |
void |
setLinkResolver(LinkResolver linkResolver)
Replaces the default Wireless Link Resolver by a custom one.
|
void |
setMessageEngine(MessageEngine messageEngine)
Sets the message engine of this topology.
|
void |
setNodeModel(java.lang.String modelName,
java.lang.Class<? extends Node> nodeClass)
Adds the given node instance as a model.
|
void |
setRefreshMode(Topology.RefreshMode refreshMode)
Sets the updates (links, sensed objects, etc.) to be instantaneous (EVENTBASED),
or periodic after each round (CLOCKBASED).
|
void |
setScheduler(Scheduler scheduler)
Sets the scheduler of this topology.
|
void |
setSensingRange(double sensingRange)
Sets the default sensing range.
|
void |
setSerializer(TopologySerializer topologySerializer)
Sets the new
TopologySerializer to use. |
void |
setTimeUnit(int period)
Sets the global duration of a round in this topology (in millisecond).
|
void |
setWirelessStatus(boolean enabled)
Set wireless capabilities status
|
void |
shuffleNodeIds()
Shuffles the IDs of the nodes in this topology.
|
void |
start()
Initializes the clock.
|
void |
step()
Performs a single round, then switch to pause state.
|
java.lang.String |
toString() |
addPropertyListener, getProperty, hasProperty, removeProperty, removePropertyListener, setProperty
public static final int DEFAULT_WIDTH
public static final int DEFAULT_HEIGHT
public static final double DEFAULT_COMMUNICATION_RANGE
public static final double DEFAULT_SENSING_RANGE
public static final java.lang.String DEFAULT_NODE_MODEL_NAME
protected java.util.ArrayList<CommandListener> commandListeners
protected java.util.ArrayList<java.lang.String> commands
protected boolean defaultCommandsEnabled
public static final java.lang.String COMMAND_SEPARATOR
public java.lang.Class<? extends Node> getNodeModel(java.lang.String modelName)
modelName
- a String
identifying the node model.public java.lang.Class<? extends Node> getDefaultNodeModel()
public void setNodeModel(java.lang.String modelName, java.lang.Class<? extends Node> nodeClass)
modelName
- a String
identifying the node model.nodeClass
- the node model: a Class
object a class extending the Node
class.public void setDefaultNodeModel(java.lang.Class<? extends Node> nodeClass)
nodeClass
- the default node model: a Class
object a class extending the Node
class.public java.util.Set<java.lang.String> getModelsNames()
Set
of known model names.public Node newInstanceOfModel(java.lang.String modelName)
modelName
- a String
identifying the node model.public boolean isStarted()
public void setRefreshMode(Topology.RefreshMode refreshMode)
refreshMode
- the Topology.RefreshMode
to use.public Topology.RefreshMode getRefreshMode()
Topology.RefreshMode
.public void enableWireless()
public void disableWireless()
public void setWirelessStatus(boolean enabled)
enabled
- the new wireless status: true to enable,
false otherwise.public boolean getWirelessStatus()
public double getCommunicationRange()
public void setCommunicationRange(double communicationRange)
communicationRange
- The communication rangepublic double getSensingRange()
public void setSensingRange(double sensingRange)
sensingRange
- The sensing rangepublic MessageEngine getMessageEngine()
MessageEngine
.public void setMessageEngine(MessageEngine messageEngine)
messageEngine
- the new MessageEngine
.public Scheduler getScheduler()
Scheduler
.public void setScheduler(Scheduler scheduler)
scheduler
- the new Scheduler
.public int getTimeUnit()
public void setTimeUnit(int period)
period
- The desired durationpublic java.lang.Class<? extends Clock> getClockModel()
public void setClockModel(java.lang.Class<? extends Clock> clockModel)
clockModel
- A class that extends JBotSim's abstract Clockpublic int getTime()
public boolean isRunning()
public void pause()
public void resume()
public void resetTime()
public void setDimensions(int width, int height)
public int getWidth()
public int getHeight()
public void start()
public void restart()
public void clear()
public void clearLinks()
public void clearMessages()
public void step()
public void addNode(Node n)
n
- The node to be added.public void addNode(double x, double y)
x
- The abscissa of the location.y
- The ordinate of the location.public void addNode(double x, double y, Node n)
x
- The abscissa of the location.y
- The ordinate of the location.n
- The node to be added.public void removeNode(Node n)
n
- The node to be removed.public void addLink(Link l)
l
- The link to be added.public void addLink(Link l, boolean silent)
l
- The link to be added.silent
- true to disable notifications of this adding.public void removeLink(Link l)
l
- The link to be removed.public boolean hasDirectedLinks()
Topology
has at least one directed link, false otherwise.public java.util.List<Node> getNodes()
List
of Node
s.public Node findNodeById(int id)
public void shuffleNodeIds()
public java.util.List<Link> getLinks()
List
of Link
s.public java.util.List<Link> getLinks(boolean directed)
directed
- true for directed links, false for
undirected links.List
of Link
s.public Link getLink(Node n1, Node n2)
public Link getLink(Node from, Node to, boolean directed)
public void setLinkResolver(LinkResolver linkResolver)
linkResolver
- An object that implements LinkResolver.public LinkResolver getLinkResolver()
LinkResolver
.public void addConnectivityListener(ConnectivityListener listener)
listener
- The listener to add.public void addConnectivityListener(ConnectivityListener listener, boolean directed)
listener
- The listener to register.directed
- The type of links to be listened (true for
directed, false for undirected).public void removeConnectivityListener(ConnectivityListener listener)
listener
- The listener to unregister.public void removeConnectivityListener(ConnectivityListener listener, boolean directed)
listener
- The listener to unregister.directed
- The type of links that this listener was listening
(true for directed, false for undirected).public void addMovementListener(MovementListener listener)
listener
- The movement listener.public void removeMovementListener(MovementListener listener)
listener
- The movement listener.public void addTopologyListener(TopologyListener listener)
listener
- The listener to register.public void removeTopologyListener(TopologyListener listener)
listener
- The listener to unregister.public void addMessageListener(MessageListener listener)
listener
- The message listener.public void removeMessageListener(MessageListener listener)
listener
- The message listener.public void addSelectionListener(SelectionListener listener)
listener
- The selection listener.public void removeSelectionListener(SelectionListener listener)
listener
- The selection listener.public void addStartListener(StartListener listener)
listener
- The start listener.public void removeStartListener(StartListener listener)
listener
- The start listener.public void addClockListener(ClockListener listener, int period)
listener
- The listener to register.period
- The number of rounds between consecutive onClock() events,
in time units.public void addClockListener(ClockListener listener)
listener
- The listener to register.public void removeClockListener(ClockListener listener)
listener
- The listener to unregister.public void setFileManager(FileManager fileManager)
public FileManager getFileManager()
public TopologySerializer getSerializer()
TopologySerializer
.TopologySerializer
.public void setSerializer(TopologySerializer topologySerializer)
TopologySerializer
to use.topologySerializer
- the new TopologySerializer
to use.protected void notifyLinkAdded(Link l)
protected void notifyLinkRemoved(Link l)
protected void notifyNodeAdded(Node node)
protected void notifyNodeRemoved(Node node)
protected void notifyNodeSelected(Node node)
public void onClock()
ClockListener
onClock
in interface ClockListener
public java.lang.String toString()
toString
in class java.lang.Object
public void addCommandListener(CommandListener al)
Topology
.al
- The listener to add.public void removeCommandListener(CommandListener al)
Topology
.al
- The listener to remove.public void addCommand(java.lang.String command)
Topology
.command
- The command name to add.public void removeCommand(java.lang.String command)
Topology
.command
- The command name to remove.public void disableDefaultCommands()
Topology
when using getCommands()
.public void enableDefaultCommands()
Topology
when using getCommands()
.public java.lang.Iterable<java.lang.String> getCommands()
Recompute the current list of commands.
This list contains:
Topology
.
Please use disableDefaultCommands()
to if you dont want them.addCommand(String)
.public void removeAllCommands()
Topology
.public void executeCommand(java.lang.String command)
command
- the command to be executed