Class ComponentVertex
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,Eligible
,Manager
- Direct Known Subclasses:
Component
,ComponentProxy
ComponentVertex is extended by Component
for the use as base class for component implementations. As an
alternative for implementing components with an independent base class,
the derived class ComponentProxy
can be
used.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
ComponentVertex
(HandlerDefinition.ChannelReplacements channelReplacements) Initialize the ComponentVertex. -
Method Summary
Modifier and TypeMethodDescriptionReturns the pipeline used when firing an event.void
addHandler
(Method method, HandlerScope scope, int priority) Adds a handler for the given method with the given scope and priority.<T extends ComponentType>
Tattach
(T child) Attaches the given component node (or complete tree) as a child to the component managed by this manager.Return the channel replacements passed to the constructor.children()
Returns the child components of the component managed by this manager as unmodifiable list.abstract ComponentType
Returns the component represented by this node in the tree.Returns the path of the component.static ComponentVertex
componentVertex
(ComponentType component, Channel componentChannel) Return the component node for a given component.detach()
Detaches the component managed by this manager (with its children, if any) from the component tree that it currently belongs to.<T> Event
<T> Fires the given event on the given channel.protected void
Initialize the handler list of this component.iterator()
Returns an iterator that visits the components of the component subtree that has this node as root.name()
Returns the (optional) name of the component.Return a newEventPipeline
that processes the added events using a thread from a thread pool.newEventPipeline
(ExecutorService executorService) Return a newEventPipeline
that processes the added events using threads from the given executor service.parent()
Returns the parent of the component managed by this manager.void
Register the managed component as a running generator.root()
Returns the root of the tree the component managed by this manager belongs to.Sets the (optional) name of the component.toString()
If a name has been set for this component (seeManager.setName(String)
), return the name, else return the object name provided byComponents.objectName(Object)
, usingcomponent()
as argument.void
Unregister the managed component as a running generator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jgrapes.core.Channel
isEligibleFor
Methods inherited from interface org.jgrapes.core.Eligible
defaultCriterion
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ComponentVertex
Initialize the ComponentVertex.By default it forms a stand-alone tree, i.e. the root is set to the component itself.
- Parameters:
channelReplacements
- the channel replacements
-
-
Method Details
-
channelReplacements
Return the channel replacements passed to the constructor.- Returns:
- the channel replacements
-
initComponentsHandlers
Initialize the handler list of this component.May only be called when
component()
can be relied on to return the correct value. -
setName
Description copied from interface:Manager
Sets the (optional) name of the component. -
name
Description copied from interface:Manager
Returns the (optional) name of the component. -
componentPath
Description copied from interface:Manager
Returns the path of the component.The path is the concatenation of a slash (‘/’) and the component’s name for all components from the root component to this component. If a component doesn’t have a name set, the simple name of its class (see
Class.getSimpleName()
) is used instead.- Specified by:
componentPath
in interfaceManager
-
componentVertex
Return the component node for a given component.- Parameters:
component
- the componentcomponentChannel
- the component’s channel- Returns:
- the node representing the component in the tree
-
component
Returns the component represented by this node in the tree. -
children
Description copied from interface:Manager
Returns the child components of the component managed by this manager as unmodifiable list. -
parent
Description copied from interface:Manager
Returns the parent of the component managed by this manager. -
root
Description copied from interface:Manager
Returns the root of the tree the component managed by this manager belongs to. -
attach
Description copied from interface:Manager
Attaches the given component node (or complete tree) as a child to the component managed by this manager.The node or tree may not have been started.
If a component (or component tree) is attached to an already started tree, a
Start
event is automatically fired with the list of components from the attached subtree as channels. This guarantees that every component gets aStart
event once. For efficiency, it is therefore preferable to build a subtree first and attach it, instead of attaching the nodes to the existing tree one by one. -
detach
Description copied from interface:Manager
Detaches the component managed by this manager (with its children, if any) from the component tree that it currently belongs to.This method results in a
IllegalStateException
if called on a tree before aStart
event has been fired on it. The Reason for this restriction is that distributing buffered events between the two separated trees cannot easily be defined in an intuitive way. -
iterator
Description copied from interface:Manager
Returns an iterator that visits the components of the component subtree that has this node as root.- Specified by:
iterator
in interfaceIterable<ComponentType>
- Specified by:
iterator
in interfaceManager
- Returns:
- the iterator
-
addHandler
Description copied from interface:Manager
Adds a handler for the given method with the given scope and priority.This method is usually not invoked directly. Rather, a
HandlerDefinition.Evaluator
providesadd(...)
methods that evaluate the requiredmethod
andscope
arguments from easier to provide arguments and then call this method.- Specified by:
addHandler
in interfaceManager
- Parameters:
method
- the method to invokescope
- the handler scope to be used for matching eventspriority
- the priority of the handler- See Also:
-
fire
Description copied from interface:Manager
Fires the given event on the given channel.If no channels are specified as parameters, the event is fired on the event’s channel (see
Event.channels()
). If the event doesn’t specify channels either, the event is fired on the channel of the component managed by this manager (seeManager.channel()
).If an event is fired inside an event handler, it is added to the
EventPipeline
that has invoked the handler. If an event is fired by some other thread (not associated with a pipeline), a new pipeline is created for handling the event (and any events triggered by it). -
activeEventPipeline
Description copied from interface:Manager
Returns the pipeline used when firing an event.- Specified by:
activeEventPipeline
in interfaceManager
- Returns:
- the event pipeline
- See Also:
-
newEventPipeline
Description copied from interface:Manager
Return a newEventPipeline
that processes the added events using a thread from a thread pool.- Specified by:
newEventPipeline
in interfaceManager
- Returns:
- the pipeline
-
newEventPipeline
Description copied from interface:Manager
Return a newEventPipeline
that processes the added events using threads from the given executor service.- Specified by:
newEventPipeline
in interfaceManager
- Parameters:
executorService
- the executor service- Returns:
- the pipeline
-
toString
If a name has been set for this component (seeManager.setName(String)
), return the name, else return the object name provided byComponents.objectName(Object)
, usingcomponent()
as argument. -
registerAsGenerator
Description copied from interface:Manager
Register the managed component as a running generator.- Specified by:
registerAsGenerator
in interfaceManager
-
unregisterAsGenerator
Description copied from interface:Manager
Unregister the managed component as a running generator.- Specified by:
unregisterAsGenerator
in interfaceManager
-