com.google.bitcoin.net
Interface StreamParser

All Known Implementing Classes:
Peer, PeerSocketHandler, ProtobufParser

public interface StreamParser

A generic handler which is used in NioServer, NioClient and BlockingClient to handle incoming data streams.


Method Summary
 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).
 

Method Detail

connectionClosed

void connectionClosed()
Called when the connection socket is closed


connectionOpened

void connectionOpened()
Called when the connection socket is first opened


receiveBytes

int receiveBytes(ByteBuffer buff)
                 throws Exception

Called 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:

Returns:
The amount of bytes consumed which should not be provided again
Throws:
Exception

setWriteTarget

void setWriteTarget(MessageWriteTarget writeTarget)
Called when this parser is attached to an upstream write target (ie a low-level connection handler). This writeTarget should be stored and used to close the connection or write data to the socket.


getMaxMessageSize

int getMaxMessageSize()
Returns the maximum message size of a message on the socket. This is used in calculating size of buffers to allocate.



Copyright © 2014. All rights reserved.