Package restx.factory

Class Factory

java.lang.Object
restx.factory.Factory
All Implemented Interfaces:
AutoCloseable

public class Factory extends Object implements AutoCloseable
User: xavierhanin Date: 1/31/13 Time: 5:42 PM
  • Field Details

  • Method Details

    • getFactory

      public static com.google.common.base.Optional<Factory> getFactory(String key)
    • register

      public static Factory register(String key, Factory factory)
    • unregister

      public static boolean unregister(String key, Factory factory)
    • newInstance

      public static Factory newInstance()
    • getInstance

      public static Factory getInstance()
      Returns a default Factory instance, getting componenents from ServiceLoader only.

      Make sure you never close that instance except on JVM shutdown, it's probably shared among several usages.

      Prefer using your own Factory with newInstance for instance if you want to have control over its lifecycle.

      Returns:
      the default factory instance.
    • builder

      public static Factory.Builder builder()
    • activationKey

      public static <T> String activationKey(Class<T> aClass, String name)
    • concat

      public Factory concat(FactoryMachine machine)
    • getId

      public String getId()
    • getWarehouse

      public Warehouse getWarehouse()
    • getNbMachines

      public int getNbMachines()
    • queryByName

      public <T> Factory.Query<T> queryByName(Name<T> name)
    • queryByClass

      public <T> Factory.Query<T> queryByClass(Class<T> componentClass)
    • getComponent

      public <T> T getComponent(Class<T> componentClass)
      Builds a component by class.

      This is a shortcut for queryByClass(cls).mandatory().findOneAsComponent().get()

      Therefore it raises an exception if no component of this class is found or if several one match.

      Type Parameters:
      T -
      Parameters:
      componentClass -
      Returns:
    • getComponent

      public <T> T getComponent(Name<T> componentName)
      Builds a component by name.

      This is a shortcut for queryByName(name).mandatory().findOneAsComponent().get()

      Therefore it raises an exception if no component of this name is found.

      Type Parameters:
      T -
      Parameters:
      componentName -
      Returns:
    • getComponents

      public <T> Set<T> getComponents(Class<T> componentClass)
      Builds and return all the component of given class.

      This is a shortcut for queryByClass(componentClass).findAsComponents()

      Type Parameters:
      T - the type of components
      Parameters:
      componentClass - the class of the components to build and return
      Returns:
      the set of components of given class
    • and

      public Factory and()
      Returns current factory, used only for fluent API to have more readable code like factory.start().and().prepare();
      Returns:
      current factory
    • start

      public Factory start()
      Starts all the AutoStartable components of this factory.
    • prepare

      public Factory prepare()
      Prepares all the AutoPreparable components of this factory.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dumper

      public Object dumper()
      Returns an object which toString method dumps the factory.

      This is useful in logger or check messages, to prevent actually calling dump() if log is disabled or check does not raise exception.

      Returns:
      a dumper for the factory.
    • dump

      public String dump()