Class Connection<T extends Connector>

  • 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.
    • 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
      void clear()
      Deprecated.
      Clears the connection so it can be reused.
      void close​(boolean graceful)
      Deprecated.
      Closes the connection.
      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.
      protected ReadableSelectionChannel createReadableSelectionChannel()
      Deprecated.
      Creates a new readable channel.
      protected WritableSelectionChannel createWritableSelectionChannel()
      Deprecated.
      Creates a new writable channel.
      java.lang.String getAddress()
      Deprecated.
      Returns the socket IP address.
      ConnectionHelper<T> getHelper()
      Deprecated.
      Returns the parent connector helper.
      int getInboundBufferSize()
      Deprecated.
      Returns the size of the content buffer for receiving messages.
      InboundWay getInboundWay()
      Deprecated.
      Returns the inbound way.
      long getLastActivity()
      Deprecated.
      Returns the timestamp of the last IO activity.
      int getLoadScore()
      Deprecated.
      Returns a score representing the connection load and that could be compared with other connections of the same parent connector.
      java.util.logging.Logger getLogger()
      Deprecated.
      Returns the logger.
      int getMaxIoIdleTimeMs()
      Deprecated.
      Returns the time for an idle IO connection to wait for an operation before being closed.
      int getOutboundBufferSize()
      Deprecated.
      Returns the size of the content buffer for sending responses.
      OutboundWay getOutboundWay()
      Deprecated.
      Returns the outbound way.
      int getPort()
      Deprecated.
      Returns the socket port.
      ReadableSelectionChannel getReadableSelectionChannel()
      Deprecated.
      Returns the underlying socket channel as a readable selection channel.
      SelectionRegistration getRegistration()
      Deprecated.
      Returns the socket's NIO registration holding the link between the SocketChannel and the Connection.
      java.net.Socket getSocket()
      Deprecated.
      Returns the underlying socket.
      java.net.SocketAddress getSocketAddress()
      Deprecated.
      Returns the socket address.
      java.nio.channels.SocketChannel getSocketChannel()
      Deprecated.
      Returns the underlying NIO socket channel.
      ConnectionState getState()
      Deprecated.
      Returns the state of the connection.
      WritableSelectionChannel getWritableSelectionChannel()
      Deprecated.
      Returns the underlying socket channel as a writable selection channel.
      boolean hasTimedOut()
      Deprecated.
      Indicates if the connection has timed out.
      void init​(java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress)
      Deprecated.
      Initializes the connection and associates it to the given socket.
      boolean isAvailable()
      Deprecated.
      Indicates if the connection is available to handle new messages.
      boolean isClientSide()
      Deprecated.
      Indicates if it is a client-side connection.
      boolean isEmpty()
      Deprecated.
      Indicates if the connection is empty of messages and bytes.
      boolean isPersistent()
      Deprecated.
      Indicates if the connection should be persisted across calls.
      boolean isPipelining()
      Deprecated.
      Indicates if idempotent sequences of requests can be pipelined.
      boolean isReady()
      Deprecated.
      Indicates if at least one way is in the IoState.READY state.
      boolean isServerSide()
      Deprecated.
      Indicates if it is a server-side connection.
      void onActivity()
      Deprecated.
      Notifies the connection that a new activity has been detected and that it should be kept alive.
      void onError​(java.lang.String message, java.lang.Throwable throwable, Status status)
      Deprecated.
      Called on error.
      void onSelected​(SelectionRegistration registration)
      Deprecated.
      Callback method invoked when the connection has been selected for IO operations it registered interest in.
      void onTimeOut()
      Deprecated.
      Called back by the controller when an IO time out has been detected.
      void open()
      Deprecated.
      Opens the connection.
      void reuse​(java.nio.channels.SocketChannel socketChannel, ConnectionController controller, java.net.InetSocketAddress socketAddress)
      Deprecated.
      Reuses the connection and associates it to the given socket.
      void setPersistent​(boolean persistent)
      Deprecated.
      Indicates if the connection should be persisted across calls.
      void setPipelining​(boolean pipelining)
      Deprecated.
      Indicates if idempotent sequences of requests can be pipelined.
      void setRegistration​(SelectionRegistration registration)
      Deprecated.
      Sets the socket's NIO registration holding the link between the channel and the way.
      void setState​(ConnectionState state)
      Deprecated.
      Sets the state of the connection.
      protected void shutdown​(java.net.Socket socket)
      Deprecated.
      Shutdowns the socket, first its input then its output.
      java.lang.String toString()
      Deprecated.
       
      boolean updateState()
      Deprecated.
      Updates the connection states.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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 to ConnectionState.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 calls getInboundBufferSize().
        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 calls getOutboundBufferSize().
        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 the SocketChannel and the Connection.
        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.IOException
        Deprecated.
        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 the IoState.READY state.
        Returns:
        True if at least one way is in the IoState.READY state.
      • 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 calls close(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 calls SelectionRegistration.onSelected(int) on the inbound or outbound way.
        Specified by:
        onSelected in interface SelectionListener
        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 to ConnectionState.OPEN and the IO state of the inbound way to IoState.INTEREST.
      • reuse

        public void reuse​(java.nio.channels.SocketChannel socketChannel,
                          ConnectionController controller,
                          java.net.InetSocketAddress socketAddress)
                   throws java.io.IOException
        Deprecated.
        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.IOException
        Deprecated.
        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:
        toString in class java.lang.Object
      • updateState

        public boolean updateState()
        Deprecated.
        Updates the connection states.
        Returns:
        True if the state was changed.