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 String |
COMMAND_SEPARATOR
The character used as command separator.
|
protected ArrayList<CommandListener> |
commandListeners |
protected ArrayList<String> |
commands |
static double |
DEFAULT_COMMUNICATION_RANGE |
static int |
DEFAULT_HEIGHT |
static String |
DEFAULT_NODE_MODEL_NAME
The name under which the default Node model is stored.
|
static Link.Orientation |
DEFAULT_ORIENTATION |
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(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)
Deprecated.
|
void |
addConnectivityListener(ConnectivityListener listener,
Link.Orientation orientation)
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(String command)
Executes a command.
|
Node |
findNodeById(int id)
Returns the first node found with this ID.
|
Class<? extends Clock> |
getClockModel()
Returns the clock model currently in use.
|
Iterable<String> |
getCommands()
Recompute the current list of commands.
|
double |
getCommunicationRange()
Returns the default communication range.
|
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 link shared by the specified nodes, if any.
|
Link |
getLink(Node from,
Node to,
boolean directed)
Deprecated.
use
getLink(Node, Node, Link.Orientation) instead. |
Link |
getLink(Node from,
Node to,
Link.Orientation orientation)
Returns the link with the specified orientation between the given nodes,
if any.
|
LinkResolver |
getLinkResolver()
Return the current LinkResolver.
|
List<Link> |
getLinks()
Returns a list containing all links in this topology with respect to its
orientation.
|
List<Link> |
getLinks(boolean directed)
Deprecated.
use
getLinks(Link.Orientation) instead. |
List<Link> |
getLinks(Link.Orientation orientation)
Returns a list containing all links with the specified orientation.
|
MessageEngine |
getMessageEngine()
Gets a reference on the message engine of this topology.
|
Set<String> |
getModelsNames()
Returns the set registered node classes.
|
Class<? extends Node> |
getNodeModel(String modelName)
Returns the node class corresponding to that name.
|
List<Node> |
getNodes()
Returns a list containing all the nodes in this topology.
|
Link.Orientation |
getOrientation()
Returns the orientation of the 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()
Deprecated.
see
isDirected() |
boolean |
isDirected() |
boolean |
isRunning()
Indicates whether the internal clock is currently running or in pause.
|
boolean |
isStarted() |
Node |
newInstanceOfModel(String modelName)
Create a new instance of this type of node.
|
protected void |
notifyLinkAdded(Link l) |
protected void |
notifyLinkRemoved(Link l) |
protected void |
notifyMessageDelivered(Message message) |
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(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 according to the orientation of the topology.
|
void |
removeConnectivityListener(ConnectivityListener listener,
boolean directed)
Deprecated.
|
void |
removeConnectivityListener(ConnectivityListener listener,
Link.Orientation orientation)
Unregisters the specified connectivity listener from the listeners
of the specified orientation.
|
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(Class<? extends Clock> clockModel)
Sets the clock model (to be instantiated automatically).
|
void |
setCommunicationRange(double communicationRange)
Sets the default communication range.
|
void |
setDefaultNodeModel(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(String modelName,
Class<? extends Node> nodeClass)
Adds the given node instance as a model.
|
void |
setOrientation(Link.Orientation orientation)
Set the orientation of the topology.
|
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.
|
String |
toString() |
addPropertyListener, getProperty, hasProperty, removeProperty, removePropertyListener, setProperty
public static final Link.Orientation DEFAULT_ORIENTATION
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 String DEFAULT_NODE_MODEL_NAME
protected ArrayList<CommandListener> commandListeners
protected boolean defaultCommandsEnabled
public static final String COMMAND_SEPARATOR
public Class<? extends Node> getNodeModel(String modelName)
modelName
- a String
identifying the node model.public Class<? extends Node> getDefaultNodeModel()
public void setNodeModel(String modelName, Class<? extends Node> nodeClass)
public void setDefaultNodeModel(Class<? extends Node> nodeClass)
public Set<String> getModelsNames()
Set
of known model names.public Node newInstanceOfModel(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()
true
if the wireless links are enabled,
false
otherwise.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 Class<? extends Clock> getClockModel()
public void setClockModel(Class<? extends Clock> clockModel)
clockModel
- A class that extends JBotSim's abstract Clockpublic int getTime()
public boolean isRunning()
true
if running, false
if paused.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)
(0,0)
if no location was prealably given to it).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.@Deprecated public boolean hasDirectedLinks()
isDirected()
true
if the Topology
has at least one directed link, false
otherwise.public boolean isDirected()
Link.Orientation.DIRECTED
public List<Node> getNodes()
public Node findNodeById(int id)
public void shuffleNodeIds()
public Link.Orientation getOrientation()
public void setOrientation(Link.Orientation orientation)
orientation
- the enforced orientationpublic List<Link> getLinks()
List
of Link
s.getOrientation()
,
setOrientation(Link.Orientation)
public List<Link> getLinks(Link.Orientation orientation)
@Deprecated public List<Link> getLinks(boolean directed)
getLinks(Link.Orientation)
instead.public Link getLink(Node n1, Node n2)
n1
- the first Node
.n2
- the second Node
.null
otherwise.getOrientation()
public Link getLink(Node from, Node to, Link.Orientation orientation)
@Deprecated public Link getLink(Node from, Node to, boolean directed)
getLink(Node, Node, Link.Orientation)
instead.public void setLinkResolver(LinkResolver linkResolver)
linkResolver
- An object that implements LinkResolver.public LinkResolver getLinkResolver()
LinkResolver
.public void addConnectivityListener(ConnectivityListener listener)
Registers the specified topology listener to this topology.
The listener will be notified whenever a link is added or removed. It will either receive notifications for directed or undirected links, according to the orientation of the topology when it was registered.
listener
- The listener to add.getOrientation()
@Deprecated public void addConnectivityListener(ConnectivityListener listener, boolean directed)
addConnectivityListener(ConnectivityListener, Link.Orientation)
instead.Registers the specified connectivity listener to this topology.
The listener will be notified whenever a link of the specified orientation is added or removed.
listener
- The listener to register.directed
- The orientation of links to be listened, as a boolean (true
for
directed, false
for undirected).public void addConnectivityListener(ConnectivityListener listener, Link.Orientation orientation)
Registers the specified connectivity listener to this topology.
The listener will be notified whenever a link of the specified orientation is added or removed.
listener
- The listener to register.orientation
- The type of orientation to be listened, as an Link.Orientation
.public void removeConnectivityListener(ConnectivityListener listener)
Unregisters the specified connectivity listener according to the orientation of the topology.
The listener will be removed from the list of listeners, according to the current orientation of the topology.
listener
- The listener to unregister.getOrientation()
@Deprecated public void removeConnectivityListener(ConnectivityListener listener, boolean directed)
removeConnectivityListener(ConnectivityListener, Link.Orientation)
instead.Unregisters the specified connectivity listener from the listeners of the specified orientation.
listener
- The listener to unregister.directed
- The orientation of links that this listener was listening
(true
for directed, false
for undirected).public void removeConnectivityListener(ConnectivityListener listener, Link.Orientation orientation)
Unregisters the specified connectivity listener from the listeners of the specified orientation.
listener
- The listener to unregister.orientation
- The orientation of links that this listener was listening, as an Link.Orientation
.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)
onClock()
method of this
listener will not longer be called.)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)
protected void notifyMessageDelivered(Message message)
public void onClock()
ClockListener
onClock
in interface ClockListener
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(String command)
Topology
.command
- The command name to add.public void removeCommand(String command)
Topology
.command
- The command name to remove.public void disableDefaultCommands()
Topology
when using getCommands()
.public void enableDefaultCommands()
Topology
when using getCommands()
.public Iterable<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(String command)
command
- the command to be executed