public abstract class AConnection extends Object
ConnectionFactory and attached to SelectionKey key.
Selection key is registered to one of Dispatchers Selector to
handle io read and write.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
closed
True if this connection is already closed.
|
protected Object |
guard
Object on witch some methods are synchronized
|
protected boolean |
isForcedClosing
True if OnDisconnect() method should be called immediately after this
connection was closed.
|
protected boolean |
pendingClose
True if this connection should be closed after sending last server
packet.
|
ByteBuffer |
readBuffer
ByteBuffer for io read.
|
ByteBuffer |
writeBuffer
ByteBuffer for io write.
|
| Constructor and Description |
|---|
AConnection(SocketChannel sc,
Dispatcher d)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
close(boolean forced)
Connection will be closed at some time [by Dispatcher Thread], after that
onDisconnect() method will be called to clear all other things.
|
protected void |
enableWriteInterest()
Notify Dispatcher Selector that we want write some data here.
|
protected abstract long |
getDisconnectionDelay()
This method is called by Dispatcher when connection is ready to be
closed.
|
String |
getIP() |
SocketChannel |
getSocketChannel() |
protected boolean |
isWriteDisabled() |
protected abstract void |
onDisconnect()
This method is called by Dispatcher to inform that this connection was
closed and should be cleared.
|
protected abstract void |
onServerClose()
This method is called by NioServer to inform that NioServer is shouting
down.
|
protected abstract boolean |
processData(ByteBuffer data) |
protected abstract boolean |
writeData(ByteBuffer data)
This method will be called by Dispatcher, and will be repeated till
return false.
|
protected boolean pendingClose
protected boolean isForcedClosing
protected boolean closed
protected final Object guard
public final ByteBuffer writeBuffer
public final ByteBuffer readBuffer
public AConnection(SocketChannel sc, Dispatcher d) throws IOException
sc - d - IOExceptionprotected final void enableWriteInterest()
public SocketChannel getSocketChannel()
public void close(boolean forced)
forced - is just hint that getDisconnectionDelay() should return 0 so
OnDisconnect() method will be called without any delay.protected final boolean isWriteDisabled()
public final String getIP()
protected abstract boolean processData(ByteBuffer data)
data - protected abstract boolean writeData(ByteBuffer data)
data - protected abstract long getDisconnectionDelay()
protected abstract void onDisconnect()
protected abstract void onServerClose()
Copyright © 2014–2015. All rights reserved.