Package org.eso.ias.command
Class CommandSender
java.lang.Object
org.eso.ias.command.CommandSender
- All Implemented Interfaces:
ReplyListener
Objects of this class send commands and optionally wait for the reply through the kafka topics.
Methods to send commands are synchronized i.e. it is not possible to send a command before the
previous send terminates. This is in particular true for the request/reply
(the
sendSync(String, CommandType, List, Map, long, TimeUnit)) that releases the lock
when the reply has been received or the timelout elapses.
This forces the sender to serialize requests and replies and can be a limitation if the sender needs
to sand a bounce of commands.
There is room for improvement, but at the present it is all the IAS need.
To implement the reply, the CommandCenter uses a BlockingQueue (repliesQueue)
to get the received reply or the timeout.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCommandSender(String senderFullRuningId, SimpleStringProducer stringProducer, String senderId, String brokers) ConstructorCommandSender(org.eso.ias.types.Identifier identifier, SimpleStringProducer stringProducer, String brokers) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the object and release the resourcesvoidnewReply(ReplyMessage reply) Invoked when a new reply has been producedvoidSend a command asynchronously This method sends the commands but do not wait for the reception of the replysendSync(String destId, CommandType command, List<String> params, Map<String, String> properties, long timeout, TimeUnit timeUnit) Send a command synchronously This method sends the commands and holds until receives the replay or a timeout elapses.voidsetUp()
-
Field Details
-
senderFullRunningId
The full running id of the sender -
senderId
The id of the sender
-
-
Constructor Details
-
CommandSender
public CommandSender(String senderFullRuningId, SimpleStringProducer stringProducer, String senderId, String brokers) Constructor- Parameters:
senderFullRuningId- The full runing id of the senderstringProducer- The string producer to publish commandssenderId- The id of the senderbrokers- URL of kafka brokers
-
CommandSender
public CommandSender(org.eso.ias.types.Identifier identifier, SimpleStringProducer stringProducer, String brokers) Constructor- Parameters:
identifier- The identifier of the senderstringProducer- The string producer to publish commandsbrokers- URL of kafka brokers
-
-
Method Details
-
setUp
- Throws:
Exception
-
close
Close the object and release the resources- Throws:
Exception
-
newReply
Invoked when a new reply has been produced- Specified by:
newReplyin interfaceReplyListener- Parameters:
reply- The not-null reply read from the topic
-
sendSync
public Optional<ReplyMessage> sendSync(String destId, CommandType command, List<String> params, Map<String, String> properties, long timeout, TimeUnit timeUnit) throws ExceptionSend a command synchronously This method sends the commands and holds until receives the replay or a timeout elapses. Send-reply is not available for broadcast- Parameters:
destId- The id of the destination of the command (cannot be BROADCAST)command- The command to sendparams- The optional parameters of the commandproperties- The optional properties of the commandtimeout- the time interval for the timeouttimeUnit- the time unit for the timeout- Returns:
- the reply received by the destinator of the command; empty if the waiting time elapsed before getting the reply
- Throws:
InterruptedExceptionException
-
sendAsync
public void sendAsync(String destId, CommandType command, List<String> params, Map<String, String> properties) throws ExceptionSend a command asynchronously This method sends the commands but do not wait for the reception of the reply- Parameters:
destId- The id of the destination of the command (cannot be BROADCAST)command- The command to sendparams- The optional parameters of the commandproperties- The optional properties of the command- Throws:
Exception
-