Class Factory
- All Implemented Interfaces:
AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<MachineEngine<?>>static final Stringstatic final Stringstatic final Comparator<NamedComponent<?>> -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> StringactivationKey(Class<T> aClass, String name) and()Returns current factory, used only for fluent API to have more readable code like factory.start().and().prepare();static Factory.Builderbuilder()voidclose()concat(FactoryMachine machine) dump()dumper()Returns an object which toString method dumps the factory.<T> TgetComponent(Class<T> componentClass) Builds a component by class.<T> TgetComponent(Name<T> componentName) Builds a component by name.<T> Set<T>getComponents(Class<T> componentClass) Builds and return all the component of given class.static com.google.common.base.Optional<Factory>getFactory(String key) getId()static FactoryReturns a default Factory instance, getting componenents from ServiceLoader only.intstatic Factoryprepare()Prepares all the AutoPreparable components of this factory.<T> Factory.Query<T>queryByClass(Class<T> componentClass) <T> Factory.Query<T>queryByName(Name<T> name) static Factorystart()Starts all the AutoStartable components of this factory.toString()static booleanunregister(String key, Factory factory)
-
Field Details
-
METRICS_REGISTRY
- See Also:
-
HEALTH_CHECK_REGISTRY
- See Also:
-
ENGINE_COMPARATOR
-
NAMED_COMPONENT_COMPARATOR
-
-
Method Details
-
getFactory
-
register
-
unregister
-
newInstance
-
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
-
activationKey
-
concat
-
getId
-
getWarehouse
-
getNbMachines
public int getNbMachines() -
queryByName
-
queryByClass
-
getComponent
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
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
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
Returns current factory, used only for fluent API to have more readable code like factory.start().and().prepare();- Returns:
- current factory
-
start
Starts all the AutoStartable components of this factory. -
prepare
Prepares all the AutoPreparable components of this factory. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
toString
-
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
-