T
- The parent connector type.public class Connection<T extends Connector> extends Object implements SelectionListener
Constructor and Description |
---|
Connection(ConnectionHelper<T> helper,
SocketChannel socketChannel,
ConnectionController controller,
InetSocketAddress socketAddress,
int inboundBufferSize,
int outboundBufferSize)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the connection so it can be reused.
|
void |
close(boolean graceful)
Closes the connection.
|
void |
commit(Response response)
Asks the server connector to immediately commit the given response
associated to this request, making it ready to be sent back to the
client.
|
protected ReadableSelectionChannel |
createReadableSelectionChannel()
Creates a new readable channel.
|
protected WritableSelectionChannel |
createWritableSelectionChannel()
Creates a new writable channel.
|
String |
getAddress()
Returns the socket IP address.
|
ConnectionHelper<T> |
getHelper()
Returns the parent connector helper.
|
int |
getInboundBufferSize()
Returns the size of the content buffer for receiving messages.
|
InboundWay |
getInboundWay()
Returns the inbound way.
|
long |
getLastActivity()
Returns the timestamp of the last IO activity.
|
int |
getLoadScore()
Returns a score representing the connection load and that could be
compared with other connections of the same parent connector.
|
Logger |
getLogger()
Returns the logger.
|
int |
getMaxIoIdleTimeMs()
Returns the time for an idle IO connection to wait for an operation
before being closed.
|
int |
getOutboundBufferSize()
Returns the size of the content buffer for sending responses.
|
OutboundWay |
getOutboundWay()
Returns the outbound way.
|
int |
getPort()
Returns the socket port.
|
ReadableSelectionChannel |
getReadableSelectionChannel()
Returns the underlying socket channel as a readable selection channel.
|
SelectionRegistration |
getRegistration()
Returns the socket's NIO registration holding the link between the
SocketChannel and the Connection . |
Socket |
getSocket()
Returns the underlying socket.
|
SocketAddress |
getSocketAddress()
Returns the socket address.
|
SocketChannel |
getSocketChannel()
Returns the underlying NIO socket channel.
|
ConnectionState |
getState()
Returns the state of the connection.
|
WritableSelectionChannel |
getWritableSelectionChannel()
Returns the underlying socket channel as a writable selection channel.
|
boolean |
hasTimedOut()
Indicates if the connection has timed out.
|
void |
init(SocketChannel socketChannel,
ConnectionController controller,
InetSocketAddress socketAddress)
Initializes the connection and associates it to the given socket.
|
boolean |
isAvailable()
Indicates if the connection is available to handle new messages.
|
boolean |
isClientSide()
Indicates if it is a client-side connection.
|
boolean |
isEmpty()
Indicates if the connection is empty of messages and bytes.
|
boolean |
isPersistent()
Indicates if the connection should be persisted across calls.
|
boolean |
isPipelining()
Indicates if idempotent sequences of requests can be pipelined.
|
protected boolean |
isReady()
Indicates if at least one way is in the
IoState.READY state. |
boolean |
isServerSide()
Indicates if it is a server-side connection.
|
void |
onActivity()
Notifies the connection that a new activity has been detected and that it
should be kept alive.
|
void |
onError(String message,
Throwable throwable,
Status status)
Called on error.
|
void |
onSelected(SelectionRegistration registration)
Callback method invoked when the connection has been selected for IO
operations it registered interest in.
|
void |
onTimeOut()
Called back by the controller when an IO time out has been detected.
|
void |
open()
Opens the connection.
|
void |
reuse(SocketChannel socketChannel,
ConnectionController controller,
InetSocketAddress socketAddress)
Reuses the connection and associates it to the given socket.
|
void |
setPersistent(boolean persistent)
Indicates if the connection should be persisted across calls.
|
void |
setPipelining(boolean pipelining)
Indicates if idempotent sequences of requests can be pipelined.
|
void |
setRegistration(SelectionRegistration registration)
Sets the socket's NIO registration holding the link between the channel
and the way.
|
void |
setState(ConnectionState state)
Sets the state of the connection.
|
protected void |
shutdown(Socket socket)
Shutdowns the socket, first its input then its output.
|
String |
toString() |
boolean |
updateState()
Updates the connection states.
|
public Connection(ConnectionHelper<T> helper, SocketChannel socketChannel, ConnectionController controller, InetSocketAddress socketAddress, int inboundBufferSize, int outboundBufferSize) throws IOException
helper
- The parent connector helper.socketChannel
- The underlying NIO socket channel.controller
- The IO controller.socketAddress
- The associated IP address.IOException
public void clear()
public void close(boolean graceful)
ConnectionState.CLOSED
.graceful
- Indicates if a graceful close should be attempted.public void commit(Response response)
response
- The response to commit.protected ReadableSelectionChannel createReadableSelectionChannel()
protected WritableSelectionChannel createWritableSelectionChannel()
public String getAddress()
public ConnectionHelper<T> getHelper()
public int getInboundBufferSize()
getInboundBufferSize()
.public InboundWay getInboundWay()
public long getLastActivity()
public int getLoadScore()
public Logger getLogger()
public int getMaxIoIdleTimeMs()
public int getOutboundBufferSize()
getOutboundBufferSize()
.public OutboundWay getOutboundWay()
public int getPort()
public ReadableSelectionChannel getReadableSelectionChannel()
public SelectionRegistration getRegistration()
SocketChannel
and the Connection
.public Socket getSocket()
public SocketAddress getSocketAddress()
public SocketChannel getSocketChannel()
public ConnectionState getState()
public WritableSelectionChannel getWritableSelectionChannel()
public boolean hasTimedOut()
public void init(SocketChannel socketChannel, ConnectionController controller, InetSocketAddress socketAddress) throws IOException
socketChannel
- The underlying NIO socket channel.controller
- The underlying IO controller.socketAddress
- The associated socket address.IOException
public boolean isAvailable()
public boolean isClientSide()
public boolean isEmpty()
public boolean isPersistent()
public boolean isPipelining()
protected boolean isReady()
IoState.READY
state.IoState.READY
state.public boolean isServerSide()
public void onActivity()
public void onError(String message, Throwable throwable, Status status)
close(boolean)
with a
'false' parameter.message
- The error message.throwable
- The cause of the error.status
- The error status.public void onSelected(SelectionRegistration registration) throws IOException
SelectionRegistration.onSelected(int)
on the inbound or outbound
way.onSelected
in interface SelectionListener
registration
- The selected registration.IOException
public void onTimeOut()
public void open()
ConnectionState.OPEN
and the IO state of the inbound way to
IoState.INTEREST
.public void reuse(SocketChannel socketChannel, ConnectionController controller, InetSocketAddress socketAddress) throws IOException
socketChannel
- The underlying NIO socket channel.controller
- The underlying IO controller.socketAddress
- The associated socket address.IOException
public void setPersistent(boolean persistent)
persistent
- True if the connection should be persisted across calls.public void setPipelining(boolean pipelining)
pipelining
- True requests pipelining is enabled.public void setRegistration(SelectionRegistration registration)
registration
- The socket's NIO registration holding the link between the
channel and the way.public void setState(ConnectionState state)
state
- The state of the connection.protected void shutdown(Socket socket) throws IOException
socket
- The socket to shutdown.IOException
public boolean updateState()
Copyright © 2005–2015. All rights reserved.