|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.presents.client.Communicator
com.threerings.presents.client.BlockingCommunicator
public class BlockingCommunicator
The client performs all network I/O on separate threads (one for reading and one for writing). The communicator class encapsulates that functionality.
Logon synopsis:
Client.logon():
- Calls Communicator.start()
Communicator.start():
- spawn Reader thread
Reader.run():
{ - connect
- authenticate
} if either fail, notify observers of failed logon
- start writer thread
- notify observers that we're logged on
- read loop
Writer.run():
- write loop
| Nested Class Summary | |
|---|---|
protected class |
BlockingCommunicator.DatagramReader
Handles the general flow of reading datagrams. |
protected class |
BlockingCommunicator.DatagramWriter
Handles the general flow of writing datagrams. |
protected class |
BlockingCommunicator.Reader
The reader encapsulates the authentication and message reading process. |
protected static class |
BlockingCommunicator.TerminationMessage
This is used to terminate the writer threads. |
protected class |
BlockingCommunicator.Writer
The writer encapsulates the message writing process. |
| Field Summary | |
|---|---|
protected ByteBufferOutputStream |
_bout
We use these to write our upstream datagrams. |
protected ByteBuffer |
_buf
We use these to read our downstream datagrams. |
protected SocketChannel |
_channel
|
protected DatagramChannel |
_datagramChannel
|
protected BlockingCommunicator.DatagramReader |
_datagramReader
|
protected BlockingCommunicator.DatagramWriter |
_datagramWriter
|
protected Queue<UpstreamMessage> |
_dataq
|
protected MessageDigest |
_digest
|
protected FramedInputStream |
_fin
We use this to frame our downstream messages. |
protected FramingOutputStream |
_fout
We use this to frame our upstream messages. |
protected ClassLoader |
_loader
|
protected Exception |
_logonError
|
protected Queue<UpstreamMessage> |
_msgq
|
protected ObjectInputStream |
_oin
|
protected ObjectOutputStream |
_oout
|
protected BlockingCommunicator.Reader |
_reader
|
protected byte[] |
_secret
|
protected Selector |
_selector
|
protected DatagramSequencer |
_sequencer
|
protected UnreliableObjectOutputStream |
_uout
|
protected BlockingCommunicator.Writer |
_writer
|
protected static int |
DATAGRAM_ATTEMPTS_PER_PORT
The number of times per port to try to establish a datagram "connection". |
protected static long |
DATAGRAM_RESPONSE_WAIT
The number of milliseconds to wait for a response datagram. |
| Fields inherited from class com.threerings.presents.client.Communicator |
|---|
_client, _lastWrite, _omgr |
| Constructor Summary | |
|---|---|
BlockingCommunicator(Client client)
Creates a new communicator instance which is associated with the supplied client. |
|
| Method Summary | |
|---|---|
protected void |
closeChannel()
Closes the socket channel that we have open to the server. |
protected void |
closeDatagramChannel()
Closes the datagram channel. |
protected void |
connectionClosed()
Callback called by the reader if the server closes the other end of the connection. |
protected void |
connectionFailed(IOException ioe)
Callback called by the reader or writer thread when something goes awry with our socket connection to the server. |
protected void |
datagramReaderDidExit()
Callback called by the datagram reader thread when it goes away. |
protected void |
datagramWriterDidExit()
Callback called by the datagram writer thread when it goes away. |
protected boolean |
debugLogMessages()
|
long |
getLastWrite()
Returns the time at which we last sent a packet to the server. |
boolean |
getTransmitDatagrams()
Checks whether we should transmit datagrams. |
void |
gotBootstrap()
Notifies the communicator that the client has received its bootstrap data. |
void |
logoff()
Delivers a logoff notification to the server and shuts down the network connection. |
void |
logon()
Logs on to the server and initiates our full-duplex message exchange. |
protected void |
logonSucceeded(AuthResponseData data)
Called when the authentication process completes successfully. |
protected void |
openChannel(InetAddress host)
|
void |
postMessage(UpstreamMessage msg)
Queues up the specified message for delivery upstream. |
protected int |
readDatagram(ByteBuffer buf)
Reads a datagram into the supplied buffer. |
protected void |
readerDidExit()
Callback called by the reader thread when it goes away. |
protected boolean |
readFrame()
Reads a frame from the socket. |
protected DownstreamMessage |
receiveDatagram()
Reads a datagram from the socket (blocking until a datagram has arrived). |
protected DownstreamMessage |
receiveMessage()
Reads a new message from the socket (blocking until a message has arrived). |
protected void |
sendDatagram(UpstreamMessage msg)
Sends a datagram over the datagram socket. |
protected void |
sendMessage(UpstreamMessage msg)
Writes the supplied message to the socket. |
void |
setClassLoader(ClassLoader loader)
Configures this communicator with a custom class loader to be used when reading and writing objects over the network. |
protected void |
throttleOutgoingMessage()
Throttles an outgoing message operation in a thread-safe manner. |
protected int |
writeDatagram(ByteBuffer buf)
Writes the datagram contained in the supplied buffer. |
protected int |
writeMessage(ByteBuffer buf)
Writes the message contained in the supplied buffer. |
protected void |
writerDidExit()
Callback called by the writer thread when it goes away. |
| Methods inherited from class com.threerings.presents.client.Communicator |
|---|
clientCleanup, gotAuthResponse, notifyClientObservers, processMessage, updateWriteStamp |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected BlockingCommunicator.Reader _reader
protected BlockingCommunicator.Writer _writer
protected BlockingCommunicator.DatagramReader _datagramReader
protected BlockingCommunicator.DatagramWriter _datagramWriter
protected SocketChannel _channel
protected Queue<UpstreamMessage> _msgq
protected Selector _selector
protected DatagramChannel _datagramChannel
protected Queue<UpstreamMessage> _dataq
protected Exception _logonError
protected FramingOutputStream _fout
protected ObjectOutputStream _oout
protected FramedInputStream _fin
protected ObjectInputStream _oin
protected ByteBufferOutputStream _bout
protected UnreliableObjectOutputStream _uout
protected MessageDigest _digest
protected byte[] _secret
protected ByteBuffer _buf
protected DatagramSequencer _sequencer
protected ClassLoader _loader
protected static final int DATAGRAM_ATTEMPTS_PER_PORT
protected static final long DATAGRAM_RESPONSE_WAIT
| Constructor Detail |
|---|
public BlockingCommunicator(Client client)
| Method Detail |
|---|
public void logon()
Communicator
logon in class Communicatorpublic void logoff()
Communicator
logoff in class Communicatorpublic void gotBootstrap()
Communicator
gotBootstrap in class Communicatorpublic void postMessage(UpstreamMessage msg)
Communicator
postMessage in class Communicatorpublic void setClassLoader(ClassLoader loader)
Communicator
setClassLoader in class Communicatorpublic long getLastWrite()
Communicator
getLastWrite in class Communicatorpublic boolean getTransmitDatagrams()
Communicator
getTransmitDatagrams in class Communicatorprotected void logonSucceeded(AuthResponseData data)
Communicator
logonSucceeded in class Communicatorprotected void connectionFailed(IOException ioe)
protected void connectionClosed()
protected void readerDidExit()
protected void writerDidExit()
protected void closeChannel()
readerDidExit() or writerDidExit() whichever is called last.
protected void datagramReaderDidExit()
protected void datagramWriterDidExit()
protected void closeDatagramChannel()
protected void sendMessage(UpstreamMessage msg)
throws IOException
IOException
protected int writeMessage(ByteBuffer buf)
throws IOException
IOException
protected void sendDatagram(UpstreamMessage msg)
throws IOException
IOException
protected int writeDatagram(ByteBuffer buf)
throws IOException
IOException
protected DownstreamMessage receiveMessage()
throws IOException
IOException
protected boolean readFrame()
throws IOException
IOException
protected DownstreamMessage receiveDatagram()
throws IOException
IOException
protected int readDatagram(ByteBuffer buf)
throws IOException
IOException
protected void openChannel(InetAddress host)
throws IOException
IOExceptionprotected boolean debugLogMessages()
protected void throttleOutgoingMessage()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||