net.i2p.router.tunnel.pool

## Class BuildExecutor

- java.lang.Object
- - net.i2p.router.tunnel.pool.BuildExecutor

- All Implemented Interfaces:
    Runnable

      class BuildExecutor
      extends Object
      implements Runnable

  Single threaded controller of the tunnel creation process, spanning all tunnel pools. Essentially, this loops across the pools, sees which want to build tunnels, and fires off the necessary activities if the load allows. If nothing wants to build any tunnels, it waits for a short period before looping again (or until it is told that something changed, such as a tunnel failed, new client started up, or tunnel creation was aborted). Note that 10 minute tunnel expiration is hardcoded in here. As of 0.8.11, inbound request handling is done in a separate thread.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `(package private) static class` | `BuildExecutor.Result` Build result enumeration.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BuildExecutor(RouterContext ctx, TunnelPoolManager mgr)` Create a new BuildExecutor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `buildComplete(PooledTunnelCreatorConfig cfg, BuildExecutor.Result result)` Handle a completed tunnel build.
    `(package private) void` | `buildTunnel(PooledTunnelCreatorConfig cfg)` Build a tunnel with the given configuration.
    `boolean` | `fullStats()`
    `boolean` | `isRunning()` Check if the executor is currently running.
    `(package private) PooledTunnelCreatorConfig` | `removeFromBuilding(long id)` This returns the PTCC up to a minute after it 'expired', thus allowing us to still use a tunnel if it was accepted, and to update peer stats.
    `void` | `repoll()` Signal the executor to repoll for tunnel building opportunities.
    `void` | `restart()`
    `void` | `run()` Starts the tunnel building process in a loop and takes care of error handling.
    `void` | `shutdown()` Cannot be restarted.
    `boolean` | `wasRecentlyBuilding(long replyId)` Check if a tunnel build was recently attempted.

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

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

- - ### Constructor Detail

    - #### BuildExecutor

          public BuildExecutor(RouterContext ctx,
                               TunnelPoolManager mgr)

      Create a new BuildExecutor.
      Parameters:
        `ctx` - the router context
        `mgr` - the tunnel pool manager

  - ### Method Detail

    - #### buildComplete

          public void buildComplete(PooledTunnelCreatorConfig cfg,
                                    BuildExecutor.Result result)

      Handle a completed tunnel build.
      Parameters:
        `cfg` - the tunnel configuration that completed
        `result` - the build result (success, failure, etc.)

    - #### buildTunnel

          void buildTunnel(PooledTunnelCreatorConfig cfg)

      Build a tunnel with the given configuration.
      Parameters:
        `cfg` - the tunnel configuration to build

    - #### fullStats

          public boolean fullStats()

      Returns:
        true if full statistics are enabled

    - #### isRunning

          public boolean isRunning()

      Check if the executor is currently running.
      Returns:
        true if running, false otherwise

    - #### removeFromBuilding

          PooledTunnelCreatorConfig removeFromBuilding(long id)

      This returns the PTCC up to a minute after it 'expired', thus allowing us to still use a tunnel if it was accepted, and to update peer stats. This means that manager.buildComplete() could be called more than once, and a build can be failed or successful after it was timed out, which will affect the stats and profiles. But that's ok. A peer that rejects slowly gets penalized twice, for example.
      Returns:
        ptcc or null

    - #### repoll

          public void repoll()

      Signal the executor to repoll for tunnel building opportunities.

    - #### restart

          public void restart()

    - #### run

          public void run()

      Starts the tunnel building process in a loop and takes care of error handling. Catches a specific fatal error related to Java versioning and ensures the running state is properly reset on exit.
      Specified by:
        `run` in interface `Runnable`

    - #### shutdown

          public void shutdown()

      Cannot be restarted.

    - #### wasRecentlyBuilding

          public boolean wasRecentlyBuilding(long replyId)

      Check if a tunnel build was recently attempted.
      Parameters:
        `replyId` - the reply message ID to check
      Returns:
        true if the build was recently attempted, false otherwise