Package net.i2p.i2ptunnel
Class TunnelControllerGroup
- java.lang.Object
-
- net.i2p.i2ptunnel.TunnelControllerGroup
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
TunnelControllerGroup.CustomThreadPoolExecutor
Not really needed for now but in case we want to add some hooks like afterExecute().
-
Field Summary
Fields Modifier and Type Field Description (package private) static String
DEFAULT_CONFIG_FILE
-
Constructor Summary
Constructors Constructor Description TunnelControllerGroup(I2PAppContext context, ClientAppManager mgr, String[] args)
Instantiation only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (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 and clear all outstanding messages from any of the known tunnels.(package private) ThreadPoolExecutor
getClientExecutor()
I2PAppContext
getContext()
HelperList<TunnelController>
getControllers()
Retrieve a list of tunnels known.String
getDisplayName()
ClientApp interfacestatic TunnelControllerGroup
getInstance()
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.String
getName()
ClientApp interfaceClientAppState
getState()
ClientApp interfacevoid
loadControllers(File cfgFile)
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.void
removeConfig(TunnelController tc)
Remove the configuration of this tunnel onlyList<String>
removeController(TunnelController controller)
Stop and remove the given tunnel.List<String>
restartAllControllers()
Restart all tunnels.void
saveConfig()
Deprecated.use saveConfig(TunnelController) or removeConfig(TunnelController)void
saveConfig(String cfgFile)
Deprecated.void
saveConfig(TunnelController tc)
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
shutdown(String[] args)
ClientApp interfaceList<String>
startAllControllers()
Start all tunnels.void
startup()
ClientApp interfaceList<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)
-
-
-
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 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 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 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
public static TunnelControllerGroup getInstance(I2PAppContext ctx)
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
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
-
getContext
public I2PAppContext 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
public ClientAppState getState()
ClientApp interface
-
getName
public String getName()
ClientApp interface
-
getDisplayName
public String getDisplayName()
ClientApp interface- Specified by:
getDisplayName
in interfaceClientApp
- Returns:
- non-null
- Since:
- 0.9.4
-
shutdown
public void shutdown(String[] args)
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
public void loadControllers(File cfgFile)
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
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. 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
public List<String> 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
public List<String> startAllControllers()
Start all tunnels. Side effect - clears all messages from all controllers.- Returns:
- list of messages the tunnels generate when started
-
restartAllControllers
public List<String> restartAllControllers()
Restart all tunnels. Side effect - clears all messages from all controllers.- Returns:
- list of messages the tunnels generate when restarted
-
clearAllMessages
public List<String> clearAllMessages()
Fetch and clear all outstanding messages from any of the known tunnels.- Returns:
- list of messages the tunnels have generated
-
saveConfig
@Deprecated public void saveConfig() throws IOException
Deprecated.use saveConfig(TunnelController) or removeConfig(TunnelController)Save the configuration of all known tunnels to the default config file- Throws:
IOException
-
saveConfig
@Deprecated public void saveConfig(String cfgFile) throws IOException
Deprecated.Save the configuration of all known tunnels to the given file- Throws:
IOException
-
saveConfig
public void saveConfig(TunnelController tc) throws IOException
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
public void removeConfig(TunnelController tc) throws IOException
Remove the configuration of this tunnel only- Throws:
IOException
- Since:
- 0.9.42
-
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
-
-