Class DynamicSet<T>
- java.lang.Object
-
- com.google.gerrit.extensions.registration.DynamicSet<T>
-
- All Implemented Interfaces:
Iterable<T>
public class DynamicSet<T> extends Object implements Iterable<T>
A set of members that can be modified as plugins reload.DynamicSets are always mapped as singletons in Guice. Sets store Providers internally, and resolve the provider to an instance on demand. This enables registrations to decide between singleton and non-singleton members.
-
-
Constructor Summary
Constructors Constructor Description DynamicSet()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ReloadableRegistrationHandle<T>
add(String pluginName, com.google.inject.Key<T> key, com.google.inject.Provider<T> item)
Add one new element that may be hot-replaceable in the future.RegistrationHandle
add(String pluginName, com.google.inject.Provider<T> item)
Add one new element to the set.RegistrationHandle
add(String pluginName, T item)
Add one new element to the set.static <T> com.google.inject.binder.LinkedBindingBuilder<T>
bind(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type)
Bind one implementation into the set using a unique annotation.static <T> com.google.inject.binder.LinkedBindingBuilder<T>
bind(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type, com.google.inject.name.Named name)
Bind a named implementation into the set.static <T> com.google.inject.binder.LinkedBindingBuilder<T>
bind(com.google.inject.Binder binder, Class<T> type)
Bind one implementation into the set using a unique annotation.static <T> com.google.inject.binder.LinkedBindingBuilder<T>
bind(com.google.inject.Binder binder, Class<T> type, com.google.inject.name.Named name)
Bind a named implementation into the set.com.google.common.collect.ImmutableSet<com.google.inject.Provider<T>>
byPlugin(String pluginName)
Get the items exported by a single plugin.boolean
contains(T item)
Returnstrue
if this set contains the given item.static <T> DynamicSet<T>
emptySet()
Iterable<Extension<T>>
entries()
Iterator<T>
iterator()
com.google.common.collect.ImmutableSortedSet<String>
plugins()
Get the names of all running plugins supplying this type.static <T> void
setOf(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> member)
Declare a singletonDynamicSet<T>
with a binder.static <T> void
setOf(com.google.inject.Binder binder, Class<T> member)
Declare a singletonDynamicSet<T>
with a binder.Stream<T>
stream()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
setOf
public static <T> void setOf(com.google.inject.Binder binder, Class<T> member)
Declare a singletonDynamicSet<T>
with a binder.Sets must be defined in a Guice module before they can be bound:
DynamicSet.setOf(binder(), Interface.class); DynamicSet.bind(binder(), Interface.class).to(Impl.class);
- Parameters:
binder
- a new binder created in the module.member
- type of entry in the set.
-
setOf
public static <T> void setOf(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> member)
Declare a singletonDynamicSet<T>
with a binder.Sets must be defined in a Guice module before they can be bound:
DynamicSet.setOf(binder(), new TypeLiteral<Thing<Foo>>() {});
- Parameters:
binder
- a new binder created in the module.member
- type of entry in the set.
-
bind
public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, Class<T> type)
Bind one implementation into the set using a unique annotation.- Parameters:
binder
- a new binder created in the module.type
- type of entries in the set.- Returns:
- a binder to continue configuring the new set member.
-
bind
public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type)
Bind one implementation into the set using a unique annotation.- Parameters:
binder
- a new binder created in the module.type
- type of entries in the set.- Returns:
- a binder to continue configuring the new set member.
-
bind
public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, Class<T> type, com.google.inject.name.Named name)
Bind a named implementation into the set.- Parameters:
binder
- a new binder created in the module.type
- type of entries in the set.name
-@Named
annotation to apply instead of a unique annotation.- Returns:
- a binder to continue configuring the new set member.
-
bind
public static <T> com.google.inject.binder.LinkedBindingBuilder<T> bind(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> type, com.google.inject.name.Named name)
Bind a named implementation into the set.- Parameters:
binder
- a new binder created in the module.type
- type of entries in the set.name
-@Named
annotation to apply instead of a unique annotation.- Returns:
- a binder to continue configuring the new set member.
-
emptySet
public static <T> DynamicSet<T> emptySet()
-
contains
public boolean contains(T item)
Returnstrue
if this set contains the given item.- Parameters:
item
- item to check whether or not it is contained.- Returns:
true
if this set contains the given item.
-
plugins
public com.google.common.collect.ImmutableSortedSet<String> plugins()
Get the names of all running plugins supplying this type.- Returns:
- sorted set of active plugins that supply at least one item.
-
byPlugin
public com.google.common.collect.ImmutableSet<com.google.inject.Provider<T>> byPlugin(String pluginName)
Get the items exported by a single plugin.- Parameters:
pluginName
- name of the plugin.- Returns:
- items exported by a plugin.
-
add
public RegistrationHandle add(String pluginName, T item)
Add one new element to the set.- Parameters:
item
- the item to add to the collection. Must not be null.- Returns:
- handle to remove the item at a later point in time.
-
add
public RegistrationHandle add(String pluginName, com.google.inject.Provider<T> item)
Add one new element to the set.- Parameters:
item
- the item to add to the collection. Must not be null.- Returns:
- handle to remove the item at a later point in time.
-
add
public ReloadableRegistrationHandle<T> add(String pluginName, com.google.inject.Key<T> key, com.google.inject.Provider<T> item)
Add one new element that may be hot-replaceable in the future.- Parameters:
pluginName
- unique name of the plugin providing the item.key
- unique description from the item's Guice binding. This can be later obtained from the registration handle to facilitate matching with the new equivalent instance during a hot reload.item
- the item to add to the collection right now. Must not be null.- Returns:
- a handle that can remove this item later, or hot-swap the item without it ever leaving the collection.
-
-