Class ConnectorAdapter

java.lang.Object
java.lang.Thread
com.jme3.network.base.ConnectorAdapter
All Implemented Interfaces:
Runnable

public class ConnectorAdapter extends Thread
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
  • 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 wrap
      protocol - the message protocol used to decode incoming messages
      dispatcher - the listener that receives decoded messages
      errorHandler - the error listener for connector failures
      reliable - true if this adapter represents a reliable channel
  • Method Details

    • close

      public void close()
      Closes the adapter and its underlying connector.
    • dispatch

      protected void dispatch(Message m)
      Dispatches a decoded message to the configured listener.
      Parameters:
      m - the decoded message
    • write

      public void write(ByteBuffer data)
      Queues outbound bytes for writing on the background writer thread.
      Parameters:
      data - the bytes to write
    • handleError

      protected void handleError(Exception e)
      Reports an adapter or connector error if the adapter is still active.
      Parameters:
      e - the error to report
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread