Package org.km3net.clb.remote.msg
Class MessageProcessor
- java.lang.Object
-
- org.km3net.clb.remote.msg.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 Summary
Fields Modifier and Type Field Description static int
DEFAULT_PORT
Default CLBv2 slow-control port.static int
MAX_COMMAND_TIME
Maximum time a command may take before its deemed 'lost'static long
MAX_KEEP_ALIVE_SEC
-
Constructor Summary
Constructors Constructor Description MessageProcessor(java.net.Inet4Address inetAddress)
Creates a new MessageProcessor object for the given CLB.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanCache()
void
close()
Closes this message processor and all related resources.protected void
finalize()
void
flush()
Flushes the message processor, sending all queued messages.SRPSocket
getSocket()
boolean
isBatchMode()
Returns weather or not batch-mode is enabled.boolean
isBroadcast()
int
maxPacketSize()
<T> Response<T>
postCommand(int type, MessageWriter mw, MessageDecoder<T> decoder, java.lang.Object user)
Posts a command to a node.void
postEvent(int type, MessageWriter mw)
Posts an event to a node or a broadcast group.void
removeEventListenr(int type)
Removes an event listener.void
setBatchMode(boolean batch)
Sets batch mode of the CLBControl on or off.<T> void
setEventListener(int type, MessageDecoder<T> decoder, MessageEventHandler<T> handler)
Register an event handler for a specific message type.static void
setThreadPoolSize(int tpSize)
void
srpNewData()
-
-
-
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
-
MAX_KEEP_ALIVE_SEC
public static final long MAX_KEEP_ALIVE_SEC
- 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. Useflush()
to send the message, or disable batch mode usingsetBatchMode(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, invokeflush()
.- Parameters:
type
- The type identifier of the commandmw
- The MessageWriter containing the command to senddecoder
- 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:- A response is read (Response.get())
- The maximum packet size has been reached
- flush() is invoked
- 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 classjava.lang.Object
- Throws:
java.lang.Throwable
-
maxPacketSize
public int maxPacketSize()
-
getSocket
public SRPSocket getSocket()
-
srpNewData
public void srpNewData()
- Specified by:
srpNewData
in interfaceSRPSocketCallback
-
isBroadcast
public boolean isBroadcast()
-
cleanCache
public void cleanCache()
-
-