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 TypeMethodDescriptionbooleanChecks, if thisEventProcessoris able to process any events.voidchangeExternalParameters(VehicleParametersChange vehicleParametersChange) Changes parameters of externally added vehicles.voidconnectToFederate(String host, int port) Connects to SUMO using the given host and port.voidconnectToFederate(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.voidFinishes the simulation.voidinitialize(long startTime, long endTime) This method is called to tell the federate the start time and the end time.protected voidInitializes the TraciClient.booleanReturns whether this federate is time constrained.booleanReturns whether this federate is time regulating.voidprocessEvent(Event event) Processes the given event.voidprocessInteraction(Interaction interaction) This method processes the interactions.protected voidprocessInteractionAdvanced(Interaction interaction, long time) This processes all other types of interactions as part ofprocessTimeAdvanceGrant(long).voidprocessTimeAdvanceGrant(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:
createFederateExecutorin interfaceFederateAmbassador- Overrides:
createFederateExecutorin 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:
connectToFederatein interfaceFederateAmbassador- Overrides:
connectToFederatein 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:
connectToFederatein interfaceFederateAmbassador- Overrides:
connectToFederatein 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:
initializein interfaceFederateAmbassador- Overrides:
initializein 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:
processInteractionin 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:EventProcessorProcesses the given event.- Specified by:
processEventin interfaceEventProcessor- Parameters:
event- the event to process- Throws:
Exception
-
processTimeAdvanceGrant
Description copied from class:AbstractFederateAmbassadorThis 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:
processTimeAdvanceGrantin 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:AbstractFederateAmbassadorFinishes the simulation.- Specified by:
finishSimulationin interfaceFederateAmbassador- Overrides:
finishSimulationin classAbstractFederateAmbassador
-
isTimeConstrained
public boolean isTimeConstrained()Description copied from interface:FederateAmbassadorReturns 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:
isTimeConstrainedin interfaceFederateAmbassador- Returns:
trueif this federate is time constrained, elsefalse
-
isTimeRegulating
public boolean isTimeRegulating()Description copied from interface:FederateAmbassadorReturns 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:
isTimeRegulatingin interfaceFederateAmbassador- Returns:
trueif this federate is time regulating,falseelse
-
canProcessEvent
public boolean canProcessEvent()Description copied from interface:EventProcessorChecks, if thisEventProcessoris 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:
canProcessEventin interfaceEventProcessor- Returns:
trueif thisEventProcessoris currently able to process events, otherwisefalse.
-