|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjfun.yan.containers.SimpleContainer
jfun.yan.containers.ImmutablePreferredContainer
public class ImmutablePreferredContainer
An optimized container that's fast when it is used immutably.
The autowire by type is slow because it needs linear time. If the underlying container is not changing, we can optimize it by caching the result of each getComponentOfType(), getComponentsOfType() and containsType(). thus each type is searched at most once.
After getComponentOfType() is called, the same result will always be returned. Newly registered component or unregistered component will invalidate the cache and the subsequent lookup will perform the slow search again.
This is typically not a problem anyway.
| Constructor Summary | |
|---|---|
ImmutablePreferredContainer(Registrar reg)
|
|
| Method Summary | ||
|---|---|---|
boolean |
containsType(java.lang.Class type)
Whether a Component of a certain type or its sub-type is contained in the map. |
|
|
getComponentOfType(java.lang.Class<T> type)
Gets a Component object of a certain type. |
|
|
getComponentsOfType(java.lang.Class<T> type)
Gets all component objects that are of a certain type. |
|
Factory |
getFactory(java.lang.Object key)
Create an instance of Factory for a component identified by a key. |
|
Factory |
getFactory(java.lang.Object key,
ComponentMap cmap)
Create an instance of Factory for a component identified by a key. |
|
|
getFactoryOfType(java.lang.Class<T> type)
Create an instance of Factory for a component of the provided type. |
|
|
getFactoryOfType(java.lang.Class<T> type,
ComponentMap cmap)
Create an instance of Factory for a component of the provided type. |
|
java.lang.Object |
getInstance(java.lang.Object key)
Create instance for a component identified by a key. |
|
java.lang.Object |
getInstance(java.lang.Object key,
ComponentMap cmap)
Create instance for a component identified by a key. |
|
|
getInstanceOfType(java.lang.Class<T> type)
Create component instance of the provided type. |
|
|
getInstanceOfType(java.lang.Class<T> type,
ComponentMap cmap)
Create component instance of the provided type. |
|
void |
registerComponent(java.lang.Object key,
Component cc)
Register a Component identified by a key. |
|
void |
unregisterComponent(java.lang.Object key)
Unregister a component identified by a key. |
|
void |
unregisterComponentsOfType(java.lang.Class type)
Unregister components of a certain type. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ImmutablePreferredContainer(Registrar reg)
| Method Detail |
|---|
public <T> Component<T> getComponentOfType(java.lang.Class<T> type)
ComponentMap
getComponentOfType in interface ComponentMapgetComponentOfType in class SimpleContainertype - the component instance type.
public boolean containsType(java.lang.Class type)
ComponentMap
containsType in interface ComponentMapcontainsType in class SimpleContainertype - the type of the component.
public <T> java.util.List<Component<T>> getComponentsOfType(java.lang.Class<T> type)
ComponentMap
getComponentsOfType in interface ComponentMapgetComponentsOfType in class SimpleContainertype - the component instance type.
public Factory getFactory(java.lang.Object key,
ComponentMap cmap)
throws UnresolvedComponentException,
YanException
ContainerFactory for a component identified by a key.
when Factory.create() is called, the component is instantiated.
getFactory in interface ContainergetFactory in class SimpleContainerkey - the component key.cmap - the container to resolve dependency.
UnresolvedComponentException - if this component cannot be resolved.
YanException - for any other exception.public Factory getFactory(java.lang.Object key)
ContainerFactory for a component identified by a key.
when Factory.create() is called, the component is instantiated.
getFactory in interface ContainergetFactory in class SimpleContainerkey - the component key.
public <T> Factory<T> getFactoryOfType(java.lang.Class<T> type,
ComponentMap cmap)
ContainerFactory for a component of the provided type.
when Factory.create() is called, the component is instantiated.
getFactoryOfType in interface ContainergetFactoryOfType in class SimpleContainertype - the type.cmap - the container to resolve dependency.
public <T> Factory<T> getFactoryOfType(java.lang.Class<T> type)
ContainerFactory for a component of the provided type.
when Factory.create() is called, the component is instantiated.
getFactoryOfType in interface ContainergetFactoryOfType in class SimpleContainertype - the type.
public java.lang.Object getInstance(java.lang.Object key,
ComponentMap cmap)
Container
getInstance in interface ContainergetInstance in class SimpleContainerkey - the component key.cmap - the container to resolve dependency.
public java.lang.Object getInstance(java.lang.Object key)
Container
getInstance in interface ContainergetInstance in class SimpleContainerkey - the component key.
public <T> T getInstanceOfType(java.lang.Class<T> type,
ComponentMap cmap)
Container
getInstanceOfType in interface ContainergetInstanceOfType in class SimpleContainertype - the type.cmap - the container to resolve dependency.
public <T> T getInstanceOfType(java.lang.Class<T> type)
Container
getInstanceOfType in interface ContainergetInstanceOfType in class SimpleContainertype - the type.
public void registerComponent(java.lang.Object key,
Component cc)
Registrar
registerComponent in interface RegistrarregisterComponent in class SimpleContainerkey - the component key.cc - the component.public void unregisterComponent(java.lang.Object key)
Registrar
unregisterComponent in interface RegistrarunregisterComponent in class SimpleContainerkey - the component key.public void unregisterComponentsOfType(java.lang.Class type)
Registrar
unregisterComponentsOfType in interface RegistrarunregisterComponentsOfType in class SimpleContainertype - the component instance type.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||