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
ExtensionListinstances 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>extensionTypeHudsonhudsonDeprecated.as of 1.417 UsejenkinsJenkinsjenkins-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedExtensionList(Hudson hudson, Class<T> extensionType)Deprecated.as of 1.416 UseExtensionList(Jenkins, Class)protectedExtensionList(Hudson hudson, Class<T> extensionType, CopyOnWriteArrayList<ExtensionComponent<T>> legacyStore)Deprecated.as of 1.416 UseExtensionList(Jenkins, Class, CopyOnWriteArrayList)protectedExtensionList(Jenkins jenkins, Class<T> extensionType)protectedExtensionList(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 voidadd(int index, T element)booleanadd(T t)Deprecated.since 2009-02-23.voidaddListener(ExtensionListListener listener)Add a listener to the extension list.static voidclearLegacyInstances()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)Tget(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 asExtensionComponents.TgetDynamic(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 ObjectgetLoadLock()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> UlookupFirst(Class<U> type)Convenience method allowing lookup of the instance of a given type with the highest ordinal.static <U> UlookupSingleton(Class<U> type)Convenience method allowing lookup of the only instance of a given type.voidrefresh(ExtensionComponentSet delta)Used duringJenkins.refreshExtensions()to add new components into existingExtensionLists.Tremove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)List<T>reverseView()Gets the read-only view of thisExtensionListwhere components are reversed.intsize()protected List<ExtensionComponent<T>>sort(List<ExtensionComponent<T>> r)If theExtensionListimplementation 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 asExtensionComponents.
-
get
public T get(int index)
-
size
public int size()
- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceList<T>- Specified by:
sizein classAbstractCollection<T>
-
reverseView
public List<T> reverseView()
Gets the read-only view of thisExtensionListwhere components are reversed.
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<T>- Specified by:
removein interfaceList<T>- Overrides:
removein classAbstractCollection<T>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<T>- Specified by:
removeAllin interfaceList<T>- Overrides:
removeAllin 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:
addin interfaceCollection<T>- Specified by:
addin interfaceList<T>- Overrides:
addin 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 existingExtensionLists. 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 theExtensionListimplementation 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 anIllegalStateExceptionotherwise.- 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
-
lookupFirst
@NonNull public static <U> U lookupFirst(Class<U> type)
Convenience method allowing lookup of the instance of a given type with the highest ordinal. Equivalent toExtensionList.lookup(type).get(0)if there is at least one instance, and throws anIllegalStateExceptionotherwise if no instance could be found.- 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- Since:
- 2.435
-
clearLegacyInstances
public static void clearLegacyInstances()
Exposed for the test harness to clear all legacy extension instances.
-
-