public class ConnectionImpl extends Object implements Connection, ManagedConnection, WriteDataAction
Connection
.Constructor and Description |
---|
ConnectionImpl(SelectionKey selectionKey,
SocketChannel socketChannel,
CommunicationProtocol communicationProtocol,
SocketListener socketListener)
Initiate.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Flags to close the
WriteBufferReceiver . |
WriteBuffer |
createWriteBuffer(byte[] data,
int length)
Creates a
WriteBuffer for the data. |
WriteBuffer |
createWriteBuffer(ByteBuffer buffer)
Creates the
WriteBuffer for the ByteBuffer . |
ManagedConnection |
getConnection()
Obtains the
ManagedConnection for the WriteDataAction . |
ConnectionHandler |
getConnectionHandler()
Obtains the
ConnectionHandler . |
InetSocketAddress |
getLocalAddress()
Obtains the local address for the
Connection . |
Object |
getLock()
Obtains the lock to
synchronize for using this
WriteBufferReceiver . |
InetSocketAddress |
getRemoteAddress()
Obtains the remote address for the
Connection . |
SelectionKey |
getSelectionKey()
Obtains the
SelectionKey for the Connection . |
SocketChannel |
getSocketChannel()
Obtains the
SocketChannel for the Connection . |
boolean |
isClosed()
Indicates if the
WriteBufferReceiver is closed. |
boolean |
isSecure()
Indicates if the connection is over a secure channel (e.g.
|
boolean |
processWriteQueue()
Undertakes the queued writes and possible
Connection close. |
void |
terminate()
Terminates this
Connection immediately. |
void |
writeData(WriteBuffer[] data)
Writes data to client of this
Connection . |
public ConnectionImpl(SelectionKey selectionKey, SocketChannel socketChannel, CommunicationProtocol communicationProtocol, SocketListener socketListener)
selectionKey
- SelectionKey
for this Connection
.socketChannel
- SocketChannel
for this Connection
.communicationProtocol
- CommunicationProtocol
.socketListener
- SocketListener
.public Object getLock()
WriteBufferReceiver
synchronize
for using this
WriteBufferReceiver
.getLock
in interface WriteBufferReceiver
WriteBufferReceiver
.public boolean isSecure()
Connection
isSecure
in interface Connection
true
if connection is over a secure channel.public WriteBuffer createWriteBuffer(byte[] data, int length)
WriteBufferReceiver
WriteBuffer
for the data.createWriteBuffer
in interface WriteBufferReceiver
data
- Data.length
- Length of data.WriteBuffer
.public WriteBuffer createWriteBuffer(ByteBuffer buffer)
WriteBufferReceiver
WriteBuffer
for the ByteBuffer
.createWriteBuffer
in interface WriteBufferReceiver
buffer
- ByteBuffer
.WriteBuffer
.public void writeData(WriteBuffer[] data) throws IOException
WriteBufferReceiver
Connection
.writeData
in interface WriteBufferReceiver
data
- Data to be written.IOException
- If fails to write data.public InetSocketAddress getLocalAddress()
Connection
Connection
.getLocalAddress
in interface Connection
InetSocketAddress
describing the local Socket
for
the Connection
.public InetSocketAddress getRemoteAddress()
Connection
Connection
.getRemoteAddress
in interface Connection
InetSocketAddress
describing the remote Socket
for the Connection
.public void close() throws IOException
WriteBufferReceiver
Flags to close the WriteBufferReceiver
.
Close occurs after all data has been written.
close
in interface WriteBufferReceiver
IOException
- If fails to close.public boolean isClosed()
WriteBufferReceiver
WriteBufferReceiver
is closed.isClosed
in interface WriteBufferReceiver
true
if the WriteBufferReceiver
is closed.public SelectionKey getSelectionKey()
ManagedConnection
SelectionKey
for the Connection
.getSelectionKey
in interface ManagedConnection
SelectionKey
for the Connection
.public SocketChannel getSocketChannel()
ManagedConnection
SocketChannel
for the Connection
.getSocketChannel
in interface ManagedConnection
SocketChannel
for the Connection
.public ConnectionHandler getConnectionHandler()
ManagedConnection
ConnectionHandler
.getConnectionHandler
in interface ManagedConnection
ConnectionHandler
.public boolean processWriteQueue() throws IOException
ManagedConnection
Connection
close.processWriteQueue
in interface ManagedConnection
true
if all data written. false
indicating not able to write all data, requiring waiting for
client to consume data (clear space in socket buffer).IOException
- If fails to process the queued writes.public void terminate() throws IOException
ManagedConnection
Connection
immediately.terminate
in interface ManagedConnection
IOException
- If fails to terminate the Connection
.public ManagedConnection getConnection()
WriteDataAction
ManagedConnection
for the WriteDataAction
.getConnection
in interface WriteDataAction
ManagedConnection
for the WriteDataAction
.Copyright © 2005–2016. All rights reserved.