Package jenkins.slaves.iterators.api
Class NodeIterator<N extends Node>
- java.lang.Object
-
- jenkins.slaves.iterators.api.NodeIterator<N>
-
- All Implemented Interfaces:
ExtensionPoint
,Iterator<N>
public abstract class NodeIterator<N extends Node> extends Object implements Iterator<N>, ExtensionPoint
A class that iterates through all theNode
s in the system, even nodes which are not attached to the mainJenkins
object. If you are holding onto nodes that are not attached to the mainJenkins
object then you need to have anExtension
which extends this class and can iterate through yourNode
s.- Author:
- Stephen Connolly
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description NodeIterator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <N extends Node>
booleanhasCompleteLiveSet(Class<N> nodeClass)
Implementers ofNodeIterator
should override this method if they "lend"Node
instances to other JVMs and they require an on-line connection to those JVMs in order to iterate theNode
instances that have been "lent".static boolean
isComplete()
static <N extends Node>
booleanisComplete(Class<N> nodeClass)
Returnstrue
if and only ifiterator()
will iterate all live instances of the specified subtype ofNode
.static NodeIterator<Node>
iterator()
Returns a new iterator of all theNode
s in the system.static <N extends Node>
NodeIterator<N>iterator(Class<N> nodeClass)
Returns a new iterator of all theNode
s in the system.static Iterable<Node>
nodes()
Adapter to allow easy use from Java 5+ for loops.static <N extends Node>
Iterable<N>nodes(Class<N> nodeClass)
Adapter to allow easy use from Java 5+ for loops.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
-
-
-
Method Detail
-
iterator
@NonNull public static NodeIterator<Node> iterator()
Returns a new iterator of all theNode
s in the system.- Returns:
- a new iterator of all the
Node
s in the system.
-
nodes
@NonNull public static Iterable<Node> nodes()
Adapter to allow easy use from Java 5+ for loops.- Returns:
- an
Iterable
.
-
iterator
@NonNull public static <N extends Node> NodeIterator<N> iterator(@NonNull Class<N> nodeClass)
Returns a new iterator of all theNode
s in the system.
-
nodes
@NonNull public static <N extends Node> Iterable<N> nodes(@NonNull Class<N> nodeClass)
Adapter to allow easy use from Java 5+ for loops. If attempting to get all nodes usenodes()
-
isComplete
public static boolean isComplete()
Returnstrue
if and only ifiterator()
will iterate all live instances ofNode
. This is useful if you want to resolve any backing resources that do not have a correspondingNode
instance. If this method returnsfalse
then it will not be possible to definitively determine the complete live set and hence it will not be possible to definitively identify unused backing resources.- Returns:
true
if and only ifiterator()
will iterate all live instances ofNode
.- Since:
- 1.2
-
isComplete
public static <N extends Node> boolean isComplete(@NonNull Class<N> nodeClass)
Returnstrue
if and only ifiterator()
will iterate all live instances of the specified subtype ofNode
. This is useful if you want to resolve any backing resources that do not have a correspondingNode
instance. If this method returnsfalse
then it will not be possible to definitively determine the complete live set and hence it will not be possible to definitively identify unused backing resources.- Type Parameters:
N
- the class type of node- Parameters:
nodeClass
- the type ofNode
- Returns:
true
if and only ifiterator()
will iterate all live instances ofNode
.- Since:
- 1.2
-
hasCompleteLiveSet
protected <N extends Node> boolean hasCompleteLiveSet(@NonNull Class<N> nodeClass)
Implementers ofNodeIterator
should override this method if they "lend"Node
instances to other JVMs and they require an on-line connection to those JVMs in order to iterate theNode
instances that have been "lent". Where an implementer only "lends" a specific sub-type ofNode
it should returntrue
if the specified node type is not a sub-type of the type ofNode
that it leases. Implementers should only returnfalse
when the type ofNode
they "lend" is a sub-type of the specified type and at least one of their connections to remote JVMs is off-line in order to allow clients of theNodeIterator
API to identify unused backing resources.- Type Parameters:
N
- the sub-type ofNode
that is being queried.- Parameters:
nodeClass
- the sub-type ofNode
that is being queried.- Returns:
false
if and only if thisNodeIterator
cannot currently return the full set ofNode
instances of the specified type as a result of a transient loss of remote connectivity- Since:
- 1.2
-
-