Package hudson
Class ExtensionList<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<T>
-
- hudson.ExtensionList<T>
-
- Type Parameters:
T
- Type of the extension point. This class holds instances of the subtypes of 'T'.
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,List<T>
,OnMaster
- Direct Known Subclasses:
DescriptorExtensionList
public class ExtensionList<T> extends AbstractList<T> implements OnMaster
Retains the known extension instances for the given type 'T'.Extensions are loaded lazily on demand and automatically by using
ExtensionFinder
, but this class also provides a mechanism to provide compatibility with the olderDescriptorList
-based manual registration,All
ExtensionList
instances should be owned byJenkins
, even though extension points can be defined by anyone on any type. UseJenkins.getExtensionList(Class)
andJenkins.getDescriptorList(Class)
to obtain the instances.- Since:
- 1.286
- Author:
- Kohsuke Kawaguchi
- See Also:
Jenkins.getExtensionList(Class)
,Jenkins.getDescriptorList(Class)
-
-
Field Summary
Fields Modifier and Type Field Description Class<T>
extensionType
Hudson
hudson
Deprecated.as of 1.417 Usejenkins
Jenkins
jenkins
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExtensionList(Hudson hudson, Class<T> extensionType)
Deprecated.as of 1.416 UseExtensionList(Jenkins, Class)
protected
ExtensionList(Hudson hudson, Class<T> extensionType, CopyOnWriteArrayList<ExtensionComponent<T>> legacyStore)
Deprecated.as of 1.416 UseExtensionList(Jenkins, Class, CopyOnWriteArrayList)
protected
ExtensionList(Jenkins jenkins, Class<T> extensionType)
protected
ExtensionList(Jenkins jenkins, Class<T> extensionType, CopyOnWriteArrayList<ExtensionComponent<T>> legacyStore)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(int index, T element)
boolean
add(T t)
Deprecated.since 2009-02-23.void
addListener(ExtensionListListener listener)
Add a listener to the extension list.static void
clearLegacyInstances()
Exposed for the test harness to clear all legacy extension instances.static <T> ExtensionList<T>
create(Hudson hudson, Class<T> type)
Deprecated.as of 1.416 Usecreate(Jenkins, Class)
static <T> ExtensionList<T>
create(Jenkins jenkins, Class<T> type)
T
get(int index)
<U extends T>
Uget(Class<U> type)
Looks for the extension instance of the given type (subclasses excluded), or return null.List<ExtensionComponent<T>>
getComponents()
Gets the same thing as the 'this' list represents, except asExtensionComponent
s.T
getDynamic(String className)
Used to bind extension to URLs by their class names.<U extends T>
UgetInstance(Class<U> type)
Looks for the extension instance of the given type (subclasses excluded), or throws an IllegalStateException.protected Object
getLoadLock()
Chooses the object that locks the loading of the extension instances.Iterator<T>
iterator()
protected List<ExtensionComponent<T>>
load()
Loads all the extensions.protected Collection<ExtensionComponent<T>>
load(ExtensionComponentSet delta)
Picks up extensions that we care from the given list.static <T> ExtensionList<T>
lookup(Class<T> type)
Gets the extension list for a given type.static <U> U
lookupSingleton(Class<U> type)
Convenience method allowing lookup of the only instance of a given type.void
refresh(ExtensionComponentSet delta)
Used duringJenkins.refreshExtensions()
to add new components into existingExtensionList
s.T
remove(int index)
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
List<T>
reverseView()
Gets the read-only view of thisExtensionList
where components are reversed.int
size()
protected List<ExtensionComponent<T>>
sort(List<ExtensionComponent<T>> r)
If theExtensionList
implementation requires sorting extensions, override this method to do so.-
Methods inherited from class java.util.AbstractList
addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, set, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
ExtensionList
@Deprecated protected ExtensionList(Hudson hudson, Class<T> extensionType)
Deprecated.as of 1.416 UseExtensionList(Jenkins, Class)
-
ExtensionList
@Deprecated protected ExtensionList(Hudson hudson, Class<T> extensionType, CopyOnWriteArrayList<ExtensionComponent<T>> legacyStore)
Deprecated.as of 1.416 UseExtensionList(Jenkins, Class, CopyOnWriteArrayList)
-
ExtensionList
protected ExtensionList(Jenkins jenkins, Class<T> extensionType, CopyOnWriteArrayList<ExtensionComponent<T>> legacyStore)
- Parameters:
legacyStore
- Place to store manually registered instances. The version of the constructor that omits this uses a newVector
, making the storage lifespan tied to the life ofExtensionList
. If the manually registered instances are scoped to VM level, the caller should pass in a static list.
-
-
Method Detail
-
addListener
public void addListener(@NonNull ExtensionListListener listener)
Add a listener to the extension list.- Parameters:
listener
- The listener.
-
get
@CheckForNull public <U extends T> U get(@NonNull Class<U> type)
Looks for the extension instance of the given type (subclasses excluded), or return null.
-
getInstance
@NonNull public <U extends T> U getInstance(@NonNull Class<U> type) throws IllegalStateException
Looks for the extension instance of the given type (subclasses excluded), or throws an IllegalStateException. Meant to simplify call inside @Extension annotated class to retrieve their own instance.- Throws:
IllegalStateException
-
getComponents
public List<ExtensionComponent<T>> getComponents()
Gets the same thing as the 'this' list represents, except asExtensionComponent
s.
-
get
public T get(int index)
-
size
public int size()
- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in classAbstractCollection<T>
-
reverseView
public List<T> reverseView()
Gets the read-only view of thisExtensionList
where components are reversed.
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<T>
- Specified by:
remove
in interfaceList<T>
- Overrides:
remove
in classAbstractCollection<T>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<T>
- Specified by:
removeAll
in interfaceList<T>
- Overrides:
removeAll
in classAbstractCollection<T>
-
remove
public final T remove(int index)
-
add
@Deprecated public boolean add(T t)
Deprecated.since 2009-02-23. Prefer automatic registration.Write access will put the instance into a legacy store.- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceList<T>
- Overrides:
add
in classAbstractList<T>
-
add
public void add(int index, T element)
-
getDynamic
public T getDynamic(String className)
Used to bind extension to URLs by their class names.- Since:
- 1.349
-
getLoadLock
protected Object getLoadLock()
Chooses the object that locks the loading of the extension instances.
-
refresh
public void refresh(ExtensionComponentSet delta)
Used duringJenkins.refreshExtensions()
to add new components into existingExtensionList
s. Do not call from anywhere else.
-
load
protected List<ExtensionComponent<T>> load()
Loads all the extensions.
-
load
protected Collection<ExtensionComponent<T>> load(ExtensionComponentSet delta)
Picks up extensions that we care from the given list.
-
sort
protected List<ExtensionComponent<T>> sort(List<ExtensionComponent<T>> r)
If theExtensionList
implementation requires sorting extensions, override this method to do so.The implementation should copy a list, do a sort, and return the new instance.
-
create
@Deprecated public static <T> ExtensionList<T> create(Hudson hudson, Class<T> type)
Deprecated.as of 1.416 Usecreate(Jenkins, Class)
-
create
public static <T> ExtensionList<T> create(Jenkins jenkins, Class<T> type)
-
lookup
@NonNull public static <T> ExtensionList<T> lookup(Class<T> type)
Gets the extension list for a given type. Normally callsJenkins.getExtensionList(Class)
but falls back to an empty list in caseJenkins.getInstanceOrNull()
is null. Thus it is useful to call fromall()
methods which need to behave gracefully during startup or shutdown.- Parameters:
type
- the extension point type- Returns:
- some list
- Since:
- 1.572
-
lookupSingleton
@NonNull public static <U> U lookupSingleton(Class<U> type)
Convenience method allowing lookup of the only instance of a given type. Equivalent toExtensionList.lookup(Class).get(Class)
if there is one instance, and throws anIllegalStateException
otherwise.- Parameters:
type
- The type to look up.- Returns:
- the singleton instance of the given type in its list.
- Throws:
IllegalStateException
- if there are no instances, or more than one- Since:
- 2.87
-
clearLegacyInstances
public static void clearLegacyInstances()
Exposed for the test harness to clear all legacy extension instances.
-
-