abstract class SAMHandler extends Object implements Runnable
Modifier and Type | Field and Description |
---|---|
protected Log |
_log |
protected SAMBridge |
bridge |
protected Properties |
i2cpProps
I2CP options configuring the I2CP connection (port, host, numHops, etc)
|
protected SocketChannel |
socket |
protected I2PAppThread |
thread |
protected int |
verMajor |
protected int |
verMinor |
Modifier | Constructor and Description |
---|---|
protected |
SAMHandler(SocketChannel s,
int verMajor,
int verMinor,
Properties i2cpProps)
SAMHandler constructor (to be called by subclasses)
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeClientSocket()
Close the socket connected to the SAM client.
|
protected SocketChannel |
getClientSocket()
Get the input stream of the socket connected to the SAM client
|
protected Object |
getWriteLock()
If you're crazy enough to write to the raw socket, grab the write lock
with getWriteLock(), synchronize against it, and write to the getOut()
|
protected abstract void |
handle()
Actually handle the SAM protocol.
|
void |
run() |
void |
setBridge(SAMBridge bridge) |
protected boolean |
shouldStop()
Should the handler be stopped?
|
void |
startHandling()
Start handling the SAM connection, detaching an handling thread.
|
void |
stopHandling()
Stop the SAM handler
|
String |
toString()
Get a string describing the handler.
|
protected void |
writeBytes(ByteBuffer data)
Write a byte array on the handler's socket.
|
static void |
writeBytes(ByteBuffer data,
SocketChannel out) |
protected boolean |
writeString(String str)
Write a string to the handler's socket.
|
static boolean |
writeString(String str,
SocketChannel out) |
protected final Log _log
protected I2PAppThread thread
protected SAMBridge bridge
protected final SocketChannel socket
protected final int verMajor
protected final int verMinor
protected final Properties i2cpProps
protected SAMHandler(SocketChannel s, int verMajor, int verMinor, Properties i2cpProps) throws IOException
s
- Socket attached to a SAM clientverMajor
- SAM major version to manageverMinor
- SAM minor version to managei2cpProps
- properties to configure the I2CP connection (host, port, etc)IOException
public final void startHandling()
public void setBridge(SAMBridge bridge)
protected abstract void handle()
protected final SocketChannel getClientSocket()
IOException
protected final void writeBytes(ByteBuffer data) throws IOException
data
- A byte array to be writtenIOException
public static void writeBytes(ByteBuffer data, SocketChannel out) throws IOException
IOException
protected Object getWriteLock()
protected final boolean writeString(String str)
str
- A byte array to be writtenpublic static boolean writeString(String str, SocketChannel out)
protected final void closeClientSocket() throws IOException
IOException
public final void stopHandling()
protected final boolean shouldStop()
public final String toString()