Class CommandSender

java.lang.Object
org.eso.ias.command.CommandSender
All Implemented Interfaces:
ReplyListener

public class CommandSender extends Object implements 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 Details

    • senderFullRunningId

      public final String senderFullRunningId
      The full running id of the sender
    • senderId

      public final String 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 sender
      stringProducer - The string producer to publish commands
      senderId - The id of the sender
      brokers - URL of kafka brokers
    • CommandSender

      public CommandSender(org.eso.ias.types.Identifier identifier, SimpleStringProducer stringProducer, String brokers)
      Constructor
      Parameters:
      identifier - The identifier of the sender
      stringProducer - The string producer to publish commands
      brokers - URL of kafka brokers
  • Method Details

    • setUp

      public void setUp() throws Exception
      Throws:
      Exception
    • close

      public void close() throws Exception
      Close the object and release the resources
      Throws:
      Exception
    • newReply

      public void newReply(ReplyMessage reply)
      Invoked when a new reply has been produced
      Specified by:
      newReply in interface ReplyListener
      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 Exception
      Send 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 send
      params - The optional parameters of the command
      properties - The optional properties of the command
      timeout - the time interval for the timeout
      timeUnit - 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:
      InterruptedException
      Exception
    • sendAsync

      public void sendAsync(String destId, CommandType command, List<String> params, Map<String,String> properties) throws Exception
      Send 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 send
      params - The optional parameters of the command
      properties - The optional properties of the command
      Throws:
      Exception