Remove and ban ImmutableSet#copyOf

It was used heavily in the Guice we've embedded.
This commit is contained in:
Nik Everett 2015-09-23 15:37:49 -04:00
parent 6ecda41485
commit b0ab02e35c
26 changed files with 250 additions and 150 deletions

View File

@ -20,7 +20,6 @@
package org.elasticsearch.cluster.block; package org.elasticsearch.cluster.block;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.AbstractDiffable;
import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData;
@ -152,7 +151,7 @@ public class ClusterBlocks extends AbstractDiffable<ClusterBlocks> {
if (global(level).isEmpty()) { if (global(level).isEmpty()) {
return null; return null;
} }
return new ClusterBlockException(ImmutableSet.copyOf(global(level))); return new ClusterBlockException(global(level));
} }
public void indexBlockedRaiseException(ClusterBlockLevel level, String index) throws ClusterBlockException { public void indexBlockedRaiseException(ClusterBlockLevel level, String index) throws ClusterBlockException {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.cluster.routing.allocation; package org.elasticsearch.cluster.routing.allocation;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.cluster.ClusterInfo; import org.elasticsearch.cluster.ClusterInfo;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.node.DiscoveryNodes;
@ -34,6 +33,9 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
/** /**
* The {@link RoutingAllocation} keep the state of the current allocation * The {@link RoutingAllocation} keep the state of the current allocation
* of shards and holds the {@link AllocationDeciders} which are responsible * of shards and holds the {@link AllocationDeciders} which are responsible
@ -220,13 +222,13 @@ public class RoutingAllocation {
public Set<String> getIgnoreNodes(ShardId shardId) { public Set<String> getIgnoreNodes(ShardId shardId) {
if (ignoredShardToNodes == null) { if (ignoredShardToNodes == null) {
return ImmutableSet.of(); return emptySet();
} }
Set<String> ignore = ignoredShardToNodes.get(shardId); Set<String> ignore = ignoredShardToNodes.get(shardId);
if (ignore == null) { if (ignore == null) {
return ImmutableSet.of(); return emptySet();
} }
return ImmutableSet.copyOf(ignore); return unmodifiableSet(new HashSet<>(ignore));
} }
/** /**

View File

@ -16,12 +16,15 @@
package org.elasticsearch.common.inject; package org.elasticsearch.common.inject;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.internal.Errors; import org.elasticsearch.common.inject.internal.Errors;
import org.elasticsearch.common.inject.spi.Message; import org.elasticsearch.common.inject.spi.Message;
import java.util.Collection; import java.util.Collection;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
/** /**
* Thrown when a programming error such as a misplaced annotation, illegal binding, or unsupported * Thrown when a programming error such as a misplaced annotation, illegal binding, or unsupported
@ -31,15 +34,14 @@ import java.util.Locale;
* @since 2.0 * @since 2.0
*/ */
public final class ConfigurationException extends RuntimeException { public final class ConfigurationException extends RuntimeException {
private final Set<Message> messages;
private final ImmutableSet<Message> messages;
private Object partialValue = null; private Object partialValue = null;
/** /**
* Creates a ConfigurationException containing {@code messages}. * Creates a ConfigurationException containing {@code messages}.
*/ */
public ConfigurationException(Iterable<Message> messages) { public ConfigurationException(Iterable<Message> messages) {
this.messages = ImmutableSet.copyOf(messages); this.messages = unmodifiableSet(newHashSet(messages));
initCause(Errors.getOnlyCause(this.messages)); initCause(Errors.getOnlyCause(this.messages));
} }

View File

@ -16,7 +16,6 @@
package org.elasticsearch.common.inject; package org.elasticsearch.common.inject;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.internal.Errors; import org.elasticsearch.common.inject.internal.Errors;
import org.elasticsearch.common.inject.spi.Message; import org.elasticsearch.common.inject.spi.Message;
@ -29,14 +28,13 @@ import java.util.Collection;
* @author crazybob@google.com (Bob Lee) * @author crazybob@google.com (Bob Lee)
*/ */
public class CreationException extends RuntimeException { public class CreationException extends RuntimeException {
private final Collection<Message> messages;
private final ImmutableSet<Message> messages;
/** /**
* Creates a CreationException containing {@code messages}. * Creates a CreationException containing {@code messages}.
*/ */
public CreationException(Collection<Message> messages) { public CreationException(Collection<Message> messages) {
this.messages = ImmutableSet.copyOf(messages); this.messages = messages;
if (this.messages.isEmpty()) { if (this.messages.isEmpty()) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View File

@ -16,15 +16,15 @@
package org.elasticsearch.common.inject; package org.elasticsearch.common.inject;
import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.internal.BindingImpl;
import org.elasticsearch.common.inject.internal.*; import org.elasticsearch.common.inject.internal.Errors;
import org.elasticsearch.common.inject.internal.ErrorsException;
import org.elasticsearch.common.inject.internal.InternalContext;
import org.elasticsearch.common.inject.internal.Stopwatch;
import org.elasticsearch.common.inject.spi.Dependency; import org.elasticsearch.common.inject.spi.Dependency;
import org.elasticsearch.common.util.iterable.Iterables;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* Builds a tree of injectors. This is a primary injector, plus child injectors needed for each * Builds a tree of injectors. This is a primary injector, plus child injectors needed for each
@ -182,12 +182,16 @@ class InjectorBuilder {
* Loads eager singletons, or all singletons if we're in Stage.PRODUCTION. Bindings discovered * Loads eager singletons, or all singletons if we're in Stage.PRODUCTION. Bindings discovered
* while we're binding these singletons are not be eager. * while we're binding these singletons are not be eager.
*/ */
public void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors) { public void loadEagerSingletons(InjectorImpl injector, Stage stage, Errors errors) {
@SuppressWarnings("unchecked") // casting Collection<Binding> to Collection<BindingImpl> is safe for (final Binding<?> binding : injector.state.getExplicitBindingsThisLevel().values()) {
Set<BindingImpl<?>> candidateBindings = ImmutableSet.copyOf(Iterables.concat( loadEagerSingletons(injector, stage, errors, (BindingImpl<?>)binding);
(Collection) injector.state.getExplicitBindingsThisLevel().values(), }
injector.jitBindings.values())); for (final Binding<?> binding : injector.jitBindings.values()) {
for (final BindingImpl<?> binding : candidateBindings) { loadEagerSingletons(injector, stage, errors, (BindingImpl<?>)binding);
}
}
private void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors, BindingImpl<?> binding) {
if (binding.getScoping().isEagerSingleton(stage)) { if (binding.getScoping().isEagerSingleton(stage)) {
try { try {
injector.callInContext(new ContextualCallable<Void>() { injector.callInContext(new ContextualCallable<Void>() {
@ -213,7 +217,6 @@ class InjectorBuilder {
} }
} }
} }
}
/** /**
* {@link Injector} exposed to users in {@link Stage#TOOL}. * {@link Injector} exposed to users in {@link Stage#TOOL}.

View File

@ -25,6 +25,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Logger; import java.util.logging.Logger;
import static java.util.Collections.emptySet;
import static org.elasticsearch.common.inject.Scopes.SINGLETON; import static org.elasticsearch.common.inject.Scopes.SINGLETON;
/** /**
@ -185,7 +186,7 @@ class InjectorShell {
injector.state.putBinding(key, injector.state.putBinding(key,
new ProviderInstanceBindingImpl<>(injector, key, SourceProvider.UNKNOWN_SOURCE, new ProviderInstanceBindingImpl<>(injector, key, SourceProvider.UNKNOWN_SOURCE,
injectorFactory, Scoping.UNSCOPED, injectorFactory, injectorFactory, Scoping.UNSCOPED, injectorFactory,
ImmutableSet.<InjectionPoint>of())); emptySet()));
} }
private static class InjectorFactory implements InternalFactory<Injector>, Provider<Injector> { private static class InjectorFactory implements InternalFactory<Injector>, Provider<Injector> {
@ -222,7 +223,7 @@ class InjectorShell {
injector.state.putBinding(key, injector.state.putBinding(key,
new ProviderInstanceBindingImpl<>(injector, key, new ProviderInstanceBindingImpl<>(injector, key,
SourceProvider.UNKNOWN_SOURCE, loggerFactory, Scoping.UNSCOPED, SourceProvider.UNKNOWN_SOURCE, loggerFactory, Scoping.UNSCOPED,
loggerFactory, ImmutableSet.<InjectionPoint>of())); loggerFactory, emptySet()));
} }
private static class LoggerFactory implements InternalFactory<Logger>, Provider<Logger> { private static class LoggerFactory implements InternalFactory<Logger>, Provider<Logger> {

View File

@ -16,12 +16,16 @@
package org.elasticsearch.common.inject; package org.elasticsearch.common.inject;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.internal.Errors; import org.elasticsearch.common.inject.internal.Errors;
import org.elasticsearch.common.inject.spi.Message; import org.elasticsearch.common.inject.spi.Message;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Set;
import static java.util.Collections.singleton;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
/** /**
* Indicates that there was a runtime failure while providing an instance. * Indicates that there was a runtime failure while providing an instance.
@ -31,14 +35,13 @@ import java.util.Collections;
* @since 2.0 * @since 2.0
*/ */
public final class ProvisionException extends RuntimeException { public final class ProvisionException extends RuntimeException {
private final Set<Message> messages;
private final ImmutableSet<Message> messages;
/** /**
* Creates a ConfigurationException containing {@code messages}. * Creates a ConfigurationException containing {@code messages}.
*/ */
public ProvisionException(Iterable<Message> messages) { public ProvisionException(Iterable<Message> messages) {
this.messages = ImmutableSet.copyOf(messages); this.messages = unmodifiableSet(newHashSet(messages));
if (this.messages.isEmpty()) { if (this.messages.isEmpty()) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@ -47,11 +50,11 @@ public final class ProvisionException extends RuntimeException {
public ProvisionException(String message, Throwable cause) { public ProvisionException(String message, Throwable cause) {
super(cause); super(cause);
this.messages = ImmutableSet.of(new Message(Collections.emptyList(), message, cause)); this.messages = singleton(new Message(Collections.emptyList(), message, cause));
} }
public ProvisionException(String message) { public ProvisionException(String message) {
this.messages = ImmutableSet.of(new Message(message)); this.messages = singleton(new Message(message));
} }
/** /**

View File

@ -18,6 +18,7 @@ package org.elasticsearch.common.inject.assistedinject;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.ConfigurationException;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
@ -37,10 +38,13 @@ import java.lang.reflect.Proxy;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static java.util.Collections.unmodifiableSet;
/** /**
* Provides a factory that combines the caller's arguments with injector-supplied values to * Provides a factory that combines the caller's arguments with injector-supplied values to
* construct objects. * construct objects.
@ -279,7 +283,7 @@ public class FactoryProvider<F> implements Provider<F>, HasDependencies {
@Override @Override
public Set<Dependency<?>> getDependencies() { public Set<Dependency<?>> getDependencies() {
List<Dependency<?>> dependencies = new ArrayList<>(); Set<Dependency<?>> dependencies = new HashSet<>();
for (AssistedConstructor<?> constructor : factoryMethodToConstructor.values()) { for (AssistedConstructor<?> constructor : factoryMethodToConstructor.values()) {
for (Parameter parameter : constructor.getAllParameters()) { for (Parameter parameter : constructor.getAllParameters()) {
if (!parameter.isProvidedByFactory()) { if (!parameter.isProvidedByFactory()) {
@ -287,7 +291,7 @@ public class FactoryProvider<F> implements Provider<F>, HasDependencies {
} }
} }
} }
return ImmutableSet.copyOf(dependencies); return unmodifiableSet(dependencies);
} }
@Override @Override

View File

@ -16,18 +16,25 @@
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.*; import org.elasticsearch.common.inject.ConfigurationException;
import org.elasticsearch.common.inject.Key;
import org.elasticsearch.common.inject.Provider;
import org.elasticsearch.common.inject.TypeLiteral;
import org.elasticsearch.common.inject.binder.AnnotatedBindingBuilder; import org.elasticsearch.common.inject.binder.AnnotatedBindingBuilder;
import org.elasticsearch.common.inject.spi.Element; import org.elasticsearch.common.inject.spi.Element;
import org.elasticsearch.common.inject.spi.InjectionPoint; import org.elasticsearch.common.inject.spi.InjectionPoint;
import org.elasticsearch.common.inject.spi.Message; import org.elasticsearch.common.inject.spi.Message;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
/** /**
* Bind a non-constant key. * Bind a non-constant key.
* *
@ -85,11 +92,11 @@ public class BindingBuilder<T> extends AbstractBindingBuilder<T>
for (Message message : e.getErrorMessages()) { for (Message message : e.getErrorMessages()) {
binder.addError(message); binder.addError(message);
} }
injectionPoints = e.getPartialValue(); injectionPoints = unmodifiableSet(new HashSet<>(e.getPartialValue()));
} }
} else { } else {
binder.addError(BINDING_TO_NULL); binder.addError(BINDING_TO_NULL);
injectionPoints = ImmutableSet.of(); injectionPoints = emptySet();
} }
BindingImpl<T> base = getBinding(); BindingImpl<T> base = getBinding();
@ -110,7 +117,7 @@ public class BindingBuilder<T> extends AbstractBindingBuilder<T>
for (Message message : e.getErrorMessages()) { for (Message message : e.getErrorMessages()) {
binder.addError(message); binder.addError(message);
} }
injectionPoints = e.getPartialValue(); injectionPoints = unmodifiableSet(new HashSet<>(e.getPartialValue()));
} }
BindingImpl<T> base = getBinding(); BindingImpl<T> base = getBinding();

View File

@ -16,17 +16,17 @@
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Key; import org.elasticsearch.common.inject.Key;
import org.elasticsearch.common.inject.binder.AnnotatedConstantBindingBuilder; import org.elasticsearch.common.inject.binder.AnnotatedConstantBindingBuilder;
import org.elasticsearch.common.inject.binder.ConstantBindingBuilder; import org.elasticsearch.common.inject.binder.ConstantBindingBuilder;
import org.elasticsearch.common.inject.spi.Element; import org.elasticsearch.common.inject.spi.Element;
import org.elasticsearch.common.inject.spi.InjectionPoint;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.List; import java.util.List;
import static java.util.Collections.emptySet;
/** /**
* Bind a constant. * Bind a constant.
* *
@ -130,7 +130,7 @@ public final class ConstantBindingBuilderImpl<T>
} }
setBinding(new InstanceBindingImpl<>( setBinding(new InstanceBindingImpl<>(
base.getSource(), key, base.getScoping(), ImmutableSet.<InjectionPoint>of(), instanceAsT)); base.getSource(), key, base.getScoping(), emptySet(), instanceAsT));
} }
@Override @Override

View File

@ -17,6 +17,7 @@
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.CollectionUtil;
import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.ConfigurationException;
import org.elasticsearch.common.inject.CreationException; import org.elasticsearch.common.inject.CreationException;
@ -49,6 +50,8 @@ import java.util.Formatter;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import static java.util.Collections.unmodifiableList;
/** /**
* A collection of error messages. If this type is passed as a method parameter, the method is * A collection of error messages. If this type is passed as a method parameter, the method is
* considered to have executed successfully only if new errors were not added to this collection. * considered to have executed successfully only if new errors were not added to this collection.
@ -463,7 +466,7 @@ public final class Errors implements Serializable {
} }
}); });
return result; return unmodifiableList(result);
} }
/** /**

View File

@ -16,27 +16,33 @@
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Key; import org.elasticsearch.common.inject.Key;
import org.elasticsearch.common.inject.Provider; import org.elasticsearch.common.inject.Provider;
import org.elasticsearch.common.inject.spi.*; import org.elasticsearch.common.inject.spi.BindingTargetVisitor;
import org.elasticsearch.common.inject.spi.Dependency;
import org.elasticsearch.common.inject.spi.HasDependencies;
import org.elasticsearch.common.inject.spi.InjectionPoint;
import org.elasticsearch.common.inject.spi.InstanceBinding;
import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.inject.util.Providers;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static java.util.Collections.unmodifiableSet;
public class InstanceBindingImpl<T> extends BindingImpl<T> implements InstanceBinding<T> { public class InstanceBindingImpl<T> extends BindingImpl<T> implements InstanceBinding<T> {
final T instance; final T instance;
final Provider<T> provider; final Provider<T> provider;
final ImmutableSet<InjectionPoint> injectionPoints; final Set<InjectionPoint> injectionPoints;
public InstanceBindingImpl(Injector injector, Key<T> key, Object source, public InstanceBindingImpl(Injector injector, Key<T> key, Object source,
InternalFactory<? extends T> internalFactory, Set<InjectionPoint> injectionPoints, InternalFactory<? extends T> internalFactory, Set<InjectionPoint> injectionPoints,
T instance) { T instance) {
super(injector, key, source, internalFactory, Scoping.UNSCOPED); super(injector, key, source, internalFactory, Scoping.UNSCOPED);
this.injectionPoints = ImmutableSet.copyOf(injectionPoints); this.injectionPoints = injectionPoints;
this.instance = instance; this.instance = instance;
this.provider = Providers.of(instance); this.provider = Providers.of(instance);
} }
@ -44,7 +50,7 @@ public class InstanceBindingImpl<T> extends BindingImpl<T> implements InstanceBi
public InstanceBindingImpl(Object source, Key<T> key, Scoping scoping, public InstanceBindingImpl(Object source, Key<T> key, Scoping scoping,
Set<InjectionPoint> injectionPoints, T instance) { Set<InjectionPoint> injectionPoints, T instance) {
super(source, key, scoping); super(source, key, scoping);
this.injectionPoints = ImmutableSet.copyOf(injectionPoints); this.injectionPoints = injectionPoints;
this.instance = instance; this.instance = instance;
this.provider = Providers.of(instance); this.provider = Providers.of(instance);
} }
@ -72,7 +78,7 @@ public class InstanceBindingImpl<T> extends BindingImpl<T> implements InstanceBi
@Override @Override
public Set<Dependency<?>> getDependencies() { public Set<Dependency<?>> getDependencies() {
return instance instanceof HasDependencies return instance instanceof HasDependencies
? ImmutableSet.copyOf(((HasDependencies) instance).getDependencies()) ? unmodifiableSet(new HashSet<>((((HasDependencies) instance).getDependencies())))
: Dependency.forInjectionPoints(injectionPoints); : Dependency.forInjectionPoints(injectionPoints);
} }

View File

@ -16,20 +16,26 @@ limitations under the License.
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Key; import org.elasticsearch.common.inject.Key;
import org.elasticsearch.common.inject.Provider; import org.elasticsearch.common.inject.Provider;
import org.elasticsearch.common.inject.spi.*; import org.elasticsearch.common.inject.spi.BindingTargetVisitor;
import org.elasticsearch.common.inject.spi.Dependency;
import org.elasticsearch.common.inject.spi.HasDependencies;
import org.elasticsearch.common.inject.spi.InjectionPoint;
import org.elasticsearch.common.inject.spi.ProviderInstanceBinding;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static java.util.Collections.unmodifiableSet;
public final class ProviderInstanceBindingImpl<T> extends BindingImpl<T> public final class ProviderInstanceBindingImpl<T> extends BindingImpl<T>
implements ProviderInstanceBinding<T> { implements ProviderInstanceBinding<T> {
final Provider<? extends T> providerInstance; final Provider<? extends T> providerInstance;
final ImmutableSet<InjectionPoint> injectionPoints; final Set<InjectionPoint> injectionPoints;
public ProviderInstanceBindingImpl(Injector injector, Key<T> key, public ProviderInstanceBindingImpl(Injector injector, Key<T> key,
Object source, InternalFactory<? extends T> internalFactory, Scoping scoping, Object source, InternalFactory<? extends T> internalFactory, Scoping scoping,
@ -37,13 +43,13 @@ public final class ProviderInstanceBindingImpl<T> extends BindingImpl<T>
Set<InjectionPoint> injectionPoints) { Set<InjectionPoint> injectionPoints) {
super(injector, key, source, internalFactory, scoping); super(injector, key, source, internalFactory, scoping);
this.providerInstance = providerInstance; this.providerInstance = providerInstance;
this.injectionPoints = ImmutableSet.copyOf(injectionPoints); this.injectionPoints = injectionPoints;
} }
public ProviderInstanceBindingImpl(Object source, Key<T> key, Scoping scoping, public ProviderInstanceBindingImpl(Object source, Key<T> key, Scoping scoping,
Set<InjectionPoint> injectionPoints, Provider<? extends T> providerInstance) { Set<InjectionPoint> injectionPoints, Provider<? extends T> providerInstance) {
super(source, key, scoping); super(source, key, scoping);
this.injectionPoints = ImmutableSet.copyOf(injectionPoints); this.injectionPoints = injectionPoints;
this.providerInstance = providerInstance; this.providerInstance = providerInstance;
} }
@ -65,7 +71,7 @@ public final class ProviderInstanceBindingImpl<T> extends BindingImpl<T>
@Override @Override
public Set<Dependency<?>> getDependencies() { public Set<Dependency<?>> getDependencies() {
return providerInstance instanceof HasDependencies return providerInstance instanceof HasDependencies
? ImmutableSet.copyOf(((HasDependencies) providerInstance).getDependencies()) ? unmodifiableSet(new HashSet<>((((HasDependencies) providerInstance).getDependencies())))
: Dependency.forInjectionPoints(injectionPoints); : Dependency.forInjectionPoints(injectionPoints);
} }

View File

@ -16,8 +16,11 @@
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.*; import org.elasticsearch.common.inject.Exposed;
import org.elasticsearch.common.inject.Key;
import org.elasticsearch.common.inject.PrivateBinder;
import org.elasticsearch.common.inject.Provider;
import org.elasticsearch.common.inject.spi.Dependency; import org.elasticsearch.common.inject.spi.Dependency;
import org.elasticsearch.common.inject.spi.ProviderWithDependencies; import org.elasticsearch.common.inject.spi.ProviderWithDependencies;
@ -37,7 +40,7 @@ public class ProviderMethod<T> implements ProviderWithDependencies<T> {
private final Class<? extends Annotation> scopeAnnotation; private final Class<? extends Annotation> scopeAnnotation;
private final Object instance; private final Object instance;
private final Method method; private final Method method;
private final ImmutableSet<Dependency<?>> dependencies; private final Set<Dependency<?>> dependencies;
private final List<Provider<?>> parameterProviders; private final List<Provider<?>> parameterProviders;
private final boolean exposed; private final boolean exposed;
@ -45,7 +48,7 @@ public class ProviderMethod<T> implements ProviderWithDependencies<T> {
* @param method the method to invoke. Its return type must be the same type as {@code key}. * @param method the method to invoke. Its return type must be the same type as {@code key}.
*/ */
ProviderMethod(Key<T> key, Method method, Object instance, ProviderMethod(Key<T> key, Method method, Object instance,
ImmutableSet<Dependency<?>> dependencies, List<Provider<?>> parameterProviders, Set<Dependency<?>> dependencies, List<Provider<?>> parameterProviders,
Class<? extends Annotation> scopeAnnotation) { Class<? extends Annotation> scopeAnnotation) {
this.key = key; this.key = key;
this.scopeAnnotation = scopeAnnotation; this.scopeAnnotation = scopeAnnotation;

View File

@ -16,7 +16,6 @@
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Key; import org.elasticsearch.common.inject.Key;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
@ -31,8 +30,12 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import static java.util.Collections.unmodifiableSet;
/** /**
* Creates bindings to methods annotated with {@literal @}{@link Provides}. Use the scope and * Creates bindings to methods annotated with {@literal @}{@link Provides}. Use the scope and
@ -94,7 +97,7 @@ public final class ProviderMethodsModule implements Module {
Errors errors = new Errors(method); Errors errors = new Errors(method);
// prepare the parameter providers // prepare the parameter providers
List<Dependency<?>> dependencies = new ArrayList<>(); Set<Dependency<?>> dependencies = new HashSet<>();
List<Provider<?>> parameterProviders = new ArrayList<>(); List<Provider<?>> parameterProviders = new ArrayList<>();
List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method); List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method);
Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Annotation[][] parameterAnnotations = method.getParameterAnnotations();
@ -115,7 +118,7 @@ public final class ProviderMethodsModule implements Module {
binder.addError(message); binder.addError(message);
} }
return new ProviderMethod<>(key, method, delegate, ImmutableSet.copyOf(dependencies), return new ProviderMethod<>(key, method, delegate, unmodifiableSet(dependencies),
parameterProviders, scopeAnnotation); parameterProviders, scopeAnnotation);
} }

View File

@ -16,11 +16,11 @@
package org.elasticsearch.common.inject.internal; package org.elasticsearch.common.inject.internal;
import com.google.common.collect.ImmutableSet; import java.util.HashSet;
import org.elasticsearch.common.util.iterable.Iterables; import java.util.Set;
import java.util.ArrayList; import static java.util.Collections.singleton;
import java.util.List; import static java.util.Collections.unmodifiableSet;
/** /**
* Provides access to the calling line of code. * Provides access to the calling line of code.
@ -34,35 +34,29 @@ public class SourceProvider {
*/ */
public static final Object UNKNOWN_SOURCE = "[unknown source]"; public static final Object UNKNOWN_SOURCE = "[unknown source]";
private final ImmutableSet<String> classNamesToSkip; private final Set<String> classNamesToSkip;
public SourceProvider() { public SourceProvider() {
this.classNamesToSkip = ImmutableSet.of(SourceProvider.class.getName()); this.classNamesToSkip = singleton(SourceProvider.class.getName());
} }
public static final SourceProvider DEFAULT_INSTANCE public static final SourceProvider DEFAULT_INSTANCE = new SourceProvider();
= new SourceProvider(ImmutableSet.of(SourceProvider.class.getName()));
private SourceProvider(Iterable<String> classesToSkip) { @SuppressWarnings("rawtypes")
this.classNamesToSkip = ImmutableSet.copyOf(classesToSkip); private SourceProvider(SourceProvider copy, Class[] moreClassesToSkip) {
Set<String> classNamesToSkip = new HashSet<>(copy.classNamesToSkip);
for (Class toSkip : moreClassesToSkip) {
classNamesToSkip.add(toSkip.getName());
}
this.classNamesToSkip = unmodifiableSet(classNamesToSkip);
} }
/** /**
* Returns a new instance that also skips {@code moreClassesToSkip}. * Returns a new instance that also skips {@code moreClassesToSkip}.
*/ */
@SuppressWarnings("rawtypes")
public SourceProvider plusSkippedClasses(Class... moreClassesToSkip) { public SourceProvider plusSkippedClasses(Class... moreClassesToSkip) {
return new SourceProvider(Iterables.concat(classNamesToSkip, asStrings(moreClassesToSkip))); return new SourceProvider(this, moreClassesToSkip);
}
/**
* Returns the class names as Strings
*/
private static List<String> asStrings(Class... classes) {
List<String> strings = new ArrayList<>();
for (Class c : classes) {
strings.add(c.getName());
}
return strings;
} }
/** /**

View File

@ -17,6 +17,7 @@
package org.elasticsearch.common.inject.multibindings; package org.elasticsearch.common.inject.multibindings;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Binding; import org.elasticsearch.common.inject.Binding;
import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.ConfigurationException;
@ -37,11 +38,14 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import static java.util.Collections.unmodifiableSet;
/** /**
* An API to bind multiple values separately, only to later inject them as a * An API to bind multiple values separately, only to later inject them as a
* complete collection. Multibinder is intended for use in your application's * complete collection. Multibinder is intended for use in your application's
@ -238,9 +242,8 @@ public abstract class Multibinder<T> {
@Inject @Inject
public void initialize(Injector injector) { public void initialize(Injector injector) {
providers = new ArrayList<>(); providers = new ArrayList<>();
List<Dependency<?>> dependencies = new ArrayList<>(); Set<Dependency<?>> dependencies = new HashSet<>();
for (Binding<?> entry : injector.findBindingsByType(elementType)) { for (Binding<?> entry : injector.findBindingsByType(elementType)) {
if (keyMatches(entry.getKey())) { if (keyMatches(entry.getKey())) {
@SuppressWarnings("unchecked") // protected by findBindingsByType() @SuppressWarnings("unchecked") // protected by findBindingsByType()
Binding<T> binding = (Binding<T>) entry; Binding<T> binding = (Binding<T>) entry;
@ -249,7 +252,7 @@ public abstract class Multibinder<T> {
} }
} }
this.dependencies = ImmutableSet.copyOf(dependencies); this.dependencies = unmodifiableSet(dependencies);
this.binder = null; this.binder = null;
} }

View File

@ -16,14 +16,14 @@
package org.elasticsearch.common.inject.spi; package org.elasticsearch.common.inject.spi;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Key; import org.elasticsearch.common.inject.Key;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.util.set.Sets.toFlatSet;
/** /**
* A variable that can be resolved by an injector. * A variable that can be resolved by an injector.
* <p> * <p>
@ -60,11 +60,8 @@ public final class Dependency<T> {
* Returns the dependencies from the given injection points. * Returns the dependencies from the given injection points.
*/ */
public static Set<Dependency<?>> forInjectionPoints(Set<InjectionPoint> injectionPoints) { public static Set<Dependency<?>> forInjectionPoints(Set<InjectionPoint> injectionPoints) {
List<Dependency<?>> dependencies = new ArrayList<>(); return unmodifiableSet(
for (InjectionPoint injectionPoint : injectionPoints) { injectionPoints.stream().map(InjectionPoint::getDependencies).collect(toFlatSet()));
dependencies.addAll(injectionPoint.getDependencies());
}
return ImmutableSet.copyOf(dependencies);
} }
/** /**

View File

@ -17,6 +17,7 @@
package org.elasticsearch.common.inject.spi; package org.elasticsearch.common.inject.spi;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.ConfigurationException; import org.elasticsearch.common.inject.ConfigurationException;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Key; import org.elasticsearch.common.inject.Key;
@ -38,10 +39,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.inject.internal.MoreTypes.getRawType; import static org.elasticsearch.common.inject.internal.MoreTypes.getRawType;
/** /**
@ -253,13 +256,13 @@ public final class InjectionPoint {
* of the valid injection points. * of the valid injection points.
*/ */
public static Set<InjectionPoint> forStaticMethodsAndFields(TypeLiteral type) { public static Set<InjectionPoint> forStaticMethodsAndFields(TypeLiteral type) {
List<InjectionPoint> sink = new ArrayList<>(); Set<InjectionPoint> result = new HashSet<>();
Errors errors = new Errors(); Errors errors = new Errors();
addInjectionPoints(type, Factory.FIELDS, true, sink, errors); addInjectionPoints(type, Factory.FIELDS, true, result, errors);
addInjectionPoints(type, Factory.METHODS, true, sink, errors); addInjectionPoints(type, Factory.METHODS, true, result, errors);
ImmutableSet<InjectionPoint> result = ImmutableSet.copyOf(sink); result = unmodifiableSet(result);
if (errors.hasErrors()) { if (errors.hasErrors()) {
throw new ConfigurationException(errors.getMessages()).withPartialValue(result); throw new ConfigurationException(errors.getMessages()).withPartialValue(result);
} }
@ -293,14 +296,14 @@ public final class InjectionPoint {
* of the valid injection points. * of the valid injection points.
*/ */
public static Set<InjectionPoint> forInstanceMethodsAndFields(TypeLiteral<?> type) { public static Set<InjectionPoint> forInstanceMethodsAndFields(TypeLiteral<?> type) {
List<InjectionPoint> sink = new ArrayList<>(); Set<InjectionPoint> result = new HashSet<>();
Errors errors = new Errors(); Errors errors = new Errors();
// TODO (crazybob): Filter out overridden members. // TODO (crazybob): Filter out overridden members.
addInjectionPoints(type, Factory.FIELDS, false, sink, errors); addInjectionPoints(type, Factory.FIELDS, false, result, errors);
addInjectionPoints(type, Factory.METHODS, false, sink, errors); addInjectionPoints(type, Factory.METHODS, false, result, errors);
ImmutableSet<InjectionPoint> result = ImmutableSet.copyOf(sink); result = unmodifiableSet(result);
if (errors.hasErrors()) { if (errors.hasErrors()) {
throw new ConfigurationException(errors.getMessages()).withPartialValue(result); throw new ConfigurationException(errors.getMessages()).withPartialValue(result);
} }

View File

@ -16,7 +16,6 @@
package org.elasticsearch.common.inject.util; package org.elasticsearch.common.inject.util;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Binding; import org.elasticsearch.common.inject.Binding;
@ -40,6 +39,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
/** /**
* Static utility methods for creating and working with instances of {@link Module}. * Static utility methods for creating and working with instances of {@link Module}.
* *
@ -94,15 +96,14 @@ public final class Modules {
* Returns a new module that installs all of {@code modules}. * Returns a new module that installs all of {@code modules}.
*/ */
public static Module combine(Module... modules) { public static Module combine(Module... modules) {
return combine(ImmutableSet.copyOf(modules)); return combine(Arrays.asList(modules));
} }
/** /**
* Returns a new module that installs all of {@code modules}. * Returns a new module that installs all of {@code modules}.
*/ */
public static Module combine(Iterable<? extends Module> modules) { public static Module combine(Iterable<? extends Module> modules) {
// TODO: infer type once JI-9019884 is fixed final Set<? extends Module> modulesSet = newHashSet(modules);
final Set<Module> modulesSet = ImmutableSet.<Module>copyOf(modules);
return new Module() { return new Module() {
@Override @Override
public void configure(Binder binder) { public void configure(Binder binder) {
@ -131,11 +132,10 @@ public final class Modules {
} }
private static final class RealOverriddenModuleBuilder implements OverriddenModuleBuilder { private static final class RealOverriddenModuleBuilder implements OverriddenModuleBuilder {
private final ImmutableSet<Module> baseModules; private final Set<Module> baseModules;
private RealOverriddenModuleBuilder(Iterable<? extends Module> baseModules) { private RealOverriddenModuleBuilder(Iterable<? extends Module> baseModules) {
// TODO: infer type once JI-9019884 is fixed this.baseModules = unmodifiableSet(newHashSet(baseModules));
this.baseModules = ImmutableSet.<Module>copyOf(baseModules);
} }
@Override @Override

View File

@ -21,11 +21,17 @@ package org.elasticsearch.common.util.set;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public final class Sets { public final class Sets {
@ -66,6 +72,14 @@ public final class Sets {
return set; return set;
} }
/**
* Collects {@code Stream<Collection<T>>} into {@code Set<T>}.
*/
@SuppressWarnings("unchecked")
public static <T> Collector<Collection<T>, Set<T>, Set<T>> toFlatSet() {
return (Collector<Collection<T>, Set<T>, Set<T>>) (Object) ToFlatSetCollector.INSTANCE;
}
public static <T> Set<T> newConcurrentHashSet() { public static <T> Set<T> newConcurrentHashSet() {
return Collections.newSetFromMap(new ConcurrentHashMap<>()); return Collections.newSetFromMap(new ConcurrentHashMap<>());
} }
@ -89,4 +103,39 @@ public final class Sets {
union.addAll(right); union.addAll(right);
return union; return union;
} }
/**
* Collects {@code Stream<Collection<T>>} into {@code Set<T>}.
*/
private static enum ToFlatSetCollector implements Collector<Collection<Object>, Set<Object>, Set<Object>> {
INSTANCE;
@Override
public Supplier<Set<Object>> supplier() {
return HashSet::new;
}
@Override
public BiConsumer<Set<Object>, Collection<Object>> accumulator() {
return Collection::addAll;
}
@Override
public BinaryOperator<Set<Object>> combiner() {
return (lhs, rhs) -> {
lhs.addAll(rhs);
return lhs;
};
}
@Override
public Function<Set<Object>, Set<Object>> finisher() {
return Function.identity();
}
@Override
public Set<java.util.stream.Collector.Characteristics> characteristics() {
return EnumSet.of(Collector.Characteristics.IDENTITY_FINISH, Collector.Characteristics.UNORDERED);
}
}
} }

View File

@ -20,6 +20,7 @@ package org.elasticsearch.gateway;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
@ -38,7 +39,13 @@ import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.transport.ReceiveTimeoutTransportException; import org.elasticsearch.transport.ReceiveTimeoutTransportException;
import java.util.*; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import static java.util.Collections.unmodifiableSet;
/** /**
* Allows to asynchronously fetch shard related data from other nodes for allocation, without blocking * Allows to asynchronously fetch shard related data from other nodes for allocation, without blocking
@ -143,7 +150,7 @@ public abstract class AsyncShardFetch<T extends BaseNodeResponse> implements Rel
} }
} }
} }
Set<String> allIgnoreNodes = ImmutableSet.copyOf(nodesToIgnore); Set<String> allIgnoreNodes = unmodifiableSet(new HashSet<>(nodesToIgnore));
// clear the nodes to ignore, we had a successful run in fetching everything we can // clear the nodes to ignore, we had a successful run in fetching everything we can
// we need to try them if another full run is needed // we need to try them if another full run is needed
nodesToIgnore.clear(); nodesToIgnore.clear();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.analysis; package org.elasticsearch.index.analysis;
import com.google.common.collect.ImmutableSet;
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter; import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.inject.assistedinject.Assisted;
@ -28,26 +27,26 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.settings.IndexSettings;
import java.io.Reader; import java.io.Reader;
import java.util.Set;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
/**
*
*/
public class HtmlStripCharFilterFactory extends AbstractCharFilterFactory { public class HtmlStripCharFilterFactory extends AbstractCharFilterFactory {
private final Set<String> escapedTags;
private final ImmutableSet<String> escapedTags;
@Inject @Inject
public HtmlStripCharFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { public HtmlStripCharFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) {
super(index, indexSettings, name); super(index, indexSettings, name);
String[] escapedTags = settings.getAsArray("escaped_tags"); String[] escapedTags = settings.getAsArray("escaped_tags");
if (escapedTags.length > 0) { if (escapedTags.length > 0) {
this.escapedTags = ImmutableSet.copyOf(escapedTags); this.escapedTags = unmodifiableSet(newHashSet(escapedTags));
} else { } else {
this.escapedTags = null; this.escapedTags = null;
} }
} }
public ImmutableSet<String> escapedTags() { public Set<String> escapedTags() {
return escapedTags; return escapedTags;
} }

View File

@ -20,7 +20,7 @@
package org.elasticsearch.indices; package org.elasticsearch.indices;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.CollectionUtil;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
@ -87,14 +87,15 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
@ -162,11 +163,11 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i
@Override @Override
protected void doStop() { protected void doStop() {
ImmutableSet<String> indices = ImmutableSet.copyOf(this.indices.keySet()); ExecutorService indicesStopExecutor = Executors.newFixedThreadPool(5, EsExecutors.daemonThreadFactory("indices_shutdown"));
// Copy indices because we modify it asynchronously in the body of the loop
Set<String> indices = new HashSet<>(this.indices.keySet());
final CountDownLatch latch = new CountDownLatch(indices.size()); final CountDownLatch latch = new CountDownLatch(indices.size());
final ExecutorService indicesStopExecutor = Executors.newFixedThreadPool(5, EsExecutors.daemonThreadFactory("indices_shutdown"));
for (final String index : indices) { for (final String index : indices) {
indicesStopExecutor.execute(new Runnable() { indicesStopExecutor.execute(new Runnable() {
@Override @Override

View File

@ -20,6 +20,7 @@
package org.elasticsearch.cluster; package org.elasticsearch.cluster;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionModule; import org.elasticsearch.action.ActionModule;
@ -59,7 +60,10 @@ import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
@ -89,8 +93,7 @@ public class ClusterInfoServiceIT extends ESIntegTestCase {
} }
public static class BlockingActionFilter extends org.elasticsearch.action.support.ActionFilter.Simple { public static class BlockingActionFilter extends org.elasticsearch.action.support.ActionFilter.Simple {
private Set<String> blockedActions = emptySet();
ImmutableSet<String> blockedActions = ImmutableSet.of();
@Inject @Inject
public BlockingActionFilter(Settings settings) { public BlockingActionFilter(Settings settings) {
@ -116,7 +119,7 @@ public class ClusterInfoServiceIT extends ESIntegTestCase {
} }
public void blockActions(String... actions) { public void blockActions(String... actions) {
blockedActions = ImmutableSet.copyOf(actions); blockedActions = unmodifiableSet(newHashSet(actions));
} }
} }

View File

@ -129,6 +129,10 @@ com.google.common.io.Files
com.google.common.primitives.Ints com.google.common.primitives.Ints
com.google.common.collect.ImmutableMap#entrySet() com.google.common.collect.ImmutableMap#entrySet()
com.google.common.collect.ImmutableSet#builder() com.google.common.collect.ImmutableSet#builder()
com.google.common.collect.ImmutableSet#copyOf(java.lang.Iterable)
com.google.common.collect.ImmutableSet#copyOf(java.util.Iterator)
com.google.common.collect.ImmutableSet#copyOf(java.util.Collection)
com.google.common.collect.ImmutableSet#copyOf(java.lang.Object[])
@defaultMessage Do not violate java's access system @defaultMessage Do not violate java's access system
java.lang.reflect.AccessibleObject#setAccessible(boolean) java.lang.reflect.AccessibleObject#setAccessible(boolean)