MessageType
- Indicates the generic type of messages processed by this
demultiplexer.public abstract class AbstractPacketDemultiplexer<MessageType> extends java.lang.Object implements PacketDemultiplexer<MessageType>
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractPacketDemultiplexer.Tasker |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_THREAD_POOL_SIZE
The default thread pool size.
|
protected static java.util.logging.Logger |
log |
Constructor and Description |
---|
AbstractPacketDemultiplexer() |
AbstractPacketDemultiplexer(int threadPoolSize) |
Modifier and Type | Method and Description |
---|---|
static void |
emulateDelays()
Turns on delay emulation.
|
static java.lang.String |
getHandleMessageReport(long threshold) |
protected abstract java.lang.Integer |
getPacketType(MessageType message) |
protected static int |
getThreadPoolSize() |
protected boolean |
handleMessageSuper(byte[] msg,
NIOHeader header) |
protected boolean |
isCongested(NIOHeader header) |
boolean |
isOrderPreserving(MessageType msg) |
protected boolean |
loopback(java.lang.Object obj) |
protected abstract boolean |
matchesType(java.lang.Object message) |
protected abstract MessageType |
processHeader(byte[] message,
NIOHeader header) |
void |
register(IntegerPacketType type)
Registers
type with this . |
void |
register(IntegerPacketType[] types)
Registers
types with this . |
void |
register(IntegerPacketType[] types,
PacketDemultiplexer<MessageType> pd)
Registers
types with this . |
void |
register(IntegerPacketType type,
PacketDemultiplexer<MessageType> pd)
Registers
type with pd . |
void |
register(java.util.Set<IntegerPacketType> types)
Registers
types with this . |
void |
register(java.util.Set<IntegerPacketType> types,
PacketDemultiplexer<MessageType> pd)
Registers
types with pd ; |
void |
registerOrderPreserving(IntegerPacketType type) |
AbstractPacketDemultiplexer<MessageType> |
setNumDemultiplexerThreads(int corePoolSize)
Sets the number of packet demultiplexing threads.
|
protected AbstractPacketDemultiplexer<MessageType> |
setThreadName(java.lang.String name) |
static void |
setThreadPoolSize(int threadPoolSize) |
void |
stop()
Any created instance of AbstractPacketDemultiplexer or its inheritors
must be cleanly closed by invoking this stop method.
|
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
handleMessage
public static final int DEFAULT_THREAD_POOL_SIZE
protected static final java.util.logging.Logger log
public AbstractPacketDemultiplexer(int threadPoolSize)
threadPoolSize
- Refer documentation for setThreadPoolsize(int)
.public AbstractPacketDemultiplexer()
public static void setThreadPoolSize(int threadPoolSize)
threadPoolSize
- The threadPoolSize parameter determines the level of
parallelism in NIO packet processing. Setting it to 0 means no
parallelism, i.e., each received packet will be fully
processed by NIO before it does anything else. So if the
PacketDemultiplexer.handleMessage(Object,NIOHeader)
implementation
blocks, NIO may deadlock.
Setting the threadPoolSize higher allows
PacketDemultiplexer.handleMessage(Object,NIOHeader)
to include a limited
number of blocking operations, but NIO can still deadlock if
the number of pending PacketDemultiplexer.handleMessage(Object,NIOHeader)
invocations at a node exceeds the thread pool size in this
class. Thus, it is best for
PacketDemultiplexer.handleMessage(Object,NIOHeader)
methods to only
perform operations that return quickly; if longer packet
processing is needed, PacketDemultiplexer.handleMessage(Object,NIOHeader)
must accordingly spawn its own helper threads. It is a bad
idea, for example, for
PacketDemultiplexer.handleMessage(Object,NIOHeader)
to itself send a
request over the network and wait until it gets back a
response.protected static int getThreadPoolSize()
protected abstract java.lang.Integer getPacketType(MessageType message)
protected abstract MessageType processHeader(byte[] message, NIOHeader header)
protected abstract boolean matchesType(java.lang.Object message)
public AbstractPacketDemultiplexer<MessageType> setNumDemultiplexerThreads(int corePoolSize)
corePoolSize
- this
protected AbstractPacketDemultiplexer<MessageType> setThreadName(java.lang.String name)
public java.lang.String toString()
toString
in class java.lang.Object
protected boolean handleMessageSuper(byte[] msg, NIOHeader header) throws org.json.JSONException
org.json.JSONException
public static final void emulateDelays()
protected boolean loopback(java.lang.Object obj)
public boolean isOrderPreserving(MessageType msg)
msg
- public void register(IntegerPacketType type)
type
with this
.type
- public void register(IntegerPacketType type, PacketDemultiplexer<MessageType> pd)
type
with pd
.type
- pd
- protected boolean isCongested(NIOHeader header)
public void register(java.util.Set<IntegerPacketType> types, PacketDemultiplexer<MessageType> pd)
types
with pd
;types
- pd
- public void register(java.util.Set<IntegerPacketType> types)
types
with this
.types
- public void register(IntegerPacketType[] types, PacketDemultiplexer<MessageType> pd)
types
with this
.types
- pd
- public void register(IntegerPacketType[] types)
types
with this
.types
- public void registerOrderPreserving(IntegerPacketType type)
type
- public void stop()
public static java.lang.String getHandleMessageReport(long threshold)
threshold
- threshold
to be handled.