com.jme3.network.kernel.tcp
Class SelectorKernel

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

public class SelectorKernel
extends AbstractKernel

A Kernel implementation based on NIO selectors.


Nested Class Summary
protected  class SelectorKernel.SelectorThread
          This class is purposely tucked neatly away because messing with the selector from other threads for any reason is very bad.
 
Field Summary
 
Fields inherited from interface com.jme3.network.kernel.Kernel
EVENTS_PENDING
 
Constructor Summary
SelectorKernel(java.net.InetAddress host, int port)
           
SelectorKernel(java.net.InetSocketAddress address)
           
SelectorKernel(int port)
           
 
Method Summary
protected  NioEndpoint addEndpoint(java.nio.channels.SocketChannel c)
           
 void broadcast(Filter<? super Endpoint> filter, java.nio.ByteBuffer data, boolean reliable, boolean copy)
          Dispatches the data to all endpoints managed by the kernel that match the specified endpoint filter..
protected  void closeEndpoint(NioEndpoint p)
          Called by the endpoints when they need to be closed.
protected  SelectorKernel.SelectorThread createSelectorThread()
           
 void initialize()
          Initializes the kernel and starts any internal processing.
protected  void newData(NioEndpoint p, java.nio.channels.SocketChannel c, java.nio.ByteBuffer shared, int size)
           
protected  void removeEndpoint(NioEndpoint p, java.nio.channels.SocketChannel c)
           
 void terminate()
          Gracefully terminates the kernel and stops any internal daemon processing.
protected  void wakeupSelector()
          Used internally by the endpoints to wakeup the selector when they have data to send.
 
Methods inherited from class com.jme3.network.kernel.AbstractKernel
addEnvelope, addEvent, hasEnvelopes, nextEndpointId, nextEvent, read, reportError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectorKernel

public SelectorKernel(java.net.InetAddress host,
                      int port)

SelectorKernel

public SelectorKernel(int port)
               throws java.io.IOException
Throws:
java.io.IOException

SelectorKernel

public SelectorKernel(java.net.InetSocketAddress address)
Method Detail

createSelectorThread

protected SelectorKernel.SelectorThread createSelectorThread()

initialize

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


terminate

public void terminate()
               throws java.lang.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:
java.lang.InterruptedException

broadcast

public void broadcast(Filter<? super Endpoint> filter,
                      java.nio.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.


addEndpoint

protected NioEndpoint addEndpoint(java.nio.channels.SocketChannel c)

removeEndpoint

protected void removeEndpoint(NioEndpoint p,
                              java.nio.channels.SocketChannel c)

closeEndpoint

protected void closeEndpoint(NioEndpoint p)
                      throws java.io.IOException
Called by the endpoints when they need to be closed.

Throws:
java.io.IOException

wakeupSelector

protected void wakeupSelector()
Used internally by the endpoints to wakeup the selector when they have data to send.


newData

protected void newData(NioEndpoint p,
                       java.nio.channels.SocketChannel c,
                       java.nio.ByteBuffer shared,
                       int size)