Class NioClientManager

java.lang.Object
com.google.common.util.concurrent.AbstractExecutionThreadService
org.bitcoinj.net.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
    Creates a new client manager which uses Java NIO for socket management.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes n peer connections
    protected Executor
     
    int
    Gets the number of connected peers
    com.google.common.util.concurrent.ListenableFuture<SocketAddress>
    openConnection(SocketAddress serverAddress, StreamConnection connection)
    Creates a new connection to the given address, with the given connection used to handle incoming data.
    void
    run()
     
    void
     

    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 Details

    • 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 Details

    • run

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

      public com.google.common.util.concurrent.ListenableFuture<SocketAddress> openConnection(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
    • getConnectedClientCount

      public int getConnectedClientCount()
      Description copied from interface: ClientConnectionManager
      Gets the number of connected peers
      Specified by:
      getConnectedClientCount in interface ClientConnectionManager
    • closeConnections

      public void closeConnections(int n)
      Description copied from interface: ClientConnectionManager
      Closes n peer connections
      Specified by:
      closeConnections in interface ClientConnectionManager
    • executor

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