Reduce code duplication in DefaultPromise

This commit is contained in:
Trustin Lee 2014-02-06 22:29:53 -08:00
parent 4628d9a672
commit 35ae000c59

View File

@ -577,7 +577,7 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
try { try {
if (listeners instanceof DefaultFutureListeners) { if (listeners instanceof DefaultFutureListeners) {
final DefaultFutureListeners dfl = (DefaultFutureListeners) listeners; final DefaultFutureListeners dfl = (DefaultFutureListeners) listeners;
executor.execute(new Runnable() { execute(executor, new Runnable() {
@Override @Override
public void run() { public void run() {
notifyListeners0(DefaultPromise.this, dfl); notifyListeners0(DefaultPromise.this, dfl);
@ -588,7 +588,7 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final GenericFutureListener<? extends Future<V>> l = final GenericFutureListener<? extends Future<V>> l =
(GenericFutureListener<? extends Future<V>>) listeners; (GenericFutureListener<? extends Future<V>>) listeners;
executor.execute(new Runnable() { execute(executor, new Runnable() {
@Override @Override
public void run() { public void run() {
notifyListener0(DefaultPromise.this, l); notifyListener0(DefaultPromise.this, l);
@ -750,28 +750,24 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
self, (GenericProgressiveFutureListener<ProgressiveFuture<V>>) listeners, progress, total); self, (GenericProgressiveFutureListener<ProgressiveFuture<V>>) listeners, progress, total);
} }
} else { } else {
try { if (listeners instanceof GenericProgressiveFutureListener[]) {
if (listeners instanceof GenericProgressiveFutureListener[]) { final GenericProgressiveFutureListener<?>[] array =
final GenericProgressiveFutureListener<?>[] array = (GenericProgressiveFutureListener<?>[]) listeners;
(GenericProgressiveFutureListener<?>[]) listeners; execute(executor, new Runnable() {
executor.execute(new Runnable() { @Override
@Override public void run() {
public void run() { notifyProgressiveListeners0(self, array, progress, total);
notifyProgressiveListeners0(self, array, progress, total); }
} });
}); } else {
} else { final GenericProgressiveFutureListener<ProgressiveFuture<V>> l =
final GenericProgressiveFutureListener<ProgressiveFuture<V>> l = (GenericProgressiveFutureListener<ProgressiveFuture<V>>) listeners;
(GenericProgressiveFutureListener<ProgressiveFuture<V>>) listeners; execute(executor, new Runnable() {
executor.execute(new Runnable() { @Override
@Override public void run() {
public void run() { notifyProgressiveListener0(self, l, progress, total);
notifyProgressiveListener0(self, l, progress, total); }
} });
});
}
} catch (Throwable t) {
logger.error("Failed to notify listener(s). Event loop shut down?", t);
} }
} }
} }
@ -852,7 +848,7 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
} else { } else {
// Reschedule until the initial notification is done to avoid the race condition // Reschedule until the initial notification is done to avoid the race condition
// where the notification is made in an incorrect order. // where the notification is made in an incorrect order.
executor().execute(this); execute(executor(), this);
} }
} }
} }