Class NioEndpoint

java.lang.Object
com.jme3.network.kernel.tcp.NioEndpoint
All Implemented Interfaces:
Endpoint

public class NioEndpoint extends Object implements Endpoint
Endpoint implementation that encapsulates the channel IO based connection information and keeps track of the outbound data queue for the channel.
Author:
Paul Speed
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final ByteBuffer
    Marker queued to request endpoint closure after pending writes flush.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NioEndpoint(SelectorKernel kernel, long id, SocketChannel socket)
    Creates an endpoint backed by a socket channel.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this endpoint without flushing any of its currently enqueued outbound data.
    void
    close(boolean flushData)
    Closes this endpoint, optionally flushing any queued data before closing.
    Returns the transport specific remote address of this endpoint as a string.
    long
    Returns an ID that is unique for this endpoint within its Kernel instance.
    Returns the kernel to which this endpoint belongs.
    protected boolean
    Returns true if outbound data is queued for this endpoint.
    boolean
    Returns true if this endpoint is currently connected.
    protected ByteBuffer
    Called by the SelectorKernel to get the current top buffer for writing.
    protected ByteBuffer
    Called by the SelectorKernel when the top buffer has been exhausted.
    void
    Sends data to the other end of the connection represented by this endpoint.
    protected void
    send(ByteBuffer data, boolean copy, boolean wakeup)
    The wakeup option is used internally when the kernel is broadcasting out to a bunch of endpoints and doesn't want to necessarily wakeup right away.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • CLOSE_MARKER

      protected static final ByteBuffer CLOSE_MARKER
      Marker queued to request endpoint closure after pending writes flush.
  • Constructor Details

    • NioEndpoint

      public NioEndpoint(SelectorKernel kernel, long id, SocketChannel socket)
      Creates an endpoint backed by a socket channel.
      Parameters:
      kernel - the owning selector kernel
      id - the endpoint id
      socket - the socket channel
  • Method Details

    • getKernel

      public Kernel getKernel()
      Description copied from interface: Endpoint
      Returns the kernel to which this endpoint belongs.
      Specified by:
      getKernel in interface Endpoint
      Returns:
      the owning kernel
    • close

      public void close()
      Description copied from interface: Endpoint
      Closes this endpoint without flushing any of its currently enqueued outbound data.
      Specified by:
      close in interface Endpoint
    • close

      public void close(boolean flushData)
      Description copied from interface: Endpoint
      Closes this endpoint, optionally flushing any queued data before closing. As soon as this method is called, new send() calls will fail with an exception... even while close() is still flushing the earlier queued messages.
      Specified by:
      close in interface Endpoint
      Parameters:
      flushData - true to flush queued data before closing
    • getId

      public long getId()
      Description copied from interface: Endpoint
      Returns an ID that is unique for this endpoint within its Kernel instance.
      Specified by:
      getId in interface Endpoint
      Returns:
      the endpoint id
    • getAddress

      public String getAddress()
      Description copied from interface: Endpoint
      Returns the transport specific remote address of this endpoint as a string. This may or may not be unique per endpoint depending on the type of transport.
      Specified by:
      getAddress in interface Endpoint
      Returns:
      the remote address string
    • isConnected

      public boolean isConnected()
      Description copied from interface: Endpoint
      Returns true if this endpoint is currently connected.
      Specified by:
      isConnected in interface Endpoint
      Returns:
      true if the endpoint is connected
    • send

      protected void send(ByteBuffer data, boolean copy, boolean wakeup)
      The wakeup option is used internally when the kernel is broadcasting out to a bunch of endpoints and doesn't want to necessarily wakeup right away.
      Parameters:
      data - the bytes to queue
      copy - true to copy the provided buffer
      wakeup - true to wake the selector after enqueueing
    • peekPending

      protected ByteBuffer peekPending()
      Called by the SelectorKernel to get the current top buffer for writing.
      Returns:
      the current pending buffer, or null if none are queued
    • removePending

      protected ByteBuffer removePending()
      Called by the SelectorKernel when the top buffer has been exhausted.
      Returns:
      the removed pending buffer, or null if none are queued
    • hasPending

      protected boolean hasPending()
      Returns true if outbound data is queued for this endpoint.
      Returns:
      true if pending outbound data exists
    • send

      public void send(ByteBuffer data)
      Description copied from interface: Endpoint
      Sends data to the other end of the connection represented by this endpoint.
      Specified by:
      send in interface Endpoint
      Parameters:
      data - the bytes to send
    • toString

      public String toString()
      Overrides:
      toString in class Object