Interface NetworkEndpoint<T>

  • Type Parameters:
    T - Base type of messages that can be supported by this endpoint.
    All Known Subinterfaces:
    NetworkClient<T>

    public interface NetworkEndpoint<T>
    Base interface for network communication endpoints.
    • Method Detail

      • remoteAddress

        InetSocketAddress remoteAddress()
        Returns the remote address of this endpoint. Returns null if this endpoint is not connected.
        Returns:
        Remote address or null if endpoint is not connected.
      • localAddress

        InetSocketAddress localAddress()
        Returns the local address of this endpoint. Returns null if this endpoint is not connected.
        Returns:
        Local address or null if this endpoint is not connected.
      • getContext

        Object getContext()
        Returns the custom user context object that was set via setContext(Object).
        Returns:
        Context object.
      • setContext

        void setContext​(Object ctx)
        Sets the custom user context object that should be associated with this endpoint.
        Parameters:
        ctx - Context object.
      • send

        void send​(T msg)
        Asynchronously sends the specified message.

        Note that this methods doesn't provide any feedback on whether operation completes successfully or with an error. Consider using send(Object, NetworkSendCallback) method if such feedback is required.

        Parameters:
        msg - Message.
      • send

        void send​(T msg,
                  NetworkSendCallback<T> callback)
        Asynchronously sends the specified message and notifies the specified callback on operation result.

        Note that the specified callback will be called on the NetworkEndpoint's NIO thread. It must be executed as fast as possible in order to prevent blocking other endpoints that can be associated with the same thread. In case of long/heavy computations consider scheduling such tasks to another thread.

        Parameters:
        msg - Message.
        callback - Callback.
      • pauseReceiving

        void pauseReceiving​(Consumer<NetworkEndpoint<T>> callback)
        Pauses receiving of messages from a remote peer. Does nothing if receiving is already paused or is disconnected.

        Note that pausing is an asynchronous operation and some messages, that were buffered prior to this method call, can still be received.

        Parameters:
        callback - Optional callback to be notified once pausing takes effect (can be null).
        See Also:
        resumeReceiving(Consumer), isReceiving()
      • resumeReceiving

        void resumeReceiving​(Consumer<NetworkEndpoint<T>> callback)
        Resumes receiving of messages from a remote peer. Does nothing if receiving is not paused or is disconnected.
        Parameters:
        callback - Optional callback to be notified once resuming takes effect (can be null).
        See Also:
        pauseReceiving(Consumer), isReceiving()
      • disconnect

        NetworkFuture<T> disconnect()
        Asynchronously disconnects this endpoint.
        Returns:
        Future object that can be used to obtain result of this operation.