All Implemented Interfaces:
SAMReader.SAMClientEventListener
Direct Known Subclasses:
SAMStreamSend.SendEventHandler, SAMStreamSink.SinkEventHandler

public class SAMEventHandlerextends SAMClientEventListenerImpl
Simple helper implementation of a the SAMClientEventListener.
  • Field Details

    • _log

      private final Log _log
      Logger for the SAM event handling.
    • _helloOk

      private Boolean _helloOk
      True if the hello succeeded, null while waiting.
    • _version

      private String _version
      The SAM version reported by the hello.
    • _helloLock

      private final Object _helloLock
      Lock for waiting on the hello reply.
    • _sessionCreateOk

      private Boolean _sessionCreateOk
      True if session create succeeded, null while waiting.
    • _sessionAddOk

      private Boolean _sessionAddOk
      True if session add succeeded, null while waiting.
    • _streamStatusOk

      private Boolean _streamStatusOk
      True if stream status succeeded, null while waiting.
    • _sessionCreateLock

      private final Object _sessionCreateLock
      Lock for waiting on the session create reply.
    • _namingReplyLock

      private final Object _namingReplyLock
      Lock for waiting on the naming reply.
    • _streamStatusLock

      private final Object _streamStatusLock
      Lock for waiting on the stream status reply.
    • _namingReplies

      private final Map<String,String> _namingReplies
      The naming replies received, by name.
  • Constructor Details

    • SAMEventHandler

      public SAMEventHandler(I2PAppContext ctx)
      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

      public void helloReplyReceived(boolean ok, String version)
      Records the HELLO outcome and version, then wakes any waiter.
      Specified by:
      helloReplyReceived in interface SAMReader.SAMClientEventListener
      Overrides:
      helloReplyReceived in class SAMClientEventListenerImpl
      Parameters:
      ok - whether the SAM bridge accepted our HELLO greeting
      version - the bridge version string it reported, null if none was sent
    • sessionStatusReceived

      public void sessionStatusReceived(String result, String destination, String msg)
      May be called twice, first for CREATE and second for ADD.
      Specified by:
      sessionStatusReceived in interface SAMReader.SAMClientEventListener
      Overrides:
      sessionStatusReceived in class SAMClientEventListenerImpl
      Parameters:
      result - the session status, one of the SESSION_STATUS_* constants
      destination - the base64 destination the status refers to
      msg - the human-readable explanation supplied by the bridge
    • namingReplyReceived

      public void namingReplyReceived(String name, String result, String value, String msg)
      Files a naming reply under its name, value on success and result otherwise.
      Specified by:
      namingReplyReceived in interface SAMReader.SAMClientEventListener
      Overrides:
      namingReplyReceived in class SAMClientEventListenerImpl
      Parameters:
      name - the requested host name or service string
      result - the reply status, one of the NAMING_REPLY_* constants
      value - the resolved value, null when the lookup failed
      msg - the human-readable explanation supplied by the bridge
    • streamStatusReceived

      public void streamStatusReceived(String result, String id, String message)
      Records the session status result, then wakes any waiter.
      Specified by:
      streamStatusReceived in interface SAMReader.SAMClientEventListener
      Overrides:
      streamStatusReceived in class SAMClientEventListenerImpl
      Parameters:
      result - the stream status, one of the STREAM_STATUS_* constants
      id - the stream ID from the reply, null under SAM v3
      message - the human-readable explanation supplied by the bridge
    • unknownMessageReceived

      public void unknownMessageReceived(String major, String minor, Properties params)
      Logs a message this handler has no handling for.
      Specified by:
      unknownMessageReceived in interface SAMReader.SAMClientEventListener
      Overrides:
      unknownMessageReceived in class SAMClientEventListenerImpl
      Parameters:
      major - the first token of the SAM message, naming the command family
      minor - the second token, naming the specific command within that family
      params - the remaining name=value pairs of the line, quotes stripped
    • waitForHelloReply

      public String 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

      public String waitForNamingReply(String name)
      Return the destination found matching the name, or null if the key was not able to be retrieved.
      Parameters:
      name - name to be looked for, or "ME"
      Returns:
      destination found matching the name, or null