Top Description Fields Constructors Methods
org.apache.groovy.plugin

public Class GroovyRunnerRegistry

extends Object
implements Map<String, GroovyRunner>, Iterable<GroovyRunner>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable, java.util.Map
Imports
java.util.ArrayList, .Collection, .Collections, .Iterator, .LinkedHashMap, .LinkedHashSet, .List, .Map, .ServiceConfigurationError, .ServiceLoader, .Set, java.util.concurrent.locks.Lock, .ReadWriteLock, .ReentrantReadWriteLock, java.util.logging.Level, .Logger

Registry of services that implement the GroovyRunner interface.

This registry makes use of the ServiceLoader facility. The preferred method for registering new GroovyRunner providers is to place them in a provider-configuration file in the resource directory META-INF/services. The preferred method for accessing the registered runners is by making use of the Iterable interface using an enhanced for-loop.

For compatibility with previous versions, this registry implements the Map interface. All null keys and values will be ignored and no exception thrown, except where noted.

By default the registry contains runners that are capable of running JUnit 3 and JUnit 4 test classes if those libraries are available to the class loader.

Since
2.5.0

Field Summary

Modifier and TypeField and Description
private volatile List<GroovyRunner>
private static final GroovyRunnerRegistry
private static final Logger
private final Lock
private volatile Map<String, GroovyRunner>
private final ReadWriteLock
private final Lock

Constructor Summary

AccessConstructor and Description
pack-priv
GroovyRunnerRegistry(Map<? extends String, ? extends GroovyRunner> runners)

private

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements java.util.Map.clear.

Clears all registered runners from the registry and resets the registry so that it contains only the default set of runners.
public boolean

Returns:

true if a runner was registered with given key
containsKey
(Object
for the registered runner
key
)

Implements java.util.Map.containsKey.

Returns true if a runner was registered with the specified key.
public boolean

Returns:

true if the given runner is registered
containsValue
(Object
instance of a GroovyRunner
runner
)

Implements java.util.Map.containsValue.

Returns true if registry contains the given runner instance.
public Set<Map.Entry<String, GroovyRunner>>

Returns:

an unmodifiable set of registered runner entries
entrySet
()

Implements java.util.Map.entrySet.

Returns a set of entries for registered runners.
public GroovyRunner

Returns:

the runner registered with the given key
get
(Object
used to lookup the runner
key
)

Implements java.util.Map.get.

Returns the registered runner for the specified key.
public static GroovyRunnerRegistry

Returns:

registry instance
getInstance
()

Returns a reference to the one and only registry instance.

private Map<String, GroovyRunner>

Returns:

backing registry map
getMap
()

Lazily initialize and load the backing Map.

public boolean

Returns:

true if no runners are registered
isEmpty
()

Implements java.util.Map.isEmpty.

Returns true if the registry contains no runners, else false.
public Iterator<GroovyRunner>

Returns:

iterator for all registered runners
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator for all runners that are registered.
public Set<String>

Returns:

an unmodifiable set of keys for registered runners
keySet
()

Implements java.util.Map.keySet.

Set of all keys associated with registered runners.
public void
load(ClassLoader
used to locate provider-configuration files and classes
classLoader
)

Loads GroovyRunner instances using the ServiceLoader facility.

private void
private void
public GroovyRunner

Returns:

the previously registered runner for the given key, if no runner was previously registered for the key then null
put
(String
to associate with the runner
key
,
GroovyRunner
the runner to register
runner
)

Implements java.util.Map.put.

Registers a runner with the specified key.
public void
putAll(Map<? extends String, ? extends GroovyRunner>
entries to add to the registry
m
)

Implements java.util.Map.putAll.

Adds all entries from the given Map to the registry.
private void
register(GroovyRunner
the instance to add to the registry
runner
)

Registers the given instance with the registry.

public GroovyRunner

Returns:

the runner instance that was removed, if no runner instance was removed then null
remove
(Object
of the runner to remove
key
)

Implements java.util.Map.remove.

Removes a registered runner from the registry.
public int

Returns:

number of registered runners
size
()

Implements java.util.Map.size.

Returns the number of registered runners.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public Collection<GroovyRunner>

Returns:

an unmodifiable collection of registered runner instances
values
()

Implements java.util.Map.values.

Returns a collection of all registered runners.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cachedValuesback to summary
private volatile List<GroovyRunner> cachedValues
INSTANCEback to summary
private static final GroovyRunnerRegistry INSTANCE
LOGback to summary
private static final Logger LOG
readLockback to summary
private final Lock readLock
runnerMapback to summary
private volatile Map<String, GroovyRunner> runnerMap
rwLockback to summary
private final ReadWriteLock rwLock
writeLockback to summary
private final Lock writeLock

Constructor Detail

GroovyRunnerRegistryback to summary
pack-priv GroovyRunnerRegistry(Map<? extends String, ? extends GroovyRunner> runners)
GroovyRunnerRegistryback to summary
private GroovyRunnerRegistry()

Method Detail

clearback to summary
public void clear()

Implements java.util.Map.clear.

Clears all registered runners from the registry and resets the registry so that it contains only the default set of runners.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object key)

Implements java.util.Map.containsKey.

Returns true if a runner was registered with the specified key.

Parameters
key:Object

for the registered runner

Returns:boolean

true if a runner was registered with given key

Annotations
@Override
containsValueback to summary
public boolean containsValue(Object runner)

Implements java.util.Map.containsValue.

Returns true if registry contains the given runner instance.

Parameters
runner:Object

instance of a GroovyRunner

Returns:boolean

true if the given runner is registered

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<String, GroovyRunner>> entrySet()

Implements java.util.Map.entrySet.

Returns a set of entries for registered runners. This is a snapshot of the registry and any subsequent registry changes will not be reflected in the set.

Returns:Set<Map.Entry<String, GroovyRunner>>

an unmodifiable set of registered runner entries

Annotations
@Override
getback to summary
public GroovyRunner get(Object key)

Implements java.util.Map.get.

Returns the registered runner for the specified key.

Parameters
key:Object

used to lookup the runner

Returns:GroovyRunner

the runner registered with the given key

Annotations
@Override
getInstanceback to summary
public static GroovyRunnerRegistry getInstance()

Returns a reference to the one and only registry instance.

Returns:GroovyRunnerRegistry

registry instance

getMapback to summary
private Map<String, GroovyRunner> getMap()

Lazily initialize and load the backing Map. A LinkedHashMap is used to preserve insertion order.

Do not call while holding a read lock.

Returns:Map<String, GroovyRunner>

backing registry map

isEmptyback to summary
public boolean isEmpty()

Implements java.util.Map.isEmpty.

Returns true if the registry contains no runners, else false.

Returns:boolean

true if no runners are registered

Annotations
@Override
iteratorback to summary
public Iterator<GroovyRunner> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator for all runners that are registered. The returned iterator is a snapshot of the registry at the time the iterator is created. This iterator does not support removal.

Returns:Iterator<GroovyRunner>

iterator for all registered runners

Annotations
@Override
keySetback to summary
public Set<String> keySet()

Implements java.util.Map.keySet.

Set of all keys associated with registered runners. This is a snapshot of the registry and any subsequent registry changes will not be reflected in the set.

Returns:Set<String>

an unmodifiable set of keys for registered runners

Annotations
@Override
loadback to summary
public void load(ClassLoader classLoader)

Loads GroovyRunner instances using the ServiceLoader facility.

Parameters
classLoader:ClassLoader

used to locate provider-configuration files and classes

loadDefaultRunnersback to summary
private void loadDefaultRunners()
loadWithLockback to summary
private void loadWithLock(ClassLoader classLoader)
putback to summary
public GroovyRunner put(String key, GroovyRunner runner)

Implements java.util.Map.put.

Registers a runner with the specified key.

Parameters
key:String

to associate with the runner

runner:GroovyRunner

the runner to register

Returns:GroovyRunner

the previously registered runner for the given key, if no runner was previously registered for the key then null

Annotations
@Override
putAllback to summary
public void putAll(Map<? extends String, ? extends GroovyRunner> m)

Implements java.util.Map.putAll.

Adds all entries from the given Map to the registry. Any entries in the provided Map that contain a null key or value will be ignored.

Parameters
m:Map<? extends String, ? extends GroovyRunner>

entries to add to the registry

Annotations
@Override
Exceptions
NullPointerException:
if the given Map is null
registerback to summary
private void register(GroovyRunner runner)

Registers the given instance with the registry. This is equivalent to put(String, GroovyRunner) with a key being set to runner.getClass().getName().

Parameters
runner:GroovyRunner

the instance to add to the registry

removeback to summary
public GroovyRunner remove(Object key)

Implements java.util.Map.remove.

Removes a registered runner from the registry.

Parameters
key:Object

of the runner to remove

Returns:GroovyRunner

the runner instance that was removed, if no runner instance was removed then null

Annotations
@Override
sizeback to summary
public int size()

Implements java.util.Map.size.

Returns the number of registered runners.

Returns:int

number of registered runners

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
valuesback to summary
public Collection<GroovyRunner> values()

Implements java.util.Map.values.

Returns a collection of all registered runners. This is a snapshot of the registry and any subsequent registry changes will not be reflected in the collection.

Returns:Collection<GroovyRunner>

an unmodifiable collection of registered runner instances

Annotations
@Override