net.i2p.i2ptunnel

## Class I2PTunnelServer

- java.lang.Object
- - net.i2p.i2ptunnel.I2PTunnelTask
  - - net.i2p.i2ptunnel.I2PTunnelServer

- All Implemented Interfaces:
    Runnable, EventDispatcher
  Direct Known Subclasses:
    I2PTunnelHTTPServer, I2PTunnelIRCServer

      public class I2PTunnelServer
      extends I2PTunnelTask
      implements Runnable

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static long` | `__serverId`
    `protected Log` | `_log`
    `protected boolean` | `bidir`
    `protected I2PServerSocket` | `i2pss`
    `protected int` | `localPort`
    `protected long` | `readTimeout` default timeout to 3 minutes - override if desired
    `protected InetAddress` | `remoteHost`
    `protected int` | `remotePort`
    `protected Object` | `slock`
    `protected I2PSocketManager` | `sockMgr`
    `protected I2PTunnelTask` | `task`

    - ### Fields inherited from class net.i2p.i2ptunnel.I2PTunnelTask

      `open`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `I2PTunnelServer(InetAddress host, int port, File privkey, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)`
    `I2PTunnelServer(InetAddress host, int port, InputStream privData, String privkeyname, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)`
    `I2PTunnelServer(InetAddress host, int port, String privData, Logging l, EventDispatcher notifyThis, I2PTunnel tunnel)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `blockingHandle(I2PSocket socket)`
    `boolean` | `close(boolean forced)`
    `protected int` | `getHandlerCount()`
    `long` | `getReadTimeout()` Get the read idle timeout for newly-created connections (in milliseconds).
    `void` | `run()` If usePool is set, this starts the executor pool.
    `void` | `setReadTimeout(long ms)` Set the read idle timeout for newly-created connections (in milliseconds).
    `boolean` | `shouldUsePool()`
    `void` | `startRunning()` Start running the I2PTunnelServer.

    - ### Methods inherited from class net.i2p.i2ptunnel.I2PTunnelTask

      `attachEventDispatcher, detachEventDispatcher, disconnected, errorOccurred, getEventDispatcher, getEvents, getEventValue, getId, getTunnel, ignoreEvents, isOpen, notifyEvent, reportAbuse, routerDisconnected, setId, setName, setTunnel, toString, unIgnoreEvents, waitEventValue`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### _log

          protected final Log _log

    - #### sockMgr

          protected I2PSocketManager sockMgr

    - #### i2pss

          protected I2PServerSocket i2pss

    - #### slock

          protected final Object slock

    - #### remoteHost

          protected InetAddress remoteHost

    - #### remotePort

          protected int remotePort

    - #### readTimeout

          protected long readTimeout

      default timeout to 3 minutes - override if desired

    - #### __serverId

          protected static volatile long __serverId

    - #### task

          protected I2PTunnelTask task

    - #### bidir

          protected boolean bidir

    - #### localPort

          protected int localPort

  - ### Constructor Detail

    - #### I2PTunnelServer

          public I2PTunnelServer(InetAddress host,
                         int port,
                         String privData,
                         Logging l,
                         EventDispatcher notifyThis,
                         I2PTunnel tunnel)

      Throws:
        `IllegalArgumentException` - if the I2CP configuration is b0rked so badly that we cant create a socketManager

    - #### I2PTunnelServer

          public I2PTunnelServer(InetAddress host,
                         int port,
                         File privkey,
                         String privkeyname,
                         Logging l,
                         EventDispatcher notifyThis,
                         I2PTunnel tunnel)

      Throws:
        `IllegalArgumentException` - if the I2CP configuration is b0rked so badly that we cant create a socketManager

    - #### I2PTunnelServer

          public I2PTunnelServer(InetAddress host,
                         int port,
                         InputStream privData,
                         String privkeyname,
                         Logging l,
                         EventDispatcher notifyThis,
                         I2PTunnel tunnel)

      Throws:
        `IllegalArgumentException` - if the I2CP configuration is b0rked so badly that we cant create a socketManager

  - ### Method Detail

    - #### startRunning

          public void startRunning()

      Start running the I2PTunnelServer.

    - #### setReadTimeout

          public void setReadTimeout(long ms)

      Set the read idle timeout for newly-created connections (in milliseconds). After this time expires without data being reached from the I2P network, the connection itself will be closed.

    - #### getReadTimeout

          public long getReadTimeout()

      Get the read idle timeout for newly-created connections (in milliseconds).
      Returns:
        The read timeout used for connections

    - #### close

          public boolean close(boolean forced)

      Specified by:
        `close` in class `I2PTunnelTask`

    - #### getHandlerCount

          protected int getHandlerCount()

    - #### run

          public void run()

      If usePool is set, this starts the executor pool. Then, do the accept() loop, and either hands each I2P socket to the executor or runs it in-line.
      Specified by:
        `run` in interface `Runnable`

    - #### shouldUsePool

          public boolean shouldUsePool()

    - #### blockingHandle

          protected void blockingHandle(I2PSocket socket)