Interface ComponentFactory

All Known Subinterfaces:
HttpRequestHandlerFactory

public interface ComponentFactory
A general purpose factory interface for components.

In some use cases, components may not be known at compile-time, but only made available at run-time. The usual pattern for this is to lookup a factory service using the ServiceLoader and create the components using the factory (or factories) found.

Because JGrapes components interact with their environment only through events, they do not provide special APIs and it is possible to define this generic factory service interface. Of course, lookup by the ServiceLoader will usually be done using a derived interface (or base class) that represents the special kind of components required and allows an invocation of ServiceLoader.load(Class) that returns a “filtered” set of factories.

Since:
1.3
  • Method Details

    • setStandardProperties

      static ComponentType setStandardProperties(ComponentType component, Map<?,?> properties)
      Assigns standard properties from the given properties to the component.

      Currently, the only standard property of a component is its name.

      Parameters:
      component - the component
      properties - the properties
      Returns:
      the optional
    • componentType

      Returns the type of the components created by this factory.
      Returns:
      the component type
    • create

      default ComponentType create()
      Creates a new component with its channel set to itself.
      Returns:
      the component
    • create

      default ComponentType create(Channel componentChannel)
      Creates a new component with its channel set to the given channel.
      Parameters:
      componentChannel - the channel that the component’s handlers listen on by default and that Manager.fire(Event, Channel...) sends the event to
      Returns:
      the component
    • create

      Optional<ComponentType> create(Channel componentChannel, Map<?,?> properties)
      Creates a new component with its channel set to the given channel using the given additional properties.

      If the requested properties or combination of properties cannot be provided by the component, the factory may return an empty Optional.

      Parameters:
      componentChannel - the channel that the component’s handlers listen on by default and that Manager.fire(Event, Channel...) sends the event to
      properties - additional properties for the creation of the component
      Returns:
      the component