public class MessageProcessor extends java.lang.Object implements SRPSocketCallback
Modifier and Type | Field and 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 and Description |
---|
MessageProcessor(java.net.Inet4Address inetAddress)
Creates a new MessageProcessor object for the given CLB.
|
Modifier and Type | Method and 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.
|
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.
|
void |
srpNewData() |
public static final int MAX_COMMAND_TIME
public static final long MAX_KEEP_ALIVE_SEC
public static final int DEFAULT_PORT
public MessageProcessor(java.net.Inet4Address inetAddress) throws java.io.IOException
inetAddress
- The address of the CLB to control. May also be a broadcast address.java.io.IOException
- If the socket can not be created.public void postEvent(int type, MessageWriter mw)
flush()
to send the message, or disable batch mode using
setBatchMode(boolean)
. Events may also be broadcasted, using a broadcast socket.type
- The message type identifier.mw
- The content of the event.public <T> Response<T> postCommand(int type, MessageWriter mw, MessageDecoder<T> decoder, java.lang.Object user)
flush()
.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.public void flush()
public <T> void setEventListener(int type, MessageDecoder<T> decoder, MessageEventHandler<T> handler)
type
- The type to listen to.decoder
- The decoder to use.handler
- The handler to invoke.public void removeEventListenr(int type)
type
- The type to remove.public void setBatchMode(boolean batch)
batch
- Set batching mode on or off.public boolean isBatchMode()
true
if enabled, false
otherwise.public void close() throws java.lang.InterruptedException
java.lang.InterruptedException
- If an interrupt was generated before all resources where
deallocated.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public int maxPacketSize()
public SRPSocket getSocket()
public void srpNewData()
srpNewData
in interface SRPSocketCallback
public void cleanCache()