Class Connection<T extends Connector>
- java.lang.Object
-
- org.restlet.ext.nio.internal.connection.Connection<T>
-
- Type Parameters:
T- The parent connector type.
- All Implemented Interfaces:
SelectionListener
- Direct Known Subclasses:
SslConnection
@Deprecated public class Connection<T extends Connector> extends java.lang.Object implements SelectionListener
Deprecated.Will be removed to favor lower-level network extensions allowing more control at the Restlet API level.A network connection though which messages are exchanged by connectors. Messages can be either requests or responses.
-
-
Field Summary
Fields Modifier and Type Field Description private ConnectionHelper<T>helperDeprecated.The parent connector helper.private InboundWayinboundWayDeprecated.The inbound way.private longlastActivityDeprecated.The timestamp of the last IO activity.private intmaxIoIdleTimeMsDeprecated.The time for an idle IO connection to wait for an operation before being closed.private OutboundWayoutboundWayDeprecated.The outbound way.private booleanpersistentDeprecated.Indicates if the connection should be persisted across calls.private booleanpipeliningDeprecated.Indicates if idempotent sequences of requests can be pipelined.private ReadableSelectionChannelreadableSelectionChannelDeprecated.The readable selection channel.private SelectionRegistrationregistrationDeprecated.The socket's NIO selection registration holding the link between the channel and the connection.private java.net.SocketAddresssocketAddressDeprecated.The socket address.private java.nio.channels.SocketChannelsocketChannelDeprecated.The underlying socket channel.private ConnectionStatestateDeprecated.The state of the connection.private WritableSelectionChannelwritableSelectionChannelDeprecated.The writable selection channel.
-
Constructor Summary
Constructors Constructor Description Connection(ConnectionHelper<T> helper, java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress, int inboundBufferSize, int outboundBufferSize)Deprecated.Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Deprecated.Clears the connection so it can be reused.voidclose(boolean graceful)Deprecated.Closes the connection.voidcommit(Response response)Deprecated.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 ReadableSelectionChannelcreateReadableSelectionChannel()Deprecated.Creates a new readable channel.protected WritableSelectionChannelcreateWritableSelectionChannel()Deprecated.Creates a new writable channel.java.lang.StringgetAddress()Deprecated.Returns the socket IP address.ConnectionHelper<T>getHelper()Deprecated.Returns the parent connector helper.intgetInboundBufferSize()Deprecated.Returns the size of the content buffer for receiving messages.InboundWaygetInboundWay()Deprecated.Returns the inbound way.longgetLastActivity()Deprecated.Returns the timestamp of the last IO activity.intgetLoadScore()Deprecated.Returns a score representing the connection load and that could be compared with other connections of the same parent connector.java.util.logging.LoggergetLogger()Deprecated.Returns the logger.intgetMaxIoIdleTimeMs()Deprecated.Returns the time for an idle IO connection to wait for an operation before being closed.intgetOutboundBufferSize()Deprecated.Returns the size of the content buffer for sending responses.OutboundWaygetOutboundWay()Deprecated.Returns the outbound way.intgetPort()Deprecated.Returns the socket port.ReadableSelectionChannelgetReadableSelectionChannel()Deprecated.Returns the underlying socket channel as a readable selection channel.SelectionRegistrationgetRegistration()Deprecated.Returns the socket's NIO registration holding the link between theSocketChanneland theConnection.java.net.SocketgetSocket()Deprecated.Returns the underlying socket.java.net.SocketAddressgetSocketAddress()Deprecated.Returns the socket address.java.nio.channels.SocketChannelgetSocketChannel()Deprecated.Returns the underlying NIO socket channel.ConnectionStategetState()Deprecated.Returns the state of the connection.WritableSelectionChannelgetWritableSelectionChannel()Deprecated.Returns the underlying socket channel as a writable selection channel.booleanhasTimedOut()Deprecated.Indicates if the connection has timed out.voidinit(java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress)Deprecated.Initializes the connection and associates it to the given socket.booleanisAvailable()Deprecated.Indicates if the connection is available to handle new messages.booleanisClientSide()Deprecated.Indicates if it is a client-side connection.booleanisEmpty()Deprecated.Indicates if the connection is empty of messages and bytes.booleanisPersistent()Deprecated.Indicates if the connection should be persisted across calls.booleanisPipelining()Deprecated.Indicates if idempotent sequences of requests can be pipelined.booleanisReady()Deprecated.Indicates if at least one way is in theIoState.READYstate.booleanisServerSide()Deprecated.Indicates if it is a server-side connection.voidonActivity()Deprecated.Notifies the connection that a new activity has been detected and that it should be kept alive.voidonError(java.lang.String message, java.lang.Throwable throwable, Status status)Deprecated.Called on error.voidonSelected(SelectionRegistration registration)Deprecated.Callback method invoked when the connection has been selected for IO operations it registered interest in.voidonTimeOut()Deprecated.Called back by the controller when an IO time out has been detected.voidopen()Deprecated.Opens the connection.voidreuse(java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress)Deprecated.Reuses the connection and associates it to the given socket.voidsetPersistent(boolean persistent)Deprecated.Indicates if the connection should be persisted across calls.voidsetPipelining(boolean pipelining)Deprecated.Indicates if idempotent sequences of requests can be pipelined.voidsetRegistration(SelectionRegistration registration)Deprecated.Sets the socket's NIO registration holding the link between the channel and the way.voidsetState(ConnectionState state)Deprecated.Sets the state of the connection.protected voidshutdown(java.net.Socket socket)Deprecated.Shutdowns the socket, first its input then its output.java.lang.StringtoString()Deprecated.booleanupdateState()Deprecated.Updates the connection states.
-
-
-
Field Detail
-
helper
private final ConnectionHelper<T extends Connector> helper
Deprecated.The parent connector helper.
-
inboundWay
private final InboundWay inboundWay
Deprecated.The inbound way.
-
lastActivity
private volatile long lastActivity
Deprecated.The timestamp of the last IO activity.
-
maxIoIdleTimeMs
private volatile int maxIoIdleTimeMs
Deprecated.The time for an idle IO connection to wait for an operation before being closed.
-
outboundWay
private final OutboundWay outboundWay
Deprecated.The outbound way.
-
persistent
private volatile boolean persistent
Deprecated.Indicates if the connection should be persisted across calls.
-
pipelining
private volatile boolean pipelining
Deprecated.Indicates if idempotent sequences of requests can be pipelined.
-
readableSelectionChannel
private volatile ReadableSelectionChannel readableSelectionChannel
Deprecated.The readable selection channel.
-
registration
private volatile SelectionRegistration registration
Deprecated.The socket's NIO selection registration holding the link between the channel and the connection.
-
socketAddress
private volatile java.net.SocketAddress socketAddress
Deprecated.The socket address.
-
socketChannel
private volatile java.nio.channels.SocketChannel socketChannel
Deprecated.The underlying socket channel.
-
state
private volatile ConnectionState state
Deprecated.The state of the connection.
-
writableSelectionChannel
private volatile WritableSelectionChannel writableSelectionChannel
Deprecated.The writable selection channel.
-
-
Constructor Detail
-
Connection
public Connection(ConnectionHelper<T> helper, java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress, int inboundBufferSize, int outboundBufferSize) throws java.io.IOException
Deprecated.Constructor.- Parameters:
helper- The parent connector helper.socketChannel- The underlying NIO socket channel.controller- The IO controller.socketAddress- The associated IP address.- Throws:
java.io.IOException
-
-
Method Detail
-
clear
public void clear()
Deprecated.Clears the connection so it can be reused. Typically invoked by a connection pool.
-
close
public void close(boolean graceful)
Deprecated.Closes the connection. By default, set the state toConnectionState.CLOSED.- Parameters:
graceful- Indicates if a graceful close should be attempted.
-
commit
public void commit(Response response)
Deprecated.Asks the server connector to immediately commit the given response associated to this request, making it ready to be sent back to the client. Note that all server connectors don't necessarily support this feature.- Parameters:
response- The response to commit.
-
createReadableSelectionChannel
protected ReadableSelectionChannel createReadableSelectionChannel()
Deprecated.Creates a new readable channel.- Returns:
- A new readable channel.
-
createWritableSelectionChannel
protected WritableSelectionChannel createWritableSelectionChannel()
Deprecated.Creates a new writable channel.- Returns:
- A new writable channel.
-
getAddress
public java.lang.String getAddress()
Deprecated.Returns the socket IP address.- Returns:
- The socket IP address.
-
getHelper
public ConnectionHelper<T> getHelper()
Deprecated.Returns the parent connector helper.- Returns:
- The parent connector helper.
-
getInboundBufferSize
public int getInboundBufferSize()
Deprecated.Returns the size of the content buffer for receiving messages. By default, it callsgetInboundBufferSize().- Returns:
- The size of the content buffer for receiving messages.
-
getInboundWay
public InboundWay getInboundWay()
Deprecated.Returns the inbound way.- Returns:
- The inbound way.
-
getLastActivity
public long getLastActivity()
Deprecated.Returns the timestamp of the last IO activity.- Returns:
- The timestamp of the last IO activity.
-
getLoadScore
public int getLoadScore()
Deprecated.Returns a score representing the connection load and that could be compared with other connections of the same parent connector.- Returns:
- A score representing the connection load.
-
getLogger
public java.util.logging.Logger getLogger()
Deprecated.Returns the logger.- Returns:
- The logger.
-
getMaxIoIdleTimeMs
public int getMaxIoIdleTimeMs()
Deprecated.Returns the time for an idle IO connection to wait for an operation before being closed.- Returns:
- The time for an idle IO connection to wait for an operation before being closed.
-
getOutboundBufferSize
public int getOutboundBufferSize()
Deprecated.Returns the size of the content buffer for sending responses. By default, it callsgetOutboundBufferSize().- Returns:
- The size of the content buffer for sending responses.
-
getOutboundWay
public OutboundWay getOutboundWay()
Deprecated.Returns the outbound way.- Returns:
- The outbound way.
-
getPort
public int getPort()
Deprecated.Returns the socket port.- Returns:
- The socket port.
-
getReadableSelectionChannel
public ReadableSelectionChannel getReadableSelectionChannel()
Deprecated.Returns the underlying socket channel as a readable selection channel.- Returns:
- The underlying socket channel as a readable selection channel.
-
getRegistration
public SelectionRegistration getRegistration()
Deprecated.Returns the socket's NIO registration holding the link between theSocketChanneland theConnection.- Returns:
- The socket's NIO registration holding the link between the channel and the connection.
-
getSocket
public java.net.Socket getSocket()
Deprecated.Returns the underlying socket.- Returns:
- The underlying socket.
-
getSocketAddress
public java.net.SocketAddress getSocketAddress()
Deprecated.Returns the socket address.- Returns:
- The socket address.
-
getSocketChannel
public java.nio.channels.SocketChannel getSocketChannel()
Deprecated.Returns the underlying NIO socket channel.- Returns:
- The underlying NIO socket channel.
-
getState
public ConnectionState getState()
Deprecated.Returns the state of the connection.- Returns:
- The state of the connection.
-
getWritableSelectionChannel
public WritableSelectionChannel getWritableSelectionChannel()
Deprecated.Returns the underlying socket channel as a writable selection channel.- Returns:
- The underlying socket channel as a writable selection channel.
-
hasTimedOut
public boolean hasTimedOut()
Deprecated.Indicates if the connection has timed out.- Returns:
- True if the connection has timed out.
-
init
public void init(java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress) throws java.io.IOExceptionDeprecated.Initializes the connection and associates it to the given socket.- Parameters:
socketChannel- The underlying NIO socket channel.controller- The underlying IO controller.socketAddress- The associated socket address.- Throws:
java.io.IOException
-
isAvailable
public boolean isAvailable()
Deprecated.Indicates if the connection is available to handle new messages.- Returns:
- True if the connection is available to handle new messages.
-
isClientSide
public boolean isClientSide()
Deprecated.Indicates if it is a client-side connection.- Returns:
- True if it is a client-side connection.
-
isEmpty
public boolean isEmpty()
Deprecated.Indicates if the connection is empty of messages and bytes.- Returns:
- True if the connection is empty.
-
isPersistent
public boolean isPersistent()
Deprecated.Indicates if the connection should be persisted across calls.- Returns:
- True if the connection should be persisted across calls.
-
isPipelining
public boolean isPipelining()
Deprecated.Indicates if idempotent sequences of requests can be pipelined.- Returns:
- True requests pipelining is enabled.
-
isReady
public boolean isReady()
Deprecated.Indicates if at least one way is in theIoState.READYstate.- Returns:
- True if at least one way is in the
IoState.READYstate.
-
isServerSide
public boolean isServerSide()
Deprecated.Indicates if it is a server-side connection.- Returns:
- True if it is a server-side connection.
-
onActivity
public void onActivity()
Deprecated.Notifies the connection that a new activity has been detected and that it should be kept alive.
-
onError
public void onError(java.lang.String message, java.lang.Throwable throwable, Status status)Deprecated.Called on error. By default, it callsclose(boolean)with a 'false' parameter.- Parameters:
message- The error message.throwable- The cause of the error.status- The error status.
-
onSelected
public void onSelected(SelectionRegistration registration) throws java.io.IOException
Deprecated.Callback method invoked when the connection has been selected for IO operations it registered interest in. By default it updates the timestamp that allows the detection of expired connections and callsSelectionRegistration.onSelected(int)on the inbound or outbound way.- Specified by:
onSelectedin interfaceSelectionListener- Parameters:
registration- The selected registration.- Throws:
java.io.IOException
-
onTimeOut
public void onTimeOut()
Deprecated.Called back by the controller when an IO time out has been detected.
-
open
public void open()
Deprecated.Opens the connection. By default, set the IO state of the connection toConnectionState.OPENand the IO state of the inbound way toIoState.INTEREST.
-
reuse
public void reuse(java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress) throws java.io.IOExceptionDeprecated.Reuses the connection and associates it to the given socket.- Parameters:
socketChannel- The underlying NIO socket channel.controller- The underlying IO controller.socketAddress- The associated socket address.- Throws:
java.io.IOException
-
setPersistent
public void setPersistent(boolean persistent)
Deprecated.Indicates if the connection should be persisted across calls.- Parameters:
persistent- True if the connection should be persisted across calls.
-
setPipelining
public void setPipelining(boolean pipelining)
Deprecated.Indicates if idempotent sequences of requests can be pipelined.- Parameters:
pipelining- True requests pipelining is enabled.
-
setRegistration
public void setRegistration(SelectionRegistration registration)
Deprecated.Sets the socket's NIO registration holding the link between the channel and the way.- Parameters:
registration- The socket's NIO registration holding the link between the channel and the way.
-
setState
public void setState(ConnectionState state)
Deprecated.Sets the state of the connection.- Parameters:
state- The state of the connection.
-
shutdown
protected void shutdown(java.net.Socket socket) throws java.io.IOExceptionDeprecated.Shutdowns the socket, first its input then its output.- Parameters:
socket- The socket to shutdown.- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toStringin classjava.lang.Object
-
updateState
public boolean updateState()
Deprecated.Updates the connection states.- Returns:
- True if the state was changed.
-
-