Class SelectorKernel.SelectorThread

java.lang.Object
java.lang.Thread
com.jme3.network.kernel.tcp.SelectorKernel.SelectorThread
All Implemented Interfaces:
Runnable
Enclosing class:
SelectorKernel

protected class SelectorKernel.SelectorThread extends Thread
This class is purposely tucked neatly away because messing with the selector from other threads for any reason is very bad. This is the safest architecture.
Author:
Paul Speed
  • Constructor Details

    • SelectorThread

      public SelectorThread()
      Creates the selector thread.
  • Method Details

    • connect

      public void connect() throws IOException
      Opens and binds the selector infrastructure.
      Throws:
      IOException - if the selector or socket cannot be opened
    • close

      public void close() throws IOException, InterruptedException
      Stops the selector thread and closes its resources.
      Throws:
      IOException - if socket shutdown fails
      InterruptedException - if interrupted while waiting for shutdown
    • wakeupSelector

      protected void wakeupSelector()
      Wakes the selector if it is blocked in select().
    • setupSelectorOptions

      protected void setupSelectorOptions()
      Recomputes selector interest ops for endpoints with pending output.
    • accept

      protected void accept(SelectionKey key) throws IOException
      Accepts a new incoming TCP connection.
      Parameters:
      key - the selected accept key
      Throws:
      IOException - if the connection cannot be accepted or configured
    • cancel

      protected void cancel(NioEndpoint p) throws IOException
      Cancels and closes the specified endpoint.
      Parameters:
      p - the endpoint to cancel
      Throws:
      IOException - if closing the channel fails
    • cancel

      protected void cancel(SelectionKey key, SocketChannel c) throws IOException
      Cancels and closes the specified selection key and channel.
      Parameters:
      key - the key to cancel
      c - the channel to close
      Throws:
      IOException - if closing the channel fails
    • read

      protected void read(SelectionKey key) throws IOException
      Reads pending bytes from a readable channel.
      Parameters:
      key - the readable key
      Throws:
      IOException - if the read fails
    • write

      protected void write(SelectionKey key) throws IOException
      Flushes pending endpoint data to a writable channel.
      Parameters:
      key - the writable key
      Throws:
      IOException - if writing fails
    • select

      protected void select() throws IOException
      Waits for and dispatches selector activity.
      Throws:
      IOException - if selector processing fails
    • run

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