Class KernelAdapter
- All Implemented Interfaces:
Runnable
This adapter assumes a simple protocol where two bytes define a (short) object size with the object data to follow. Note: this limits the size of serialized objects to 32676 bytes... even though, for example, datagram packets can hold twice that. :P
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorDescriptionKernelAdapter
(DefaultServer server, Kernel kernel, MessageProtocol protocol, MessageListener<HostedConnection> messageDispatcher, boolean reliable) -
Method Summary
Modifier and TypeMethodDescriptionvoid
broadcast
(Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy) void
close()
protected void
protected void
createAndDispatch
(EndpointEvent event) protected void
protected void
Note on threading for those writing their own server or adapter implementations.protected void
protected HostedConnection
protected MessageBuffer
void
protected void
reportError
(Endpoint p, Object context, Exception e) void
run()
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
KernelAdapter
public KernelAdapter(DefaultServer server, Kernel kernel, MessageProtocol protocol, MessageListener<HostedConnection> messageDispatcher, boolean reliable)
-
-
Method Details
-
getKernel
-
initialize
public void initialize() -
broadcast
public void broadcast(Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy) -
close
- Throws:
InterruptedException
-
reportError
-
getConnection
-
connectionClosed
-
dispatch
Note on threading for those writing their own server or adapter implementations. The rule that a single connection be processed by only one thread at a time is more about ensuring that the messages are delivered in the order that they are received than for any user-code safety. 99% of the time the user code should be writing for multithreaded access anyway.The issue with the messages is that if an implementation is using a general thread pool then it would be possible for a naive implementation to have one thread grab an Envelope from connection 1's and another grab the next Envelope. Since an Envelope may contain several messages, delivering the second thread's messages before or during the first's would be really confusing and hard to code for in user code.
And that's why this note is here. DefaultServer does a rudimentary per-connection locking but it couldn't possibly guard against out of order Envelope processing.
-
getMessageBuffer
-
createAndDispatch
-
createAndDispatch
-
flushEvents
protected void flushEvents() -
run
public void run()
-