net.i2p.i2ptunnel

## Class I2PTunnelTask

- java.lang.Object
- - net.i2p.util.EventDispatcherImpl
  - - net.i2p.i2ptunnel.I2PTunnelTask

- All Implemented Interfaces:
    EventDispatcher
  Direct Known Subclasses:
    I2PTunnelClientBase, I2PTunnelServer, I2PTunnelUDPClientBase, I2PTunnelUDPServerBase

      public abstract class I2PTunnelTask
      extends EventDispatcherImpl

  Base class for I2P tunnel servers and clients.

  Use caution when extending externally. Should be maintained as stable API, but confirm before use. No startRunning() method; all extending classes implement one.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `open`
    `I2PTunnel` | `tunnel`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `I2PTunnelTask(String name, EventDispatcher notifyThis, I2PTunnel tunnel)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract boolean` | `close(boolean forced)` Note that the tunnel can be reopened after this by calling startRunning().
    `void` | `connected(I2PSession session)` For tasks that don't call I2PTunnel.addSession() directly
    `boolean` | `destroy()` Note that the tunnel cannot be reopened after this by calling startRunning(), as it may destroy the underlying socket manager, depending on implementation.
    `void` | `disconnected(I2PSession session)` Called when a session is disconnected.
    `void` | `errorOccurred(I2PSession session, String message, Throwable error)` Does nothing here.
    `protected boolean` | `getBooleanOption(String opt, boolean dflt)`
    `int` | `getId()`
    `I2PTunnel` | `getTunnel()`
    `boolean` | `isOpen()`
    `void` | `optionsUpdated(I2PTunnel tunnel)` Notify the task that I2PTunnel's options have been updated.
    `void` | `reportAbuse(I2PSession session, int severity)` Does nothing here.
    `protected void` | `routerDisconnected()`
    `void` | `setId(int id)`
    `protected void` | `setName(String name)`
    `void` | `setTunnel(I2PTunnel pTunnel)` for apps that use multiple I2PTunnel instances
    `String` | `toString()`

    - ### Methods inherited from class net.i2p.util.EventDispatcherImpl

      `attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValue`

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

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

- - ### Field Detail

    - #### open

          protected volatile boolean open

    - #### tunnel

          public I2PTunnel tunnel

  - ### Constructor Detail

    - #### I2PTunnelTask

          protected I2PTunnelTask(String name,
                                  EventDispatcher notifyThis,
                                  I2PTunnel tunnel)

  - ### Method Detail

    - #### close

          public abstract boolean close(boolean forced)

      Note that the tunnel can be reopened after this by calling startRunning(). This may not release all resources. In particular, the I2PSocketManager remains and it may have timer threads that continue running. To release all resources permanently, call destroy().
      Returns:
        success

    - #### connected

          public void connected(I2PSession session)

      For tasks that don't call I2PTunnel.addSession() directly

    - #### destroy

          public boolean destroy()

      Note that the tunnel cannot be reopened after this by calling startRunning(), as it may destroy the underlying socket manager, depending on implementation. This should release all resources. The implementation here simply calls close(true). Extending classes should override to release all resources.
      Returns:
        success

    - #### disconnected

          public void disconnected(I2PSession session)

      Called when a session is disconnected.

      This method removes the session from the tunnel and notifies the router that disconnection occurred.

      Parameters:
        `session` - the session that was disconnected

    - #### errorOccurred

          public void errorOccurred(I2PSession session,
                                    String message,
                                    Throwable error)

      Does nothing here. Extending classes may override.

    - #### getBooleanOption

          protected boolean getBooleanOption(String opt,
                                             boolean dflt)

    - #### getId

          public int getId()

    - #### getTunnel

          public I2PTunnel getTunnel()

    - #### isOpen

          public boolean isOpen()

    - #### optionsUpdated

          public void optionsUpdated(I2PTunnel tunnel)

      Notify the task that I2PTunnel's options have been updated. Extending classes should override and call I2PTunnel.getClientOptions(), then update the I2PSocketManager. Does nothing here.

    - #### reportAbuse

          public void reportAbuse(I2PSession session,
                                  int severity)

      Does nothing here. Extending classes may override.

    - #### routerDisconnected

          protected void routerDisconnected()

    - #### setId

          public void setId(int id)

    - #### setName

          protected void setName(String name)

    - #### setTunnel

          public void setTunnel(I2PTunnel pTunnel)

      for apps that use multiple I2PTunnel instances

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`