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 a
AbstractFederateAmbassador
for the traffic simulator
SUMO. It allows to control the progress of the traffic simulation and
publishes VehicleUpdates
.-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.mosaic.rti.api.AbstractFederateAmbassador
AbstractFederateAmbassador.InteractionQueue
-
Field Summary
FieldsModifier and TypeFieldDescriptionList 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
Modifier and TypeMethodDescriptionboolean
Checks, if thisEventProcessor
is able to process any events.void
changeExternalParameters
(VehicleParametersChange vehicleParametersChange) Changes parameters of externally added vehicles.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.createFederateExecutor
(String host, int port, CLocalHost.OperatingSystem os) Creates and sets new federate executor.void
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
Initializes the TraciClient.boolean
Returns whether this federate is time constrained.boolean
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
-
Field Details
-
Method Details
-
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
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
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
Initializes the TraciClient.- Throws:
InternalFederateException
- Exception is thrown if an error is occurred while execution of a federate.
-
processInteraction
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
Description copied from interface:EventProcessor
Processes the given event.- Specified by:
processEvent
in interfaceEventProcessor
- Parameters:
event
- the event to process- Throws:
Exception
-
processTimeAdvanceGrant
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
-
changeExternalParameters
public void changeExternalParameters(VehicleParametersChange vehicleParametersChange) throws InternalFederateException Changes parameters of externally added vehicles. So far only color change is supported.- Parameters:
vehicleParametersChange
- Stores a list of vehicle parameters that should be changed.- Throws:
InternalFederateException
- Throws an IllegalArgumentException if color could not be set correctly.
-
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
.
-