net.i2p.sam
Class SAMMessageSession

java.lang.Object
  extended by net.i2p.sam.SAMMessageSession
Direct Known Subclasses:
SAMDatagramSession, SAMRawSession

public abstract class SAMMessageSession
extends java.lang.Object

Base abstract class for SAM message-based sessions.

Author:
human

Nested Class Summary
 class SAMMessageSession.SAMMessageSessionHandler
          SAM message-based session handler, running in its own thread
 
Constructor Summary
protected SAMMessageSession(java.io.InputStream destStream, java.util.Properties props)
          Initialize a new SAM message-based session.
protected SAMMessageSession(java.lang.String dest, java.util.Properties props)
          Initialize a new SAM message-based session.
 
Method Summary
 void close()
          Close a SAM message-based session.
 Destination getDestination()
          Get the SAM message-based session Destination.
protected  I2PSession getI2PSession()
          Get the I2PSession object used by the SAM message-based session.
protected abstract  void messageReceived(byte[] msg)
          Handle a new received message
abstract  boolean sendBytes(java.lang.String dest, byte[] data)
          Send bytes through a SAM message-based session.
protected  boolean sendBytesThroughMessageSession(java.lang.String dest, byte[] data)
          Actually send bytes through the SAM message-based session I2PSession (er...).
protected abstract  void shutDown()
          Do whatever is needed to shutdown the SAM session
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAMMessageSession

protected SAMMessageSession(java.lang.String dest,
                            java.util.Properties props)
                     throws java.io.IOException,
                            DataFormatException,
                            I2PSessionException
Initialize a new SAM message-based session.

Parameters:
dest - Base64-encoded destination (private key)
props - Properties to setup the I2P session
Throws:
java.io.IOException
DataFormatException
I2PSessionException

SAMMessageSession

protected SAMMessageSession(java.io.InputStream destStream,
                            java.util.Properties props)
                     throws java.io.IOException,
                            DataFormatException,
                            I2PSessionException
Initialize a new SAM message-based session.

Parameters:
destStream - Input stream containing the destination keys
props - Properties to setup the I2P session
Throws:
java.io.IOException
DataFormatException
I2PSessionException
Method Detail

getDestination

public Destination getDestination()
Get the SAM message-based session Destination.

Returns:
The SAM message-based session Destination.

sendBytes

public abstract boolean sendBytes(java.lang.String dest,
                                  byte[] data)
                           throws DataFormatException
Send bytes through a SAM message-based session.

Parameters:
dest - Destination
data - Bytes to be sent
Returns:
True if the data was sent, false otherwise
Throws:
DataFormatException

sendBytesThroughMessageSession

protected boolean sendBytesThroughMessageSession(java.lang.String dest,
                                                 byte[] data)
                                          throws DataFormatException
Actually send bytes through the SAM message-based session I2PSession (er...).

Parameters:
dest - Destination
data - Bytes to be sent
Returns:
True if the data was sent, false otherwise
Throws:
DataFormatException

close

public void close()
Close a SAM message-based session.


messageReceived

protected abstract void messageReceived(byte[] msg)
Handle a new received message

Parameters:
msg - Message payload

shutDown

protected abstract void shutDown()
Do whatever is needed to shutdown the SAM session


getI2PSession

protected I2PSession getI2PSession()
Get the I2PSession object used by the SAM message-based session.

Returns:
The I2PSession of the SAM message-based session