public class FS4Connection extends Object implements com.yahoo.io.Connection
Modifier and Type | Field and Description |
---|---|
private Backend |
backend |
private SocketChannel |
channel |
private ByteBuffer |
fixedReadBuffer |
private static int |
idCounter |
private int |
idNumber |
private com.yahoo.io.Listener |
listener |
private static Logger |
log |
private int |
maxInitialSize |
private PacketListener |
packetListener |
private ByteBuffer |
readBuffer |
private boolean |
shouldWrite |
private boolean |
valid |
private ByteBuffer |
writeBuffer |
private LinkedList<ByteBuffer> |
writeBufferList |
Constructor and Description |
---|
FS4Connection(SocketChannel channel,
com.yahoo.io.Listener listener,
Backend backend,
PacketListener packetListener)
Create an FS4 Connection.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
This is called when we close the connection to do any
pending cleanup work.
|
void |
connect()
Upon asynchronous connect completion this method is called by
the Listener.
|
private void |
disableWrite() |
private void |
enableWrite() |
private void |
extendReadBuffer(int size)
Extend the readBuffer.
|
private void |
extractPackets(ByteBuffer readBuffer) |
boolean |
isValid()
This method is used to determine whether the connection is still
viable or not.
|
void |
read() |
private void |
resetReadBuffer()
Clear the readBuffer, and if temporarily allocated bigger
buffer is in use: ditch it and reset the reference to the
fixed readBuffer.
|
int |
selectOps()
Since we are performing an asynchronous connect we are initially
only interested in the
OP_CONNECT event. |
void |
sendPacket(BasicPacket packet,
Integer channelId)
Packet sending interface.
|
SocketChannel |
socketChannel()
Return the underlying SocketChannel used by this connection.
|
String |
toString() |
void |
write()
The write event handler.
|
private static Logger log
private Backend backend
private com.yahoo.io.Listener listener
private SocketChannel channel
private boolean shouldWrite
private static int idCounter
private int idNumber
private int maxInitialSize
private ByteBuffer writeBuffer
private LinkedList<ByteBuffer> writeBufferList
private ByteBuffer fixedReadBuffer
private ByteBuffer readBuffer
private volatile boolean valid
private final PacketListener packetListener
public FS4Connection(SocketChannel channel, com.yahoo.io.Listener listener, Backend backend, PacketListener packetListener)
public void sendPacket(BasicPacket packet, Integer channelId) throws IOException
IOException
public void write() throws IOException
write
in interface com.yahoo.io.Connection
IOException
private void disableWrite()
private void enableWrite()
public void read() throws IOException
read
in interface com.yahoo.io.Connection
IOException
private void extractPackets(ByteBuffer readBuffer)
public void close() throws IOException
close
in interface com.yahoo.io.Connection
IOException
public void connect() throws IOException
connect
in interface com.yahoo.io.Connection
IOException
public int selectOps()
OP_CONNECT
event.selectOps
in interface com.yahoo.io.Connection
public SocketChannel socketChannel()
socketChannel
in interface com.yahoo.io.Connection
private void extendReadBuffer(int size)
The readBuffer needs to be in "readable" (flipped) state before this is called and it will be in the "writeable" state when it returns.
private void resetReadBuffer()
public boolean isValid()
Copyright © 2018. All rights reserved.