Package org.lsst.ccs.messaging
Class ConcurrentMessagingUtils
java.lang.Object
org.lsst.ccs.messaging.ConcurrentMessagingUtils
Utility class to synchronously or asynchronously invoke or listen for events
on the buses.
Synchronous command execution will wait a given time before throwing a
TimeoutException. The timeout used when throwing an exception depends
on the method invoked, the ConcurrentMessagingUtils configuration and the
command invoked.
If a method that takes a timeout is invoked, that timeout is used, otherwise
a cascade approach is used to determine the timeout among the following:
- The timeout returned as part of the
CommandAckwhen the invokedCommandis accepted - The default timeout set on the ConcurrentMessagingUtils object, either at
construction time or by invoking the method
setDefaultTimeoutmethod.
- Author:
- The LSST CCS Team
-
Constructor Summary
ConstructorsConstructorDescriptionConcurrentMessagingUtils(AgentMessagingLayer agentMessagingLayer) ConsurrentMessagingUtils constructor.ConcurrentMessagingUtils(AgentMessagingLayer agentMessagingLayer, Duration defaultTimeout) Build a ConsurrentMessagingUtils object with a default timeout. -
Method Summary
Modifier and TypeMethodDescriptiongetAckForCommand(CommandRequest command, Duration timeout) Send a CommandRequest on the buses and synchronously wait for the Ack to come back within the provided Duration timeout.Get the default timeout for this ConcurrentMessagingUtils object.sendAsynchronousCommand(CommandRequest command) Send a command on the buses and immediately return a Future that will asynchronously listen for the command reply.sendSynchronousCommand(CommandRequest command) Send synchronously a command on the Buses without a timeout.sendSynchronousCommand(CommandRequest command, Duration timeout) Send a command on the Buses and wait for the reply within the provided Duration timeout.voidsetDefaultTimeout(Duration defaultTimeout) Set the default timeout for this ConcurrentMessagingUtils object.startListeningForStatusBusMessage(Predicate<BusMessage<? extends Serializable, ?>> f) Get a Future on a StatusBusMessage.startListeningForStatusBusMessage(Predicate<BusMessage<? extends Serializable, ?>> filter, Duration timeout) Get a Future on a StatusBusMessage.
-
Constructor Details
-
ConcurrentMessagingUtils
ConsurrentMessagingUtils constructor.- Parameters:
agentMessagingLayer- TheAgentMessagingLayerused to send messages on the buses.
-
ConcurrentMessagingUtils
Build a ConsurrentMessagingUtils object with a default timeout.- Parameters:
agentMessagingLayer- TheAgentMessagingLayerused to send messages on the buses.defaultTimeout- The default timeout used when synchronous commands are invoked.
-
-
Method Details
-
setDefaultTimeout
Set the default timeout for this ConcurrentMessagingUtils object. The default timeout will be used to determine the timeout to be used when a synchronous method without a timeout is invoked.- Parameters:
defaultTimeout- The default timeout.
-
getDefaultTimeout
Get the default timeout for this ConcurrentMessagingUtils object.- Returns:
- The default timeout Duration.
-
sendSynchronousCommand
Send synchronously a command on the Buses without a timeout. The timeout used will be the last one defined out of the following:- default timeout
- timeout defined in the
Commandannotation - timeout returned as part of the
CommandAck
- Parameters:
command- The CommandRequest object to be sent on the buses.- Returns:
- The reply of the CommandRequest.
- Throws:
Exception- If an exception was fired by the remote execution of the command or the timeout expired or no valid timeout could be found.
-
sendSynchronousCommand
Send a command on the Buses and wait for the reply within the provided Duration timeout. If the command does not yield a reply within the provided timeout a TimeoutException will be thrown.- Parameters:
command- The CommandRequest object to be sent on the buses.timeout- The Duration timeout. If the reply is not received within the timeout a TimeoutException will be thrown.- Returns:
- The reply of the CommandRequest.
- Throws:
Exception- If an exception was fired by the remote execution of the command or the timeout expired.
-
sendAsynchronousCommand
Send a command on the buses and immediately return a Future that will asynchronously listen for the command reply.- Parameters:
command- The CommandRequest object to be sent on the buses.- Returns:
- A Future on the reply of the command execution. The future will also contain any possible exception thrown during the command execution.
-
getAckForCommand
Send a CommandRequest on the buses and synchronously wait for the Ack to come back within the provided Duration timeout.- Parameters:
command- The CommandRequest object to be sent on the buses.timeout- Duration timeout. If theCommandAckis not received within the timeout a TimeoutException will be thrown.- Returns:
- The CommandAck for the CommandRequest.
- Throws:
Exception- If an exception was fired by the remote execution of the command or the timeout expired.
-
startListeningForStatusBusMessage
public Future<StatusMessage> startListeningForStatusBusMessage(Predicate<BusMessage<? extends Serializable, ?>> filter, Duration timeout) Get a Future on a StatusBusMessage. The content of the Future is filled when the first StatusBusMessage that satisfies the ScriptingStatusBusMessageFilter is received. When the Future is exercised it will return the first ScriptingStatusBusMessage or an ExecutionException will be thrown when the timeout is reached.- Parameters:
filter- ScriptingStatusBusMessageFilter The message filtertimeout- Duration timeout, after which a ScriptiongTimeoutException is thrown. This timeout is from the time the method is invoked. If this timeout is reached an exception will be thrown if/when the Future is exercised.- Returns:
- A Future on a ScriptingStatusBusMessage.
-
startListeningForStatusBusMessage
public Future<StatusMessage> startListeningForStatusBusMessage(Predicate<BusMessage<? extends Serializable, ?>> f) Get a Future on a StatusBusMessage. The content of the Future is filled when the first StatusBusMessage that satisfies the ScriptingStatusBusMessageFilter is received. When the Future is exercised it will return the first ScriptingStatusBusMessage.- Parameters:
f- ScriptingStatusBusMessageFilter The message filter- Returns:
- A Future on a ScriptingStatusBusMessage.
-