java.lang.Object
net.i2p.sam.client.SAMClientEventListenerImpl
net.i2p.sam.client.SAMEventHandler
- All Implemented Interfaces:
SAMReader.SAMClientEventListener
- Direct Known Subclasses:
SAMStreamSend.SendEventHandler, SAMStreamSink.SinkEventHandler
Simple helper implementation of a the SAMClientEventListener.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ObjectLock for waiting on the hello reply.private BooleanTrue if the hello succeeded, null while waiting.private final LogLogger for the SAM event handling.The naming replies received, by name.private final ObjectLock for waiting on the naming reply.private BooleanTrue if session add succeeded, null while waiting.private final ObjectLock for waiting on the session create reply.private BooleanTrue if session create succeeded, null while waiting.private final ObjectLock for waiting on the stream status reply.private BooleanTrue if stream status succeeded, null while waiting.private StringThe SAM version reported by the hello.Fields inherited from interface SAMReader.SAMClientEventListener
NAMING_REPLY_INVALID_KEY, NAMING_REPLY_KEY_NOT_FOUND, NAMING_REPLY_OK, SESSION_STATUS_DUPLICATE_DEST, SESSION_STATUS_I2P_ERROR, SESSION_STATUS_INVALID_KEY, SESSION_STATUS_OK, STREAM_CLOSED_CANT_REACH_PEER, STREAM_CLOSED_I2P_ERROR, STREAM_CLOSED_OK, STREAM_CLOSED_PEER_NOT_FOUND, STREAM_CLOSED_TIMEOUT, STREAM_STATUS_CANT_REACH_PEER, STREAM_STATUS_I2P_ERROR, STREAM_STATUS_INVALID_KEY, STREAM_STATUS_OK, STREAM_STATUS_TIMEOUTModifier and TypeFieldDescriptionstatic final StringNaming lookup failed because the private key is invalid.static final StringNaming lookup failed because no key matches the requested name.static final StringNaming lookup succeeded.static final StringSession creation failed because the destination is already in use.static final StringSESSION_STATUS_I2P_ERROR.static final StringSession creation failed because the supplied private key is invalid.static final StringSession creation succeeded.static final StringStream closed because the peer became unreachable.static final StringSTREAM_CLOSED_I2P_ERROR.static final StringStream closed normally.static final StringStream closed because the destination was no longer known to the router.static final StringStream closed because the lease expired.static final StringStream connect failed because the peer could not be reached.static final StringSTREAM_STATUS_I2P_ERROR.static final StringStream connect failed because the private key is invalid.static final StringStream connect succeeded.static final StringStream connect failed because the lease expired before it was established.Constructor Summary
ConstructorsConstructorDescriptionBinds the log this handler reports unhandled messages to.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidhelloReplyReceived(boolean ok, String version) Records the HELLO outcome and version, then wakes any waiter.voidnamingReplyReceived(String name, String result, String value, String msg) Files a naming reply under its name, value on success and result otherwise.voidsessionStatusReceived(String result, String destination, String msg) May be called twice, first for CREATE and second for ADD.voidstreamStatusReceived(String result, String id, String message) Records the session status result, then wakes any waiter.voidunknownMessageReceived(String major, String minor, Properties params) Logs a message this handler has no handling for.Wait for the connection to be established, returning the server version if everything went ok.waitForNamingReply(String name) Return the destination found matching the name, or null if the key was not able to be retrieved.booleanWait for the session to be added, returning true if everything went ok.booleanWait for the session to be created, returning true if everything went ok.booleanWait for the stream to be created, returning true if everything went ok.Methods inherited from class SAMClientEventListenerImpl
datagramReceived, destReplyReceived, pingReceived, pongReceived, rawReceived, streamClosedReceived, streamConnectedReceived, streamDataReceivedModifier and TypeMethodDescriptionvoiddatagramReceived(String dest, byte[] data, int offset, int length, int fromPort, int toPort) Called when a datagram arrives.voiddestReplyReceived(String publicKey, String privateKey) Called when a DEST reply arrives.voidpingReceived(String data) Called when a PING reply arrives.voidpongReceived(String data) Called when a PONG reply arrives.voidrawReceived(byte[] data, int offset, int length, int fromPort, int toPort, int protocol) Called when a raw datagram arrives.voidstreamClosedReceived(String result, String id, String message) Called when a STREAM CLOSED reply arrives.voidstreamConnectedReceived(String remoteDestination, String id) Called when a STREAM CONNECTED reply arrives.voidstreamDataReceived(String id, byte[] data, int offset, int length) Called when data arrives on a stream.
Field Details
_log
Logger for the SAM event handling._helloOk
True if the hello succeeded, null while waiting._version
The SAM version reported by the hello._helloLock
Lock for waiting on the hello reply._sessionCreateOk
True if session create succeeded, null while waiting._sessionAddOk
True if session add succeeded, null while waiting._streamStatusOk
True if stream status succeeded, null while waiting._sessionCreateLock
Lock for waiting on the session create reply._namingReplyLock
Lock for waiting on the naming reply._streamStatusLock
Lock for waiting on the stream status reply._namingReplies
Constructor Details
SAMEventHandler
Binds the log this handler reports unhandled messages to.- Parameters:
ctx- the context whose log manager supplies the logger for this handler
Method Details
helloReplyReceived
Records the HELLO outcome and version, then wakes any waiter.- Specified by:
helloReplyReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
helloReplyReceivedin classSAMClientEventListenerImpl- Parameters:
ok- whether the SAM bridge accepted our HELLO greetingversion- the bridge version string it reported, null if none was sent
sessionStatusReceived
May be called twice, first for CREATE and second for ADD.- Specified by:
sessionStatusReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
sessionStatusReceivedin classSAMClientEventListenerImpl- Parameters:
result- the session status, one of the SESSION_STATUS_* constantsdestination- the base64 destination the status refers tomsg- the human-readable explanation supplied by the bridge
namingReplyReceived
Files a naming reply under its name, value on success and result otherwise.- Specified by:
namingReplyReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
namingReplyReceivedin classSAMClientEventListenerImpl- Parameters:
name- the requested host name or service stringresult- the reply status, one of the NAMING_REPLY_* constantsvalue- the resolved value, null when the lookup failedmsg- the human-readable explanation supplied by the bridge
streamStatusReceived
Records the session status result, then wakes any waiter.- Specified by:
streamStatusReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
streamStatusReceivedin classSAMClientEventListenerImpl- Parameters:
result- the stream status, one of the STREAM_STATUS_* constantsid- the stream ID from the reply, null under SAM v3message- the human-readable explanation supplied by the bridge
unknownMessageReceived
Logs a message this handler has no handling for.- Specified by:
unknownMessageReceivedin interfaceSAMReader.SAMClientEventListener- Overrides:
unknownMessageReceivedin classSAMClientEventListenerImpl- Parameters:
major- the first token of the SAM message, naming the command familyminor- the second token, naming the specific command within that familyparams- the remaining name=value pairs of the line, quotes stripped
waitForHelloReply
Wait for the connection to be established, returning the server version if everything went ok.- Returns:
- SAM server version if everything ok, or null on failure
waitForSessionCreateReply
public boolean waitForSessionCreateReply()Wait for the session to be created, returning true if everything went ok.- Returns:
- true if everything ok
waitForSessionAddReply
public boolean waitForSessionAddReply()Wait for the session to be added, returning true if everything went ok.- Returns:
- true if everything ok
waitForStreamStatusReply
public boolean waitForStreamStatusReply()Wait for the stream to be created, returning true if everything went ok.- Returns:
- true if everything ok
waitForNamingReply