java.lang.Object
net.i2p.sam.client.SAMReader

public class SAMReaderextends Object
Read from a socket, producing events for any SAM message read.
  • Field Details

    • _log

      private final Log _log
      Logger for this class.
    • _inRaw

      private final InputStream _inRaw
      The stream read from the SAM server.
    • _listener

      private final SAMReader.SAMClientEventListener _listener
      Told about the messages read.
    • _live

      private volatile boolean _live
      False once the reader is stopping.
    • _thread

      private Thread _thread
      The thread reading messages, null before start.
    • _count

      private static final AtomicInteger _count
      Counts the readers created, for thread names.
  • Constructor Details

    • SAMReader

      public SAMReader(I2PAppContext context, InputStream samIn, SAMReader.SAMClientEventListener listener)
      Reads a SAM protocol stream and passes each message to a listener.
      Parameters:
      context - the router context used to obtain the class log
      samIn - the stream positioned at the start of a SAM protocol stream
      listener - notified of each SAM message parsed off samIn
  • Method Details

    • startReading

      public void startReading()
      Starts the thread that reads and parses the SAM stream.
    • stopReading

      public void stopReading()
      Stops the reader thread and closes the underlying stream.
    • processEvent

      private void processEvent(String major, String minor, Properties params)
      Big ugly method parsing everything. If I cared, I'd factor this out into a dozen tiny methods.
      Parameters:
      major - the event's major verb, e.g. HELLO or SESSION
      minor - the event's minor noun, e.g. REPLY or STATUS
      params - the name-value pairs parsed from the event line