Class MessageProcessor

  • All Implemented Interfaces:
    SRPSocketCallback

    public class MessageProcessor
    extends java.lang.Object
    implements SRPSocketCallback
    MessageProcessor is responsible for creating and decoding messages, and tracking response objects.
    • Field Detail

      • MAX_COMMAND_TIME

        public static final int MAX_COMMAND_TIME
        Maximum time a command may take before its deemed 'lost'
        See Also:
        Constant Field Values
      • DEFAULT_PORT

        public static final int DEFAULT_PORT
        Default CLBv2 slow-control port.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MessageProcessor

        public MessageProcessor​(java.net.Inet4Address inetAddress)
                         throws java.io.IOException
        Creates a new MessageProcessor object for the given CLB. Message processors take care of delivering commands, receiving replies, processing events etc. For high level control you would usually not use this class.
        Parameters:
        inetAddress - The address of the CLB to control. May also be a broadcast address.
        Throws:
        java.io.IOException - If the socket can not be created.
    • Method Detail

      • setThreadPoolSize

        public static void setThreadPoolSize​(int tpSize)
      • postEvent

        public void postEvent​(int type,
                              MessageWriter mw)
        Posts an event to a node or a broadcast group. Unlike commands, events do not require a response. The event may not be send immediately. Use flush() to send the message, or disable batch mode using setBatchMode(boolean). Events may also be broadcasted, using a broadcast socket.
        Parameters:
        type - The message type identifier.
        mw - The content of the event.
      • postCommand

        public <T> Response<T> postCommand​(int type,
                                           MessageWriter mw,
                                           MessageDecoder<T> decoder,
                                           java.lang.Object user)
        Posts a command to a node. Commands are posted to a MessagePacket. If the processor is in batch mode, the command may not be send immediately. To force the sending of the command, invoke flush().
        Parameters:
        type - The type identifier of the command
        mw - The MessageWriter containing the command to send
        decoder - The Decoder to use for decoding, may be null for Void response.
        user - A user object.
        Returns:
        A future response.
      • flush

        public void flush()
        Flushes the message processor, sending all queued messages.
      • setEventListener

        public <T> void setEventListener​(int type,
                                         MessageDecoder<T> decoder,
                                         MessageEventHandler<T> handler)
        Register an event handler for a specific message type.
        Parameters:
        type - The type to listen to.
        decoder - The decoder to use.
        handler - The handler to invoke.
      • removeEventListenr

        public void removeEventListenr​(int type)
        Removes an event listener.
        Parameters:
        type - The type to remove.
      • setBatchMode

        public void setBatchMode​(boolean batch)
        Sets batch mode of the CLBControl on or off. When set, all commands will be batched until:
        1. A response is read (Response.get())
        2. The maximum packet size has been reached
        3. flush() is invoked
        By default batching mode is off.
        Parameters:
        batch - Set batching mode on or off.
      • isBatchMode

        public boolean isBatchMode()
        Returns weather or not batch-mode is enabled.
        Returns:
        true if enabled, false otherwise.
      • close

        public void close()
                   throws java.lang.InterruptedException
        Closes this message processor and all related resources.
        Throws:
        java.lang.InterruptedException - If an interrupt was generated before all resources where deallocated.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • maxPacketSize

        public int maxPacketSize()
      • cleanCache

        public void cleanCache()