package org.opentrafficsim.imb.transceiver.urbanstrategy;
import java.rmi.RemoteException;
import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
import org.opentrafficsim.core.network.Network;
import org.opentrafficsim.core.network.Node;
import org.opentrafficsim.core.network.OTSNetwork;
import org.opentrafficsim.imb.IMBException;
import org.opentrafficsim.imb.connector.Connector;
import org.opentrafficsim.imb.connector.Connector.IMBEventType;
import org.opentrafficsim.imb.transceiver.AbstractTransceiver;
import nl.tudelft.simulation.event.EventInterface;
import nl.tudelft.simulation.event.EventType;
import nl.tudelft.simulation.event.TimedEvent;
/**
* OTS publishes events about the Nodes to IMB to be able to identify the nodes in the network.
* At the start of the OTS simulation, or when a Node is added later, a NEW message is sent to IMB for each node to identify the
* node id. No CHANGE messages are posted. When a Node is removed from the network, a DELETE event is posted. The Node NEW
* messages are posted after the Network NEW message is posted.
*
* *
Variable | *Type | *Comments | *
---|---|---|
timestamp | *double | *time of the event, in simulation time seconds | *
networkId | *String | *Id of the Network where the Node resides | *
nodeId | *String | *id of the Node; unique within the Network | *
coordinate.x | *double | *x-coordinate of the Node | *
coordinate.y | *double | *y-coordinate of the Node | *
coordinate.z | *double | *z-coordinate of the Node | *
*
*
Variable | *Type | *Comments | *
---|---|---|
timestamp | *double | *time of the event, in simulation time seconds | *
networkId | *String | *Id of the Network where the Node resides | *
nodeId | *String | *id of the Node that is removed from the Network | *
* Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 13, 2016
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
public class NodeTransceiver extends AbstractTransceiver
{
/** */
private static final long serialVersionUID = 20160918L;
/** the OTS network on which Nodes are registered. */
private final OTSNetwork network;
/**
* Construct a new NodeTransceiver.
* @param connector Connector; the IMB connector through which this transceiver communicates
* @param simulator OTSDEVSSimulatorInterface; the simulator to schedule the incoming notifications on
* @param network OTSNetwork; the OTS network on which Nodes are registered
* @throws IMBException when the registration of one of the channels fails
* @throws NullPointerException in case one of the arguments is null.
*/
public NodeTransceiver(final Connector connector, final OTSDEVSSimulatorInterface simulator, final OTSNetwork network)
throws IMBException
{
super("Node", connector, simulator);
this.network = network;
// listen on network changes and register the listener to all the Links
addListeners();
}
/**
* Ensure that we get notified about newly created and destroyed Nodes, and instrument all currently existing Nodes.
* @throws IMBException in case notification of existing Nodes fails
*/
private void addListeners() throws IMBException
{
// Subscribe to all future link creation and removal events.
this.network.addListener(this, Network.NODE_ADD_EVENT);
this.network.addListener(this, Network.NODE_REMOVE_EVENT);
// For already existing links, post ourselves a LINK_ADD_EVENT
for (Node node : this.network.getNodeMap().values())
{
try
{
this.notify(new TimedEvent