Class ConnectionManager<C extends ConnectionManager<C>.Connection>

Type Parameters:
C - the type of the managed connections
All Implemented Interfaces:
Iterable<ComponentType>, Channel, ComponentType, Eligible, Manager
Direct Known Subclasses:
MailConnectionManager

public abstract class ConnectionManager<C extends ConnectionManager<C>.Connection> extends Component
A base class for components that manage Subchannels representing some kind of connection to a server or service.
  • Field Details

  • Constructor Details

    • ConnectionManager

      Creates a new component base with its channel set to itself.
    • ConnectionManager

      public ConnectionManager(Channel componentChannel, HandlerDefinition.ChannelReplacements channelReplacements)
      Creates a new component base with its channel set to the given channel.

      As a special case Channel.SELF can be passed to the constructor to make the component use itself as channel. The special value is necessary as you obviously cannot pass an object to be constructed to its constructor.

      Parameters:
      componentChannel - the channel that the component’s handlers listen on by default and that Manager.fire(Event, Channel...) sends the event to
    • ConnectionManager

      public ConnectionManager(Channel componentChannel)
      Creates a new component base like Component(Channel) but with channel mappings for Handler annotations.
      Parameters:
      componentChannel - the channel that the component’s handlers listen on by default and that Manager.fire(Event, Channel...) sends the event to
  • Method Details

    • connectionsGenerate

      protected abstract boolean connectionsGenerate()
      If connections are event generators, register the component as generator upon the creation of the first connection and unregister it when closing the last one.
      Returns:
      true, if connections generate
    • setExecutorService

      Sets an executor service to be used by the downstream event pipelines.

      Setting this to an executor service with a limited number of threads allows to control the maximum load caused by events generated by this component.

      Parameters:
      executorService - the executorService to set
      Returns:
      the connection manager for easy chaining
      See Also:
    • executorService

      Returns the executor service.
      Returns:
      the executorService
    • onStop

      @Handler public void onStop(Stop event)
      Closes all connections.
      Parameters:
      event - the event
    • onClose

      @Handler public void onClose(Close event, C connection)
      Closes the given connection.
      Parameters:
      event - the event
      connection - the connection