public class KernelAdapter
extends java.lang.Thread
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
Constructor and Description |
---|
KernelAdapter(DefaultServer server,
Kernel kernel,
MessageProtocol protocol,
MessageListener<HostedConnection> messageDispatcher,
boolean reliable) |
Modifier and Type | Method and Description |
---|---|
void |
broadcast(Filter<? super Endpoint> filter,
java.nio.ByteBuffer data,
boolean reliable,
boolean copy) |
void |
close() |
protected void |
connectionClosed(Endpoint p) |
protected void |
createAndDispatch(EndpointEvent event) |
protected void |
createAndDispatch(Envelope env) |
protected void |
dispatch(Endpoint p,
Message m)
Note on threading for those writing their own server
or adapter implementations.
|
protected void |
flushEvents() |
protected HostedConnection |
getConnection(Endpoint p) |
Kernel |
getKernel() |
protected MessageBuffer |
getMessageBuffer(Endpoint p) |
void |
initialize() |
protected void |
reportError(Endpoint p,
java.lang.Object context,
java.lang.Exception e) |
void |
run() |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public KernelAdapter(DefaultServer server, Kernel kernel, MessageProtocol protocol, MessageListener<HostedConnection> messageDispatcher, boolean reliable)
public Kernel getKernel()
public void initialize()
public void broadcast(Filter<? super Endpoint> filter, java.nio.ByteBuffer data, boolean reliable, boolean copy)
public void close() throws java.lang.InterruptedException
java.lang.InterruptedException
protected void reportError(Endpoint p, java.lang.Object context, java.lang.Exception e)
protected HostedConnection getConnection(Endpoint p)
protected void connectionClosed(Endpoint p)
protected void dispatch(Endpoint p, Message m)
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.
protected MessageBuffer getMessageBuffer(Endpoint p)
protected void createAndDispatch(Envelope env)
protected void createAndDispatch(EndpointEvent event)
protected void flushEvents()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread