Class SelectorKernel

java.lang.Object
com.jme3.network.kernel.AbstractKernel
com.jme3.network.kernel.tcp.SelectorKernel
All Implemented Interfaces:
Kernel

public class SelectorKernel extends AbstractKernel
A Kernel implementation based on NIO selectors.
Author:
Paul Speed
  • Constructor Details

    • SelectorKernel

      public SelectorKernel(InetAddress host, int port)
      Creates a selector kernel for the specified host and port.
      Parameters:
      host - the local bind address
      port - the local bind port
    • SelectorKernel

      public SelectorKernel(int port) throws IOException
      Creates a selector kernel bound to the specified port on the wildcard address.
      Parameters:
      port - the local bind port
      Throws:
      IOException - if the address cannot be prepared
    • SelectorKernel

      public SelectorKernel(InetSocketAddress address)
      Creates a selector kernel for the specified socket address.
      Parameters:
      address - the local socket address
  • Method Details

    • createSelectorThread

      protected SelectorKernel.SelectorThread createSelectorThread()
      Creates the selector thread implementation used by this kernel.
      Returns:
      the selector thread
    • initialize

      public void initialize()
      Description copied from interface: Kernel
      Initializes the kernel and starts any internal processing.
    • terminate

      public void terminate() throws InterruptedException
      Description copied from interface: Kernel
      Gracefully terminates the kernel and stops any internal daemon processing. This method will not return until all internal threads have been shut down.
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting
    • broadcast

      public void broadcast(Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy)
      Description copied from interface: Kernel
      Dispatches the data to all endpoints managed by the kernel that match the specified endpoint filter. If 'copy' is true then the implementation will copy the byte buffer before delivering it to endpoints. This allows the caller to reuse the data buffer. Though it is important that the buffer not be changed by another thread while this call is running. Only the bytes from data.position() to data.remaining() are sent.
      Parameters:
      filter - the endpoint filter used to select recipients
      data - the payload to send
      reliable - true to use reliable transport semantics
      copy - true to copy the buffer before dispatching it
    • addEndpoint

      protected NioEndpoint addEndpoint(SocketChannel c)
      Creates and registers a new endpoint for the accepted channel.
      Parameters:
      c - the accepted socket channel
      Returns:
      the created endpoint
    • removeEndpoint

      protected void removeEndpoint(NioEndpoint p, SocketChannel c)
      Removes bookkeeping for a closed endpoint.
      Parameters:
      p - the endpoint being removed
      c - the underlying socket channel
    • closeEndpoint

      protected void closeEndpoint(NioEndpoint p) throws IOException
      Called by the endpoints when they need to be closed.
      Parameters:
      p - the endpoint to close
      Throws:
      IOException - if the endpoint cannot be closed cleanly
    • wakeupSelector

      protected void wakeupSelector()
      Used internally by the endpoints to wake up the selector when they have data to send.
    • newData

      protected void newData(NioEndpoint p, SocketChannel c, ByteBuffer shared, int size)
      Queues newly read endpoint data as an envelope.
      Parameters:
      p - the source endpoint
      c - the source socket channel
      shared - the shared read buffer
      size - the number of valid bytes in shared