java.lang.Object
net.i2p.util.EventDispatcherImpl
net.i2p.i2ptunnel.I2PTunnelTask
- All Implemented Interfaces:
EventDispatcher
- Direct Known Subclasses:
I2PTunnelClientBase, I2PTunnelServer, I2PTunnelUDPClientBase, I2PTunnelUDPServerBase
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
FieldsConstructor Summary
ConstructorsModifierConstructorDescriptionprotectedI2PTunnelTask(String name, EventDispatcher notifyThis, I2PTunnel tunnel) Create a task bound to a tunnel.Method Summary
Modifier and TypeMethodDescriptionabstract booleanclose(boolean forced) Note that the tunnel can be reopened after this by calling startRunning().voidconnected(I2PSession session) For tasks that don't callI2PTunnel.addSession(I2PSession)directly.booleandestroy()Note that the tunnel cannot be reopened after this by calling startRunning(), as it may destroy the underlying socket manager, depending on implementation.voiddisconnected(I2PSession session) Called when a session is disconnected.voiderrorOccurred(I2PSession session, String message, Throwable error) Does nothing here.protected booleangetBooleanOption(String opt, boolean dflt) Read a boolean client option from the tunnel's properties.intgetId()The id of the client list entry for this task.Returns the I2PSocketManager for this task, or null if not applicable.The I2PTunnel this task runs inside.booleanisOpen()Whether the tunnel is running and accepting connections.voidoptionsUpdated(I2PTunnel tunnel) Notify the task that I2PTunnel's options have been updated.voidreportAbuse(I2PSession session, int severity) Does nothing here.protected voidTell the tunnel that the router connection has dropped.voidsetId(int id) Record the client list entry id for this task.protected voidRecord the display name for this task.voidRebind this task to a different tunnel.toString()The display name given to this task when it was constructed.Methods inherited from class EventDispatcherImpl
attachEventDispatcher, detachEventDispatcher, getEventDispatcher, getEvents, getEventValue, ignoreEvents, notifyEvent, unIgnoreEvents, waitEventValueModifier and TypeMethodDescriptionvoidAttach an EventDispatcher object to the events dispatching chain.voidDetach the specified EventDispatcher object from the events dispatching chain.Object to be used to deliver events (usuallythis, but YMMV).Retrieve the names of all the events that have been received.getEventValue(String name) Retrieve the value currently associated with the specified event value.voidIgnore further event notifications.voidnotifyEvent(String eventName, Object args) Deliver an event.voidAlmost like the method above :-).waitEventValue(String name) Wait until the given event has received a value.
Field Details
open
protected volatile boolean openTrue while the tunnel is running and accepting connections.tunnel
The I2PTunnel this task runs inside.
Constructor Details
I2PTunnelTask
Create a task bound to a tunnel.- Parameters:
name- display name for this task, used in logs and console outputnotifyThis- dispatcher to which this task sends its eventstunnel- the I2PTunnel this task runs inside
Method Details
setTunnel
Rebind this task to a different tunnel.- Parameters:
pTunnel- the tunnel to run inside, for apps using several instances
getTunnel
The I2PTunnel this task runs inside.- Returns:
- the tunnel this task runs inside, as set by the constructor or
setTunnel(I2PTunnel)
getId
public int getId()The id of the client list entry for this task.- Returns:
- the client list entry id, -1 until
setId(int)is called
isOpen
public boolean isOpen()Whether the tunnel is running and accepting connections.- Returns:
- true if the tunnel is running and accepting connections
setId
public void setId(int id) Record the client list entry id for this task.- Parameters:
id- the client list entry id to record for this task
setName
Record the display name for this task.- Parameters:
name- display name to record for this task
routerDisconnected
protected void routerDisconnected()Tell the tunnel that the router connection has dropped.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().- Parameters:
forced- true to interrupt an in-progress build, false to close gracefully- Returns:
- true if the tunnel was closed and can be reopened by startRunning()
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:
- true if every resource was released
optionsUpdated
Notify the task that I2PTunnel's options have been updated. Extending classes should override and callI2PTunnel.getClientOptions(), then update the I2PSocketManager. Does nothing here.- Parameters:
tunnel- the tunnel whose client options were updated
connected
For tasks that don't callI2PTunnel.addSession(I2PSession)directly.- Parameters:
session- the newly connected session to register with the tunnel
disconnected
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 dropped, removed from the tunnel here
getBooleanOption
Read a boolean client option from the tunnel's properties.- Parameters:
opt- the property name to readdflt- the value to return when the property is not set- Returns:
- the boolean option
errorOccurred
Does nothing here. Extending classes may override.- Parameters:
session- the session that reported the errormessage- a human-readable description of the errorerror- the error that was thrown, or null if none was reported
reportAbuse
Does nothing here. Extending classes may override.- Parameters:
session- the session reported for abusive behaviourseverity- the abuse severity, from the I2PClient status codes
getSocketManager
Returns the I2PSocketManager for this task, or null if not applicable. Extending classes may override to return their socket manager.- Returns:
- the socket manager
toString