Package org.jgrapes.io.util
Class ConnectionManager<C extends ConnectionManager<C>.Connection>
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.io.util.ConnectionManager<C>
- 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
Subchannel
s representing
some kind of connection to a server or service.-
Nested Class Summary
Modifier and TypeClassDescriptionclass
The base class for the connections managed by this component.Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates a new component base with its channel set to itself.ConnectionManager
(Channel componentChannel) Creates a new component base likeComponent(Channel)
but with channel mappings forHandler
annotations.ConnectionManager
(Channel componentChannel, HandlerDefinition.ChannelReplacements channelReplacements) Creates a new component base with its channel set to the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
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 the executor service.void
Closes the given connection.void
Closes all connections.setExecutorService
(ExecutorService executorService) Sets an executor service to be used by the downstream event pipelines.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
connections
-
-
Constructor Details
-
ConnectionManager
public 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 thatManager.fire(Event, Channel...)
sends the event to
-
ConnectionManager
Creates a new component base likeComponent(Channel)
but with channel mappings forHandler
annotations.- Parameters:
componentChannel
- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)
sends the event to
-
-
Method Details
-
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
Closes all connections.- Parameters:
event
- the event
-
onClose
Closes the given connection.- Parameters:
event
- the eventconnection
- the connection
-