net.i2p.i2ptunnel
Class TunnelControllerGroup

java.lang.Object
  extended by net.i2p.i2ptunnel.TunnelControllerGroup
All Implemented Interfaces:
ClientApp

public class TunnelControllerGroup
extends Object
implements ClientApp

Coordinate a set of tunnels within the JVM, loading and storing their config to disk, and building new ones as requested. This is the entry point from clients.config.


Nested Class Summary
(package private) static class TunnelControllerGroup.CustomThreadPoolExecutor
          Not really needed for now but in case we want to add some hooks like afterExecute().
 
Field Summary
(package private) static String DEFAULT_CONFIG_FILE
           
 
Constructor Summary
TunnelControllerGroup(I2PAppContext context, ClientAppManager mgr, String[] args)
          Instantiation only.
 
Method Summary
(package private)  void acquire(TunnelController controller, I2PSession session)
          Note the fact that the controller is using the session so that it isn't destroyed prematurely.
 void addController(TunnelController controller)
          Add the given tunnel to the set of known controllers (but dont add it to a config file or start it or anything)
 List<String> clearAllMessages()
          Fetch all outstanding messages from any of the known tunnels
(package private)  ThreadPoolExecutor getClientExecutor()
           
 List<TunnelController> getControllers()
          Retrieve a list of tunnels known.
 String getDisplayName()
          ClientApp interface
static TunnelControllerGroup getInstance()
          In I2PAppContext will instantiate if necessary and always return non-null.
 String getName()
          ClientApp interface
 ClientAppState getState()
          ClientApp interface
 void loadControllers(String configFile)
          Load up all of the tunnels configured in the given file.
static void main(String[] args)
           
(package private)  void release(TunnelController controller, I2PSession session)
          Note the fact that the controller is no longer using the session, and if no other controllers are using it, destroy the session.
 void reloadControllers()
          Stop all tunnels, reload config, and restart those configured to do so.
 List<String> removeController(TunnelController controller)
          Stop and remove the given tunnel
 List<String> restartAllControllers()
          Restart all tunnels
 void saveConfig()
          Save the configuration of all known tunnels to the default config file
 void saveConfig(String configFile)
          Save the configuration of all known tunnels to the given file
 void shutdown()
          Warning - destroys the singleton! Caller must root a new context before calling instance() or main() again.
 void shutdown(String[] args)
          ClientApp interface
 List<String> startAllControllers()
          Start all tunnels
 void startup()
          ClientApp interface
 List<String> stopAllControllers()
          Stop all tunnels.
 void unloadControllers()
          Stop and remove reference to all known tunnels (but dont delete any config file or do other silly things)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONFIG_FILE

static final String DEFAULT_CONFIG_FILE
See Also:
Constant Field Values
Constructor Detail

TunnelControllerGroup

public TunnelControllerGroup(I2PAppContext context,
                             ClientAppManager mgr,
                             String[] args)
Instantiation only. Caller must call startup(). Config file problems will not throw exception until startup().

Parameters:
mgr - may be null
args - one arg, the config file, if not absolute will be relative to the context's config dir, if empty or null, the default is i2ptunnel.config
Throws:
IllegalArgumentException - if too many args
Since:
0.9.4
Method Detail

getInstance

public static TunnelControllerGroup getInstance()
In I2PAppContext will instantiate if necessary and always return non-null. As of 0.9.4, when in RouterContext, will return null (except in Android) if the TCG has not yet been started by the router.

Throws:
IllegalArgumentException - if unable to load from i2ptunnel.config

main

public static void main(String[] args)
Parameters:
args - one arg, the config file, if not absolute will be relative to the context's config dir, if no args, the default is i2ptunnel.config
Throws:
IllegalArgumentException - if unable to load from config from file

startup

public void startup()
ClientApp interface

Specified by:
startup in interface ClientApp
Throws:
IllegalArgumentException - if unable to load config from file
Since:
0.9.4

getState

public ClientAppState getState()
ClientApp interface

Specified by:
getState in interface ClientApp
Returns:
non-null
Since:
0.9.4

getName

public String getName()
ClientApp interface

Specified by:
getName in interface ClientApp
Returns:
non-null
Since:
0.9.4

getDisplayName

public String getDisplayName()
ClientApp interface

Specified by:
getDisplayName in interface ClientApp
Returns:
non-null
Since:
0.9.4

shutdown

public void shutdown(String[] args)
ClientApp interface

Specified by:
shutdown in interface ClientApp
Parameters:
args - generally null but could be stopArgs from clients.config
Since:
0.9.4

shutdown

public void shutdown()
Warning - destroys the singleton! Caller must root a new context before calling instance() or main() again. Agressively kill and null everything to reduce memory usage in the JVM after stopping, and to recognize what must be reinitialized on restart (Android)

Since:
0.8.8

loadControllers

public void loadControllers(String configFile)
Load up all of the tunnels configured in the given file. Prior to 0.9.20, also started the tunnels. As of 0.9.20, does not start the tunnels, you must call startup() or getInstance() instead of loadControllers(). DEPRECATED for use outside this class. Use startup() or getInstance().

Throws:
IllegalArgumentException - if unable to load from file

reloadControllers

public void reloadControllers()
Stop all tunnels, reload config, and restart those configured to do so. WARNING - Does NOT simply reload the configuration!!! This is probably not what you want.

Throws:
IllegalArgumentException - if unable to reload config file

unloadControllers

public void unloadControllers()
Stop and remove reference to all known tunnels (but dont delete any config file or do other silly things)


addController

public void addController(TunnelController controller)
Add the given tunnel to the set of known controllers (but dont add it to a config file or start it or anything)


removeController

public List<String> removeController(TunnelController controller)
Stop and remove the given tunnel

Returns:
list of messages from the controller as it is stopped

stopAllControllers

public List<String> stopAllControllers()
Stop all tunnels. May be restarted.

Returns:
list of messages the tunnels generate when stopped

startAllControllers

public List<String> startAllControllers()
Start all tunnels

Returns:
list of messages the tunnels generate when started

restartAllControllers

public List<String> restartAllControllers()
Restart all tunnels

Returns:
list of messages the tunnels generate when restarted

clearAllMessages

public List<String> clearAllMessages()
Fetch all outstanding messages from any of the known tunnels

Returns:
list of messages the tunnels have generated

saveConfig

public void saveConfig()
                throws IOException
Save the configuration of all known tunnels to the default config file

Throws:
IOException

saveConfig

public void saveConfig(String configFile)
                throws IOException
Save the configuration of all known tunnels to the given file

Throws:
IOException

getControllers

public List<TunnelController> getControllers()
Retrieve a list of tunnels known. Side effect: if the tunnels have not been loaded from config yet, they will be.

Returns:
list of TunnelController objects
Throws:
IllegalArgumentException - if unable to load config from file

acquire

void acquire(TunnelController controller,
             I2PSession session)
Note the fact that the controller is using the session so that it isn't destroyed prematurely.


release

void release(TunnelController controller,
             I2PSession session)
Note the fact that the controller is no longer using the session, and if no other controllers are using it, destroy the session.


getClientExecutor

ThreadPoolExecutor getClientExecutor()
Returns:
non-null
Since:
0.8.8 Moved from I2PTunnelClientBase in 0.9.18