java.lang.Object
net.i2p.sam.client.SAMReader
Read from a socket, producing events for any SAM message read.
Nested Class Summary
Modifier and TypeClassDescriptionprivate classReads SAM messages on its own thread.static interfaceAsync event notification interface for SAM clients.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicIntegerCounts the readers created, for thread names.private final InputStreamThe stream read from the SAM server.private final SAMReader.SAMClientEventListenerTold about the messages read.private booleanFalse once the reader is stopping.private final LogLogger for this class.private ThreadThe thread reading messages, null before start.Constructor Summary
ConstructorsConstructorDescriptionSAMReader(I2PAppContext context, InputStream samIn, SAMReader.SAMClientEventListener listener) Reads a SAM protocol stream and passes each message to a listener.Method Summary
Modifier and TypeMethodDescriptionprivate voidprocessEvent(String major, String minor, Properties params) Big ugly method parsing everything.voidStarts the thread that reads and parses the SAM stream.voidStops the reader thread and closes the underlying stream.
Field Details
_log
Logger for this class._inRaw
The stream read from the SAM server._listener
Told about the messages read._live
private volatile boolean _liveFalse once the reader is stopping._thread
The thread reading messages, null before start._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 logsamIn- the stream positioned at the start of a SAM protocol streamlistener- 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
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 SESSIONminor- the event's minor noun, e.g. REPLY or STATUSparams- the name-value pairs parsed from the event line