Class NioClientManager

  • All Implemented Interfaces:
    com.google.common.util.concurrent.Service, ClientConnectionManager

    public class NioClientManager
    extends com.google.common.util.concurrent.AbstractExecutionThreadService
    implements ClientConnectionManager
    A class which manages a set of client connections. Uses Java NIO to select network events and processes them in a single network processing thread.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.google.common.util.concurrent.Service

        com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
    • Constructor Summary

      Constructors 
      Constructor Description
      NioClientManager()
      Creates a new client manager which uses Java NIO for socket management.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void closeConnections​(int n)
      Closes n peer connections
      protected java.util.concurrent.Executor executor()  
      int getConnectedClientCount()
      Gets the number of connected peers
      com.google.common.util.concurrent.ListenableFuture<java.net.SocketAddress> openConnection​(java.net.SocketAddress serverAddress, StreamConnection connection)
      Creates a new connection to the given address, with the given connection used to handle incoming data.
      void run()  
      void triggerShutdown()  
      • Methods inherited from class com.google.common.util.concurrent.AbstractExecutionThreadService

        addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, serviceName, shutDown, startAsync, startUp, state, stopAsync, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface com.google.common.util.concurrent.Service

        addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, startAsync, state, stopAsync
    • Constructor Detail

      • NioClientManager

        public NioClientManager()
        Creates a new client manager which uses Java NIO for socket management. Uses a single thread to handle all select calls.
    • Method Detail

      • run

        public void run()
        Specified by:
        run in class com.google.common.util.concurrent.AbstractExecutionThreadService
      • openConnection

        public com.google.common.util.concurrent.ListenableFuture<java.net.SocketAddress> openConnection​(java.net.SocketAddress serverAddress,
                                                                                                         StreamConnection connection)
        Description copied from interface: ClientConnectionManager
        Creates a new connection to the given address, with the given connection used to handle incoming data. Any errors that occur during connection will be returned in the given future, including errors that can occur immediately.
        Specified by:
        openConnection in interface ClientConnectionManager
      • triggerShutdown

        public void triggerShutdown()
        Overrides:
        triggerShutdown in class com.google.common.util.concurrent.AbstractExecutionThreadService
      • executor

        protected java.util.concurrent.Executor executor()
        Overrides:
        executor in class com.google.common.util.concurrent.AbstractExecutionThreadService