Package hudson
Class ExtensionList<T>
java.lang.Object
java.util.AbstractCollection<T>
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
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 older DescriptorList-based
manual registration,
All ExtensionList instances should be owned by Jenkins, even though
extension points can be defined by anyone on any type. Use Jenkins.getExtensionList(Class)
and Jenkins.getDescriptorList(Class) to obtain the instances.
- Since:
- 1.286
- Author:
- Kohsuke Kawaguchi
- See Also:
-
Field Summary
FieldsFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExtensionList(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
Modifier and TypeMethodDescriptionvoidbooleanDeprecated.since 2009-02-23.voidaddListener(ExtensionListListener listener) Add a listener to the extension list.static voidExposed for the test harness to clear all legacy extension instances.static <T> ExtensionList<T> Deprecated.as of 1.416 Usecreate(Jenkins, Class)static <T> ExtensionList<T> voidget(int index) <U extends T>
ULooks for the extension instance of the given type (subclasses excluded), or return null.Gets the same thing as the 'this' list represents, except asExtensionComponents.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 ObjectChooses the object that locks the loading of the extension instances.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> 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.booleanrefresh(ExtensionComponentSet delta) Used duringJenkins.refreshExtensions()to add new components into existingExtensionLists.final Tremove(int index) booleanbooleanremoveAll(Collection<?> c) 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, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Field Details
-
hudson
Deprecated.as of 1.417 Usejenkins -
jenkins
-
extensionType
-
-
Constructor Details
-
ExtensionList
Deprecated.as of 1.416 UseExtensionList(Jenkins, Class) -
ExtensionList
-
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 Details
-
addListener
Add a listener to the extension list.- Parameters:
listener- The listener.
-
get
Looks for the extension instance of the given type (subclasses excluded), or return null. -
getInstance
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
-
iterator
-
getComponents
Gets the same thing as the 'this' list represents, except asExtensionComponents. -
get
-
size
public int size()- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceList<T>- Specified by:
sizein classAbstractCollection<T>
-
reverseView
Gets the read-only view of thisExtensionListwhere components are reversed. -
remove
- Specified by:
removein interfaceCollection<T>- Specified by:
removein interfaceList<T>- Overrides:
removein classAbstractCollection<T>
-
removeAll
- Specified by:
removeAllin interfaceCollection<T>- Specified by:
removeAllin interfaceList<T>- Overrides:
removeAllin classAbstractCollection<T>
-
remove
-
add
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
-
getDynamic
Used to bind extension to URLs by their class names.- Since:
- 1.349
-
getLoadLock
Chooses the object that locks the loading of the extension instances. -
refresh
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean refresh(ExtensionComponentSet delta) Used duringJenkins.refreshExtensions()to add new components into existingExtensionLists. Do not call from anywhere else.- Returns:
- true if
fireOnChangeListeners()should be called onthisafter all lists have been refreshed.
-
fireOnChangeListeners
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void fireOnChangeListeners() -
load
Loads all the extensions. -
load
Picks up extensions that we care from the given list. -
sort
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.as of 1.416 Usecreate(Jenkins, Class) -
create
-
lookup
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
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
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.
-
jenkins