Class ConnectorAdapter
java.lang.Object
java.lang.Thread
com.jme3.network.base.ConnectorAdapter
- All Implemented Interfaces:
Runnable
Wraps a single Connector and forwards new messages
to the supplied message dispatcher. This is used
by DefaultClient to manage its connector objects.
This is only responsible for message reading and provides
no support for buffering writes.
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
- Author:
- Paul Speed
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classBackground writer thread that drains the outbound queue.Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionConnectorAdapter(Connector connector, MessageProtocol protocol, MessageListener<Object> dispatcher, ErrorListener<Object> errorHandler, boolean reliable) Creates an adapter for a connector and starts a background writer thread. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the adapter and its underlying connector.protected voidDispatches a decoded message to the configured listener.protected voidReports an adapter or connector error if the adapter is still active.voidrun()voidwrite(ByteBuffer data) Queues outbound bytes for writing on the background writer thread.Methods inherited from class Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, toString, yield
-
Constructor Details
-
ConnectorAdapter
public ConnectorAdapter(Connector connector, MessageProtocol protocol, MessageListener<Object> dispatcher, ErrorListener<Object> errorHandler, boolean reliable) Creates an adapter for a connector and starts a background writer thread.- Parameters:
connector- the transport connector to wrapprotocol- the message protocol used to decode incoming messagesdispatcher- the listener that receives decoded messageserrorHandler- the error listener for connector failuresreliable- true if this adapter represents a reliable channel
-
-
Method Details
-
close
public void close()Closes the adapter and its underlying connector. -
dispatch
Dispatches a decoded message to the configured listener.- Parameters:
m- the decoded message
-
write
Queues outbound bytes for writing on the background writer thread.- Parameters:
data- the bytes to write
-
handleError
Reports an adapter or connector error if the adapter is still active.- Parameters:
e- the error to report
-
run
-