Class ComponentVertex

java.lang.Object
org.jgrapes.core.internal.ComponentVertex
All Implemented Interfaces:
Iterable<ComponentType>, Channel, Eligible, Manager
Direct Known Subclasses:
Component, ComponentProxy

public abstract class ComponentVertex extends Object implements Manager, Channel
ComponentVertex is the base class for all nodes in the component tree.

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.

  • 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

      protected void initComponentsHandlers()
      Initialize the handler list of this component.

      May only be called when component() can be relied on to return the correct value.

    • setName

      public ComponentType setName(String name)
      Description copied from interface: Manager
      Sets the (optional) name of the component.
      Specified by:
      setName in interface Manager
      Parameters:
      name - the name to set
      Returns:
      the component (for comfortable chaining)
    • name

      public String name()
      Description copied from interface: Manager
      Returns the (optional) name of the component.
      Specified by:
      name in interface Manager
    • 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 interface Manager
    • componentVertex

      public static ComponentVertex componentVertex(ComponentType component, Channel componentChannel)
      Return the component node for a given component.
      Parameters:
      component - the component
      componentChannel - the component’s channel
      Returns:
      the node representing the component in the tree
    • component

      public abstract ComponentType component()
      Returns the component represented by this node in the tree.
      Specified by:
      component in interface Manager
      Returns:
      the component
    • children

      Description copied from interface: Manager
      Returns the child components of the component managed by this manager as unmodifiable list.
      Specified by:
      children in interface Manager
      Returns:
      the child components
    • parent

      Description copied from interface: Manager
      Returns the parent of the component managed by this manager.
      Specified by:
      parent in interface Manager
      Returns:
      the parent component or null if the component is not registered with another component
    • root

      public ComponentType root()
      Description copied from interface: Manager
      Returns the root of the tree the component managed by this manager belongs to.
      Specified by:
      root in interface Manager
      Returns:
      the root
    • attach

      public <T extends ComponentType> T attach(T child)
      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 a Start 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.

      Specified by:
      attach in interface Manager
      Type Parameters:
      T - the component node’s type
      Parameters:
      child - the component to add
      Returns:
      the added component (for comfortable chaining)
    • 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 a Start 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.

      Specified by:
      detach in interface Manager
      Returns:
      the component (for comfortable chaining)
    • 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 interface Iterable<ComponentType>
      Specified by:
      iterator in interface Manager
      Returns:
      the iterator
    • addHandler

      public void addHandler(Method method, HandlerScope scope, int priority)
      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 provides add(...) methods that evaluate the required method and scope arguments from easier to provide arguments and then call this method.

      Specified by:
      addHandler in interface Manager
      Parameters:
      method - the method to invoke
      scope - the handler scope to be used for matching events
      priority - the priority of the handler
      See Also:
    • fire

      public <T> Event<T> fire(Event<T> event, Channel... channels)
      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 (see Manager.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).

      Specified by:
      fire in interface Manager
      Type Parameters:
      T - the result type of the event
      Parameters:
      event - the event to fire
      channels - the channels to fire the event on
      Returns:
      the event (for easy chaining)
    • activeEventPipeline

      Description copied from interface: Manager
      Returns the pipeline used when firing an event.
      Specified by:
      activeEventPipeline in interface Manager
      Returns:
      the event pipeline
      See Also:
    • newEventPipeline

      Description copied from interface: Manager
      Return a new EventPipeline that processes the added events using a thread from a thread pool.
      Specified by:
      newEventPipeline in interface Manager
      Returns:
      the pipeline
    • newEventPipeline

      Description copied from interface: Manager
      Return a new EventPipeline that processes the added events using threads from the given executor service.
      Specified by:
      newEventPipeline in interface Manager
      Parameters:
      executorService - the executor service
      Returns:
      the pipeline
    • toString

      public String toString()
      If a name has been set for this component (see Manager.setName(String)), return the name, else return the object name provided by Components.objectName(Object), using component() as argument.
      Overrides:
      toString in class Object
    • registerAsGenerator

      public void registerAsGenerator()
      Description copied from interface: Manager
      Register the managed component as a running generator.
      Specified by:
      registerAsGenerator in interface Manager
    • unregisterAsGenerator

      public void unregisterAsGenerator()
      Description copied from interface: Manager
      Unregister the managed component as a running generator.
      Specified by:
      unregisterAsGenerator in interface Manager