Class ComponentReference<T>

  extended by com.atlassian.jira.component.ComponentReference<T>
Type Parameters:
T - the registration key for the component; usually an interface
All Implemented Interfaces:
Supplier<T>, Serializable

public class ComponentReference<T>
extends Object
implements com.atlassian.util.concurrent.Supplier<T>, Supplier<T>, Serializable

Provides a way to obtain a dependency that cannot be injected due to a circular reference and without having to make numerous explicit calls to ComponentAccessor.

Note that this is both serializable and thread-safe. However, it will only resolve components that were registered with the component class provided in the constructor; you can not specify some other interface as with ComponentAccessor.getComponentOfType(Class) or reference OSGi services as with ComponentAccessor.getOSGiComponentInstanceOfType(Class). This is a good thing; you should be using the proper registration key, anyway.

Unlike LazyReference, the get() method may be re-entered and multiple threads are permitted to resolve the reference if necessary. On the other hand, it also cannot deadlock, which LazyReference will do (in versions prior to 2.5.0) if a single thread attempts to re-enter it due to circular logic. Since circular logic using this class will return to the ComponentAccessor and eventually to Pico, the container's normal dependency loop detection is applied at the time the component is requested, which means you'll get told what the circular path was.

See Also:
Serialized Form

Method Summary
 boolean equals(Object o)
          Dependency references are equal iff they are references for the same componentClass.
 T get()
          Produce an object.
 int hashCode()
 String toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait

Method Detail


public T get()
Description copied from interface: Supplier
Produce an object. Retrieve an instance of the appropriate type. The returned object may or may not be a new instance, depending on the implementation.

Specified by:
get in interface Supplier<T>
the product, may be null if there are no objects available.


public final boolean equals(Object o)
Dependency references are equal iff they are references for the same componentClass.

equals in class Object


public final int hashCode()
hashCode in class Object


public String toString()
toString in class Object

Copyright © 2002-2014 Atlassian. All Rights Reserved.