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
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
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ModifierConstructorDescriptionprotected
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
Modifier and TypeMethodDescriptionvoid
boolean
Deprecated.since 2009-02-23.void
addListener
(ExtensionListListener listener) Add a listener to the extension list.static void
Exposed 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>
get
(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 asExtensionComponent
s.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
Chooses 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> U
lookupFirst
(Class<U> type) Convenience method allowing lookup of the instance of a given type with the highest ordinal.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.final T
remove
(int index) boolean
boolean
removeAll
(Collection<?> c) 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
-
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 asExtensionComponent
s. -
get
-
size
public int size()- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in classAbstractCollection<T>
-
reverseView
Gets the read-only view of thisExtensionList
where components are reversed. -
remove
- Specified by:
remove
in interfaceCollection<T>
- Specified by:
remove
in interfaceList<T>
- Overrides:
remove
in classAbstractCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
- Specified by:
removeAll
in interfaceList<T>
- Overrides:
removeAll
in classAbstractCollection<T>
-
remove
-
add
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
-
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
Used duringJenkins.refreshExtensions()
to add new components into existingExtensionList
s. Do not call from anywhere else. -
load
Loads all the extensions. -
load
Picks up extensions that we care from the given list. -
sort
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.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 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
-
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 anIllegalStateException
otherwise 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