Polishing
This commit is contained in:
@@ -75,7 +75,6 @@ public class AntPathMatcher implements PathMatcher {
|
||||
* Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
|
||||
*/
|
||||
public AntPathMatcher() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,8 +27,8 @@ public interface FailureCallback {
|
||||
|
||||
/**
|
||||
* Called when the {@link ListenableFuture} fails to complete.
|
||||
* @param t the exception that triggered the failure
|
||||
* @param ex the exception that triggered the failure
|
||||
*/
|
||||
void onFailure(Throwable t);
|
||||
void onFailure(Throwable ex);
|
||||
|
||||
}
|
||||
|
||||
@@ -30,11 +30,10 @@ import java.util.concurrent.ExecutionException;
|
||||
* @author Arjen Poutsma
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S>
|
||||
implements ListenableFuture<T> {
|
||||
public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S> implements ListenableFuture<T> {
|
||||
|
||||
/**
|
||||
* Constructs a new {@code ListenableFutureAdapter} with the given adaptee.
|
||||
* Construct a new {@code ListenableFutureAdapter} with the given adaptee.
|
||||
* @param adaptee the future to adaptee to
|
||||
*/
|
||||
protected ListenableFutureAdapter(ListenableFuture<S> adaptee) {
|
||||
@@ -48,8 +47,7 @@ public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(final SuccessCallback<? super T> successCallback,
|
||||
final FailureCallback failureCallback) {
|
||||
public void addCallback(final SuccessCallback<? super T> successCallback, final FailureCallback failureCallback) {
|
||||
ListenableFuture<S> listenableAdaptee = (ListenableFuture<S>) getAdaptee();
|
||||
listenableAdaptee.addCallback(new ListenableFutureCallback<S>() {
|
||||
@Override
|
||||
@@ -65,10 +63,9 @@ public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S>
|
||||
onFailure(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
failureCallback.onFailure(t);
|
||||
public void onFailure(Throwable ex) {
|
||||
failureCallback.onFailure(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,11 +32,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ListenableFutureCallbackRegistry<T> {
|
||||
|
||||
private final Queue<SuccessCallback<? super T>> successCallbacks =
|
||||
new LinkedList<SuccessCallback<? super T>>();
|
||||
private final Queue<SuccessCallback<? super T>> successCallbacks = new LinkedList<SuccessCallback<? super T>>();
|
||||
|
||||
private final Queue<FailureCallback> failureCallbacks =
|
||||
new LinkedList<FailureCallback>();
|
||||
private final Queue<FailureCallback> failureCallbacks = new LinkedList<FailureCallback>();
|
||||
|
||||
private State state = State.NEW;
|
||||
|
||||
@@ -52,18 +50,17 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addCallback(ListenableFutureCallback<? super T> callback) {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
|
||||
synchronized (mutex) {
|
||||
switch (state) {
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
successCallbacks.add(callback);
|
||||
failureCallbacks.add(callback);
|
||||
this.successCallbacks.add(callback);
|
||||
this.failureCallbacks.add(callback);
|
||||
break;
|
||||
case SUCCESS:
|
||||
callback.onSuccess((T)result);
|
||||
callback.onSuccess((T) this.result);
|
||||
break;
|
||||
case FAILURE:
|
||||
callback.onFailure((Throwable) result);
|
||||
callback.onFailure((Throwable) this.result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -72,20 +69,18 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
/**
|
||||
* Adds the given success callback to this registry.
|
||||
* @param callback the success callback to add
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addSuccessCallback(SuccessCallback<? super T> callback) {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
|
||||
synchronized (mutex) {
|
||||
switch (state) {
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
successCallbacks.add(callback);
|
||||
this.successCallbacks.add(callback);
|
||||
break;
|
||||
case SUCCESS:
|
||||
callback.onSuccess((T)result);
|
||||
callback.onSuccess((T) this.result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -94,57 +89,54 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
/**
|
||||
* Adds the given failure callback to this registry.
|
||||
* @param callback the failure callback to add
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addFailureCallback(FailureCallback callback) {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
|
||||
synchronized (mutex) {
|
||||
switch (state) {
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
failureCallbacks.add(callback);
|
||||
this.failureCallbacks.add(callback);
|
||||
break;
|
||||
case FAILURE:
|
||||
callback.onFailure((Throwable) result);
|
||||
callback.onFailure((Throwable) this.result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a {@link ListenableFutureCallback#onSuccess(Object)} call on all added
|
||||
* callbacks with the given result
|
||||
* Triggers a {@link ListenableFutureCallback#onSuccess(Object)} call on all
|
||||
* added callbacks with the given result
|
||||
* @param result the result to trigger the callbacks with
|
||||
*/
|
||||
public void success(T result) {
|
||||
synchronized (mutex) {
|
||||
state = State.SUCCESS;
|
||||
synchronized (this.mutex) {
|
||||
this.state = State.SUCCESS;
|
||||
this.result = result;
|
||||
|
||||
while (!successCallbacks.isEmpty()) {
|
||||
successCallbacks.poll().onSuccess(result);
|
||||
while (!this.successCallbacks.isEmpty()) {
|
||||
this.successCallbacks.poll().onSuccess(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a {@link ListenableFutureCallback#onFailure(Throwable)} call on all added
|
||||
* callbacks with the given {@code Throwable}.
|
||||
* @param t the exception to trigger the callbacks with
|
||||
* Triggers a {@link ListenableFutureCallback#onFailure(Throwable)} call on all
|
||||
* added callbacks with the given {@code Throwable}.
|
||||
* @param ex the exception to trigger the callbacks with
|
||||
*/
|
||||
public void failure(Throwable t) {
|
||||
synchronized (mutex) {
|
||||
state = State.FAILURE;
|
||||
this.result = t;
|
||||
|
||||
while (!failureCallbacks.isEmpty()) {
|
||||
failureCallbacks.poll().onFailure(t);
|
||||
public void failure(Throwable ex) {
|
||||
synchronized (this.mutex) {
|
||||
this.state = State.FAILURE;
|
||||
this.result = ex;
|
||||
while (!this.failureCallbacks.isEmpty()) {
|
||||
this.failureCallbacks.poll().onFailure(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum State {NEW, SUCCESS, FAILURE}
|
||||
|
||||
}
|
||||
|
||||
@@ -155,7 +155,6 @@ public class SettableListenableFuture<T> implements ListenableFuture<T> {
|
||||
|
||||
private volatile boolean cancelled = false;
|
||||
|
||||
|
||||
public boolean setValue(T value) {
|
||||
if (this.cancelled) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user