|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.bitcoin.net.AbstractTimeoutHandler
com.google.bitcoin.net.ProtobufParser<MessageType>
public class ProtobufParser<MessageType extends com.google.protobuf.MessageLite>
A handler which is used in NioServer and NioClient to split up incoming data streams
into protobufs and provide an interface for writing protobufs to the connections.
Messages are encoded with a 4-byte signed integer (big endian) prefix to indicate their length followed by the serialized protobuf
| Nested Class Summary | |
|---|---|
static interface |
ProtobufParser.Listener<MessageType extends com.google.protobuf.MessageLite>
An interface which can be implemented to handle callbacks as new messages are generated and socket events occur. |
| Constructor Summary | |
|---|---|
ProtobufParser(ProtobufParser.Listener<MessageType> handler,
MessageType prototype,
int maxMessageSize,
int timeoutMillis)
Creates a new protobuf handler. |
|
| Method Summary | |
|---|---|
void |
closeConnection()
Closes this connection, eventually triggering a connectionClosed() event. |
void |
connectionClosed()
Called when the connection socket is closed |
void |
connectionOpened()
Called when the connection socket is first opened |
int |
getMaxMessageSize()
Returns the maximum message size of a message on the socket. |
int |
receiveBytes(ByteBuffer buff)
Called when new bytes are available from the remote end. |
void |
setWriteTarget(MessageWriteTarget writeTarget)
Called when this parser is attached to an upstream write target (ie a low-level connection handler). |
protected void |
timeoutOccurred()
|
void |
write(MessageType msg)
Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix. |
| Methods inherited from class com.google.bitcoin.net.AbstractTimeoutHandler |
|---|
resetTimeout, setSocketTimeout, setTimeoutEnabled |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ProtobufParser(ProtobufParser.Listener<MessageType> handler,
MessageType prototype,
int maxMessageSize,
int timeoutMillis)
handler - The callback listenerprototype - The default instance of the message type used in both directions of this channel.
This should be the return value from MessageType#getDefaultInstanceForType()maxMessageSize - The maximum message size (not including the 4-byte length prefix).
Note that this has an upper bound of Integer.MAX_VALUE - 4timeoutMillis - The timeout between messages before the connection is automatically closed. Only enabled
after the connection is established.| Method Detail |
|---|
public void setWriteTarget(MessageWriteTarget writeTarget)
StreamParser
setWriteTarget in interface StreamParserpublic int getMaxMessageSize()
StreamParser
getMaxMessageSize in interface StreamParserpublic void closeConnection()
connectionClosed() event.
protected void timeoutOccurred()
timeoutOccurred in class AbstractTimeoutHandler
public int receiveBytes(ByteBuffer buff)
throws Exception
StreamParserCalled when new bytes are available from the remote end. This should only ever be called by the single writeTarget associated with any given StreamParser, multiple callers will likely confuse implementations.
Implementers/callers must follow the following conventions exactly:
receiveBytes in interface StreamParserExceptionpublic void connectionClosed()
StreamParser
connectionClosed in interface StreamParserpublic void connectionOpened()
StreamParser
connectionOpened in interface StreamParser
public void write(MessageType msg)
throws IllegalStateException
Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.
Provides a write-order guarantee.
IllegalStateException - If the encoded message is larger than the maximum message size.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||