Package net.i2p.i2ptunnel
Class TunnelControllerGroup
java.lang.Object
net.i2p.i2ptunnel.TunnelControllerGroup
- All Implemented Interfaces:
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
Modifier and TypeClassDescription(package private) static class
Not really needed for now but in case we want to add some hooks like afterExecute(). -
Field Summary
-
Constructor Summary
ConstructorDescriptionTunnelControllerGroup
(I2PAppContext context, ClientAppManager mgr, String[] args) Instantiation only. -
Method Summary
Modifier and TypeMethodDescription(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)Fetch and clear all outstanding messages from any of the known tunnels.(package private) ThreadPoolExecutor
HelperRetrieve a list of tunnels known.ClientApp interfacestatic TunnelControllerGroup
In I2PAppContext will instantiate if necessary and always return non-null.static TunnelControllerGroup
getInstance
(I2PAppContext ctx) In I2PAppContext will instantiate if necessary and always return non-null.getName()
ClientApp interfacegetState()
ClientApp interfacevoid
loadControllers
(File cfgFile) Load up all of the tunnels configured in the given file.static void
(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
Stop all tunnels, reload config, and restart those configured to do so.void
Remove the configuration of this tunnel onlyremoveController
(TunnelController controller) Stop and remove the given tunnel.Restart all tunnels.void
Deprecated.use saveConfig(TunnelController) or removeConfig(TunnelController)void
saveConfig
(String cfgFile) Deprecated.void
Save the configuration of this tunnel only, may be new.void
shutdown()
Warning - destroys the singleton! Caller must root a new context before calling instance() or main() again.void
ClientApp interfaceStart all tunnels.void
startup()
ClientApp interfaceStop all tunnels.void
Stop and remove reference to all known tunnels (but dont delete any config file or do other silly things)
-
Field Details
-
DEFAULT_CONFIG_FILE
- See Also:
-
-
Constructor Details
-
TunnelControllerGroup
Instantiation only. Caller must call startup(). Config file problems will not throw exception until startup().- Parameters:
mgr
- may be nullargs
- zero or one args, which may be one config file or one config directory. If not absolute will be relative to the context's config dir, if empty or null, the default is i2ptunnel.config for a config file and i2ptunnel.config.d for a config directory- Throws:
IllegalArgumentException
- if too many args- Since:
- 0.9.4
-
-
Method Details
-
getInstance
In I2PAppContext will instantiate if necessary and always return non-null. As of 0.9.4, when in RouterContext, will return null if the TCG has not yet been started by the router. As of 0.9.41, that's true for Android as well. In Android, this should be used for all calls except from LoadClientsJob, as we do not want to instantiate TCG too early. Android must do null checks on the return value.- Throws:
IllegalArgumentException
- if unable to load from i2ptunnel.config
-
getInstance
In I2PAppContext will instantiate if necessary and always return non-null. When in RouterContext, will return null (except in Android) if the TCG has not yet been started by the router. In Android, if the old instance uses a stale context, it will replace it. In Android, this should only be called from LoadClientsJob, as we do not want to instantiate TCG too early.- Throws:
IllegalArgumentException
- if unable to load from i2ptunnel.config- Since:
- 0.9.41
-
main
- 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
-
getContext
Helper- Since:
- 0.9.49
-
startup
public void startup()ClientApp interface- Specified by:
startup
in interfaceClientApp
- Throws:
IllegalArgumentException
- if unable to load config from file- Since:
- 0.9.4
-
getState
ClientApp interface -
getName
ClientApp interface -
getDisplayName
ClientApp interface- Specified by:
getDisplayName
in interfaceClientApp
- Returns:
- non-null
- Since:
- 0.9.4
-
shutdown
ClientApp interface -
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
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. This does not return or clear the controller messages.- 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
Add the given tunnel to the set of known controllers (but dont add it to a config file or start it or anything) -
removeController
Stop and remove the given tunnel. Side effect - clears all messages the controller. Does NOT delete the configuration - must call saveConfig() or removeConfig() also.- Returns:
- list of messages from the controller as it is stopped
-
stopAllControllers
Stop all tunnels. May be restarted. Side effect - clears all messages from all controllers.- Returns:
- list of messages the tunnels generate when stopped
-
startAllControllers
Start all tunnels. Side effect - clears all messages from all controllers.- Returns:
- list of messages the tunnels generate when started
-
restartAllControllers
Restart all tunnels. Side effect - clears all messages from all controllers.- Returns:
- list of messages the tunnels generate when restarted
-
clearAllMessages
Fetch and clear all outstanding messages from any of the known tunnels.- Returns:
- list of messages the tunnels have generated
-
saveConfig
Deprecated.use saveConfig(TunnelController) or removeConfig(TunnelController)Save the configuration of all known tunnels to the default config file- Throws:
IOException
-
saveConfig
Deprecated.Save the configuration of all known tunnels to the given file- Throws:
IOException
-
saveConfig
Save the configuration of this tunnel only, may be new. Side effect: for split config, sets "confFile" property to absolute path.- Throws:
IOException
- Since:
- 0.9.42
-
removeConfig
Remove the configuration of this tunnel only- Throws:
IOException
- Since:
- 0.9.42
-
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
Note the fact that the controller is using the session so that it isn't destroyed prematurely. -
release
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
-