Class AbstractSumoAmbassador
- java.lang.Object
-
- org.eclipse.mosaic.rti.api.AbstractFederateAmbassador
-
- org.eclipse.mosaic.fed.sumo.ambassador.AbstractSumoAmbassador
-
- All Implemented Interfaces:
Comparable<FederateAmbassador>
,EventProcessor
,FederateAmbassador
- Direct Known Subclasses:
SumoAmbassador
@NotThreadSafe public abstract class AbstractSumoAmbassador extends AbstractFederateAmbassador implements EventProcessor
Implementation of aAbstractFederateAmbassador
for the traffic simulator SUMO. It allows to control the progress of the traffic simulation and publishesVehicleUpdates
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.mosaic.rti.api.AbstractFederateAmbassador
AbstractFederateAmbassador.InteractionQueue
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,org.eclipse.mosaic.fed.sumo.ambassador.ExternalVehicleState>
externalVehicles
List of vehicles that are simulated externally.-
Fields inherited from class org.eclipse.mosaic.rti.api.AbstractFederateAmbassador
ambassadorParameter, descriptor, endTime, interactionQueue, log, lookahead, rti
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canProcessEvent()
Checks, if thisEventProcessor
is able to process any events.void
connectToFederate(String host, int port)
Connects to SUMO using the given host and port.void
connectToFederate(String host, InputStream in, InputStream err)
Connects to SUMO using the given host with input stream.FederateExecutor
createFederateExecutor(String host, int port, CLocalHost.OperatingSystem os)
Creates and sets new federate executor.void
finishSimulation()
Finishes the simulation.void
initialize(long startTime, long endTime)
This method is called to tell the federate the start time and the end time.protected void
initSumoConnection()
Initializes the TraciClient.boolean
isTimeConstrained()
Returns whether this federate is time constrained.boolean
isTimeRegulating()
Returns whether this federate is time regulating.void
processEvent(Event event)
Processes the given event.void
processInteraction(Interaction interaction)
This method processes the interactions.protected void
processInteractionAdvanced(Interaction interaction, long time)
This processes all other types of interactions as part ofprocessTimeAdvanceGrant(long)
.void
processTimeAdvanceGrant(long time)
This method is called by the AbstractFederateAmbassador when a time advance has been granted by the RTI.-
Methods inherited from class org.eclipse.mosaic.rti.api.AbstractFederateAmbassador
advanceTime, compareTo, createDockerFederateExecutor, getEndTime, getId, getPriority, receiveInteraction, setFederateDescriptor, setRtiAmbassador
-
-
-
-
Method Detail
-
createFederateExecutor
@Nonnull public FederateExecutor createFederateExecutor(String host, int port, CLocalHost.OperatingSystem os)
Creates and sets new federate executor.- Specified by:
createFederateExecutor
in interfaceFederateAmbassador
- Overrides:
createFederateExecutor
in classAbstractFederateAmbassador
- Parameters:
host
- name of the host (as specified in /etc/hosts.json)port
- port number to be used by this federateos
- operating system enum- Returns:
- FederateExecutor.
-
connectToFederate
public void connectToFederate(String host, InputStream in, InputStream err) throws InternalFederateException
Connects to SUMO using the given host with input stream.- Specified by:
connectToFederate
in interfaceFederateAmbassador
- Overrides:
connectToFederate
in classAbstractFederateAmbassador
- Parameters:
host
- The host on which the simulator is running.in
- This input stream is connected to the output stream of the started simulator process. The stream is only valid during this method call.err
- Error by connecting to federate.- Throws:
InternalFederateException
- Exception if an error occurred while starting SUMO.
-
connectToFederate
public void connectToFederate(String host, int port)
Connects to SUMO using the given host and port.- Specified by:
connectToFederate
in interfaceFederateAmbassador
- Overrides:
connectToFederate
in classAbstractFederateAmbassador
- Parameters:
host
- host on which SUMO is running.port
- port on which TraCI is listening.
-
initialize
public void initialize(long startTime, long endTime) throws InternalFederateException
This method is called to tell the federate the start time and the end time.- Specified by:
initialize
in interfaceFederateAmbassador
- Overrides:
initialize
in classAbstractFederateAmbassador
- Parameters:
startTime
- Start time of the simulation run in nano seconds.endTime
- End time of the simulation run in nano seconds.- Throws:
InternalFederateException
- Exception is thrown if an error is occurred while execute of a federate.
-
initSumoConnection
protected void initSumoConnection() throws InternalFederateException
Initializes the TraciClient.- Throws:
InternalFederateException
- Exception is thrown if an error is occurred while execution of a federate.
-
processInteraction
public void processInteraction(Interaction interaction) throws InternalFederateException
This method processes the interactions.- Overrides:
processInteraction
in classAbstractFederateAmbassador
- Parameters:
interaction
- The interaction that can be processed- Throws:
InternalFederateException
- Exception is thrown if an error is occurred while execute of a federate.
-
processInteractionAdvanced
protected void processInteractionAdvanced(Interaction interaction, long time) throws InternalFederateException
This processes all other types of interactions as part ofprocessTimeAdvanceGrant(long)
.- Parameters:
interaction
- The interaction to process.time
- The time of the processed interaction.- Throws:
InternalFederateException
- Exception if the interaction time is not correct.
-
processEvent
public void processEvent(Event event) throws Exception
Description copied from interface:EventProcessor
Processes the given event.- Specified by:
processEvent
in interfaceEventProcessor
- Parameters:
event
- the event to process- Throws:
Exception
-
processTimeAdvanceGrant
public void processTimeAdvanceGrant(long time) throws InternalFederateException
Description copied from class:AbstractFederateAmbassador
This method is called by the AbstractFederateAmbassador when a time advance has been granted by the RTI. Before this call is placed, any unprocessed interaction is forwarded to the federate using the processInteraction method.- Overrides:
processTimeAdvanceGrant
in classAbstractFederateAmbassador
- Parameters:
time
- The timestamp towards which the federate can advance it local time.- Throws:
InternalFederateException
-
finishSimulation
public void finishSimulation()
Description copied from class:AbstractFederateAmbassador
Finishes the simulation.- Specified by:
finishSimulation
in interfaceFederateAmbassador
- Overrides:
finishSimulation
in classAbstractFederateAmbassador
-
isTimeConstrained
public boolean isTimeConstrained()
Description copied from interface:FederateAmbassador
Returns whether this federate is time constrained. Is set if the federate is sensitive towards the correct ordering of events. The federate ambassador will ensure that the message processing happens in time stamp order. If set to false, interactions will be processed will be in receive order.- Specified by:
isTimeConstrained
in interfaceFederateAmbassador
- Returns:
true
if this federate is time constrained, elsefalse
-
isTimeRegulating
public boolean isTimeRegulating()
Description copied from interface:FederateAmbassador
Returns whether this federate is time regulating. Is set if the federate influences other federates and can prevent them from advancing their local time.- Specified by:
isTimeRegulating
in interfaceFederateAmbassador
- Returns:
true
if this federate is time regulating,false
else
-
canProcessEvent
public boolean canProcessEvent()
Description copied from interface:EventProcessor
Checks, if thisEventProcessor
is able to process any events. If the processor is not currently to able to process a given event, those events will be skipped and never reach thisEventProcessor
.- Specified by:
canProcessEvent
in interfaceEventProcessor
- Returns:
true
if thisEventProcessor
is currently able to process events, otherwisefalse
.
-
-