Skip to content

Commit 97bd0cc

Browse files
committed
Polishing
1 parent 8543a55 commit 97bd0cc

File tree

10 files changed

+306
-432
lines changed

10 files changed

+306
-432
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,8 +49,7 @@
4949
* @see #setBeforeExistingAdvisors
5050
*/
5151
@SuppressWarnings("serial")
52-
public class AsyncAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor
53-
implements BeanFactoryAware {
52+
public class AsyncAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor implements BeanFactoryAware {
5453

5554
private Class<? extends Annotation> asyncAnnotationType;
5655

@@ -61,6 +60,7 @@ public AsyncAnnotationBeanPostProcessor() {
6160
setBeforeExistingAdvisors(true);
6261
}
6362

63+
6464
/**
6565
* Set the 'async' annotation type to be detected at either class or method
6666
* level. By default, both the {@link Async} annotation and the EJB 3.1

spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureAdapter.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,18 +30,16 @@
3030
* @author Arjen Poutsma
3131
* @since 4.0
3232
*/
33-
public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S>
34-
implements ListenableFuture<T> {
33+
public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S> implements ListenableFuture<T> {
3534

3635
/**
37-
* Constructs a new {@code ListenableFutureAdapter} with the given adaptee.
36+
* Construct a new {@code ListenableFutureAdapter} with the given adaptee.
3837
* @param adaptee the future to adaptee to
3938
*/
4039
protected ListenableFutureAdapter(ListenableFuture<S> adaptee) {
4140
super(adaptee);
4241
}
4342

44-
4543
@Override
4644
public void addCallback(final ListenableFutureCallback<? super T> callback) {
4745
ListenableFuture<S> listenableAdaptee = (ListenableFuture<S>) getAdaptee();
@@ -59,11 +57,11 @@ public void onSuccess(S result) {
5957
onFailure(t);
6058
}
6159
}
62-
6360
@Override
64-
public void onFailure(Throwable t) {
65-
callback.onFailure(t);
61+
public void onFailure(Throwable ex) {
62+
callback.onFailure(ex);
6663
}
6764
});
6865
}
66+
6967
}

spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallback.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,8 +33,8 @@ public interface ListenableFutureCallback<T> {
3333

3434
/**
3535
* Called when the {@link ListenableFuture} fails to complete.
36-
* @param t the exception that triggered the failure
36+
* @param ex the exception that triggered the failure
3737
*/
38-
void onFailure(Throwable t);
38+
void onFailure(Throwable ex);
3939

4040
}

spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,54 +48,52 @@ public class ListenableFutureCallbackRegistry<T> {
4848
@SuppressWarnings("unchecked")
4949
public void addCallback(ListenableFutureCallback<? super T> callback) {
5050
Assert.notNull(callback, "'callback' must not be null");
51-
52-
synchronized (mutex) {
53-
switch (state) {
51+
synchronized (this.mutex) {
52+
switch (this.state) {
5453
case NEW:
55-
callbacks.add(callback);
54+
this.callbacks.add(callback);
5655
break;
5756
case SUCCESS:
58-
callback.onSuccess((T)result);
57+
callback.onSuccess((T) this.result);
5958
break;
6059
case FAILURE:
61-
callback.onFailure((Throwable) result);
60+
callback.onFailure((Throwable) this.result);
6261
break;
6362
}
6463
}
6564
}
6665

6766
/**
68-
* Triggers a {@link ListenableFutureCallback#onSuccess(Object)} call on all added
69-
* callbacks with the given result
67+
* Triggers a {@link ListenableFutureCallback#onSuccess(Object)} call on all
68+
* added callbacks with the given result.
7069
* @param result the result to trigger the callbacks with
7170
*/
7271
public void success(T result) {
73-
synchronized (mutex) {
74-
state = State.SUCCESS;
72+
synchronized (this.mutex) {
73+
this.state = State.SUCCESS;
7574
this.result = result;
76-
77-
while (!callbacks.isEmpty()) {
78-
callbacks.poll().onSuccess(result);
75+
while (!this.callbacks.isEmpty()) {
76+
this.callbacks.poll().onSuccess(result);
7977
}
8078
}
8179
}
8280

8381
/**
84-
* Triggers a {@link ListenableFutureCallback#onFailure(Throwable)} call on all added
85-
* callbacks with the given {@code Throwable}.
86-
* @param t the exception to trigger the callbacks with
82+
* Triggers a {@link ListenableFutureCallback#onFailure(Throwable)} call on all
83+
* added callbacks with the given {@code Throwable}.
84+
* @param ex the exception to trigger the callbacks with
8785
*/
88-
public void failure(Throwable t) {
89-
synchronized (mutex) {
90-
state = State.FAILURE;
91-
this.result = t;
92-
93-
while (!callbacks.isEmpty()) {
94-
callbacks.poll().onFailure(t);
86+
public void failure(Throwable ex) {
87+
synchronized (this.mutex) {
88+
this.state = State.FAILURE;
89+
this.result = ex;
90+
while (!this.callbacks.isEmpty()) {
91+
this.callbacks.poll().onFailure(ex);
9592
}
9693
}
9794
}
9895

96+
9997
private enum State {NEW, SUCCESS, FAILURE}
10098

10199
}

spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,10 @@
2020
import java.util.concurrent.Callable;
2121
import java.util.concurrent.ExecutionException;
2222

23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.fail;
2523
import org.junit.Test;
2624

25+
import static org.junit.Assert.*;
26+
2727
/**
2828
* @author Arjen Poutsma
2929
*/
@@ -44,10 +44,9 @@ public String call() throws Exception {
4444
public void onSuccess(String result) {
4545
assertEquals(s, result);
4646
}
47-
4847
@Override
49-
public void onFailure(Throwable t) {
50-
fail(t.getMessage());
48+
public void onFailure(Throwable ex) {
49+
fail(ex.getMessage());
5150
}
5251
});
5352
task.run();
@@ -68,15 +67,12 @@ public String call() throws Exception {
6867
public void onSuccess(String result) {
6968
fail("onSuccess not expected");
7069
}
71-
7270
@Override
73-
public void onFailure(Throwable t) {
74-
assertEquals(s, t.getMessage());
71+
public void onFailure(Throwable ex) {
72+
assertEquals(s, ex.getMessage());
7573
}
7674
});
7775
task.run();
7876
}
7977

80-
81-
8278
}

0 commit comments

Comments
 (0)