upgrade to google guava v 15
This commit is contained in:
parent
3162eb4dcf
commit
cd90382964
4
pom.xml
4
pom.xml
|
@ -158,7 +158,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>14.0.1</version>
|
<version>15.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
@ -976,7 +976,7 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-eclipse-plugin</artifactId>
|
<artifactId>maven-eclipse-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<buildOutputDirectory>eclipse-build</buildOutputDirectory>
|
<buildOutputDirectory>eclipse-build</buildOutputDirectory>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to ElasticSearch and Shay Banon under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. ElasticSearch licenses this
|
|
||||||
* file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.elasticsearch.common.collect;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.AbstractSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class MapBackedSet<E> extends AbstractSet<E> implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -6761513279741915432L;
|
|
||||||
|
|
||||||
private final Map<E, Boolean> map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance which wraps the specified {@code map}.
|
|
||||||
*/
|
|
||||||
public MapBackedSet(Map<E, Boolean> map) {
|
|
||||||
this.map = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return map.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(Object o) {
|
|
||||||
return map.containsKey(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean add(E o) {
|
|
||||||
return map.put(o, Boolean.TRUE) == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean remove(Object o) {
|
|
||||||
return map.remove(o) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
map.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<E> iterator() {
|
|
||||||
return map.keySet().iterator();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,10 +16,11 @@
|
||||||
|
|
||||||
package org.elasticsearch.common.inject.internal;
|
package org.elasticsearch.common.inject.internal;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lazily creates (and caches) values for keys. If creating the value fails (with errors), an
|
* Lazily creates (and caches) values for keys. If creating the value fails (with errors), an
|
||||||
|
@ -29,31 +30,35 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public abstract class FailableCache<K, V> {
|
public abstract class FailableCache<K, V> {
|
||||||
|
|
||||||
private final Map<K, Object> delegate = new MapMaker().makeComputingMap(
|
private final LoadingCache<K, Object> delegate = CacheBuilder.newBuilder().build(new CacheLoader<K, Object>() {
|
||||||
new Function<K, Object>() {
|
@Override
|
||||||
public Object apply(@Nullable K key) {
|
public Object load(K key) throws Exception {
|
||||||
Errors errors = new Errors();
|
Errors errors = new Errors();
|
||||||
V result = null;
|
V result = null;
|
||||||
try {
|
try {
|
||||||
result = FailableCache.this.create(key, errors);
|
result = FailableCache.this.create(key, errors);
|
||||||
} catch (ErrorsException e) {
|
} catch (ErrorsException e) {
|
||||||
errors.merge(e.getErrors());
|
errors.merge(e.getErrors());
|
||||||
}
|
}
|
||||||
return errors.hasErrors() ? errors : result;
|
return errors.hasErrors() ? errors : result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
protected abstract V create(K key, Errors errors) throws ErrorsException;
|
protected abstract V create(K key, Errors errors) throws ErrorsException;
|
||||||
|
|
||||||
public V get(K key, Errors errors) throws ErrorsException {
|
public V get(K key, Errors errors) throws ErrorsException {
|
||||||
Object resultOrError = delegate.get(key);
|
try {
|
||||||
if (resultOrError instanceof Errors) {
|
Object resultOrError = delegate.get(key);
|
||||||
errors.merge((Errors) resultOrError);
|
if (resultOrError instanceof Errors) {
|
||||||
throw errors.toException();
|
errors.merge((Errors) resultOrError);
|
||||||
} else {
|
throw errors.toException();
|
||||||
@SuppressWarnings("unchecked") // create returned a non-error result, so this is safe
|
} else {
|
||||||
V result = (V) resultOrError;
|
@SuppressWarnings("unchecked") // create returned a non-error result, so this is safe
|
||||||
return result;
|
V result = (V) resultOrError;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
|
|
||||||
package org.elasticsearch.common.util.concurrent;
|
package org.elasticsearch.common.util.concurrent;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import jsr166e.ConcurrentHashMapV8;
|
import jsr166e.ConcurrentHashMapV8;
|
||||||
import jsr166y.LinkedTransferQueue;
|
import jsr166y.LinkedTransferQueue;
|
||||||
import org.elasticsearch.common.collect.MapBackedSet;
|
|
||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -73,7 +73,7 @@ public abstract class ConcurrentCollections {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <V> Set<V> newConcurrentSet() {
|
public static <V> Set<V> newConcurrentSet() {
|
||||||
return new MapBackedSet<V>(ConcurrentCollections.<V, Boolean>newConcurrentMap());
|
return Sets.newSetFromMap(ConcurrentCollections.<V, Boolean>newConcurrentMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Queue<T> newQueue() {
|
public static <T> Queue<T> newQueue() {
|
||||||
|
|
Loading…
Reference in New Issue