Remove Future.removeListener* and addListeners (#11375)

Motivation:

We didnt really have a good use-case for removeListener* and addListeners. Because of this we should just remove these methods and so make things simpler.

Modifications:

Remove methods

Result:

Cleanup
This commit is contained in:
Norman Maurer 2021-06-09 08:31:02 +02:00 committed by GitHub
parent ed2443ec09
commit 1415938163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 0 additions and 425 deletions

View File

@ -310,27 +310,6 @@ public abstract class AbstractScheduledEventExecutor extends AbstractEventExecut
return this; return this;
} }
@Override
public RunnableScheduledFuture<V> addListeners(
GenericFutureListener<? extends Future<? super V>>... listeners) {
future.addListeners(listeners);
return this;
}
@Override
public RunnableScheduledFuture<V> removeListener(
GenericFutureListener<? extends Future<? super V>> listener) {
future.removeListener(listener);
return this;
}
@Override
public RunnableScheduledFuture<V> removeListeners(
GenericFutureListener<? extends Future<? super V>>... listeners) {
future.removeListeners(listeners);
return this;
}
@Override @Override
public boolean isPeriodic() { public boolean isPeriodic() {
return future.isPeriodic(); return future.isPeriodic();

View File

@ -55,34 +55,6 @@ public abstract class CompleteFuture<V> implements Future<V> {
return this; return this;
} }
@Override
public Future<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
requireNonNull(listeners, "listeners");
DefaultPromise.safeExecute(executor(), () -> notifyListeners(listeners));
return this;
}
private void notifyListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
for (GenericFutureListener<? extends Future<? super V>> l : listeners) {
if (l == null) {
break;
}
DefaultPromise.notifyListener0(this, l);
}
}
@Override
public Future<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener) {
// NOOP
return this;
}
@Override
public Future<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
// NOOP
return this;
}
@Override @Override
public Future<V> await() throws InterruptedException { public Future<V> await() throws InterruptedException {
if (Thread.interrupted()) { if (Thread.interrupted()) {

View File

@ -72,24 +72,6 @@ public class DefaultProgressivePromise<V> extends DefaultPromise<V> implements P
return this; return this;
} }
@Override
public ProgressivePromise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
super.addListeners(listeners);
return this;
}
@Override
public ProgressivePromise<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener) {
super.removeListener(listener);
return this;
}
@Override
public ProgressivePromise<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
super.removeListeners(listeners);
return this;
}
@Override @Override
public ProgressivePromise<V> sync() throws InterruptedException { public ProgressivePromise<V> sync() throws InterruptedException {
super.sync(); super.sync();

View File

@ -175,53 +175,6 @@ public class DefaultPromise<V> implements Promise<V> {
return this; return this;
} }
@Override
public Promise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
requireNonNull(listeners, "listeners");
synchronized (this) {
for (GenericFutureListener<? extends Future<? super V>> listener : listeners) {
if (listener == null) {
break;
}
addListener0(listener);
}
}
if (isDone()) {
notifyListeners();
}
return this;
}
@Override
public Promise<V> removeListener(final GenericFutureListener<? extends Future<? super V>> listener) {
requireNonNull(listener, "listener");
synchronized (this) {
removeListener0(listener);
}
return this;
}
@Override
public Promise<V> removeListeners(final GenericFutureListener<? extends Future<? super V>>... listeners) {
requireNonNull(listeners, "listeners");
synchronized (this) {
for (GenericFutureListener<? extends Future<? super V>> listener : listeners) {
if (listener == null) {
break;
}
removeListener0(listener);
}
}
return this;
}
@Override @Override
public Promise<V> await() throws InterruptedException { public Promise<V> await() throws InterruptedException {
if (isDone()) { if (isDone()) {

View File

@ -55,32 +55,6 @@ public interface Future<V> extends java.util.concurrent.Future<V> {
*/ */
Future<V> addListener(GenericFutureListener<? extends Future<? super V>> listener); Future<V> addListener(GenericFutureListener<? extends Future<? super V>> listener);
/**
* Adds the specified listeners to this future. The
* specified listeners are notified when this future is
* {@linkplain #isDone() done}. If this future is already
* completed, the specified listeners are notified immediately.
*/
Future<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
/**
* Removes the first occurrence of the specified listener from this future.
* The specified listener is no longer notified when this
* future is {@linkplain #isDone() done}. If the specified
* listener is not associated with this future, this method
* does nothing and returns silently.
*/
Future<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener);
/**
* Removes the first occurrence for each of the listeners from this future.
* The specified listeners are no longer notified when this
* future is {@linkplain #isDone() done}. If the specified
* listeners are not associated with this future, this method
* does nothing and returns silently.
*/
Future<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
/** /**
* Waits for this future until it is done, and rethrows the cause of the failure if this future * Waits for this future until it is done, and rethrows the cause of the failure if this future
* failed. * failed.

View File

@ -24,15 +24,6 @@ public interface ProgressiveFuture<V> extends Future<V> {
@Override @Override
ProgressiveFuture<V> addListener(GenericFutureListener<? extends Future<? super V>> listener); ProgressiveFuture<V> addListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
ProgressiveFuture<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override
ProgressiveFuture<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
ProgressiveFuture<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override @Override
ProgressiveFuture<V> sync() throws InterruptedException; ProgressiveFuture<V> sync() throws InterruptedException;

View File

@ -42,15 +42,6 @@ public interface ProgressivePromise<V> extends Promise<V>, ProgressiveFuture<V>
@Override @Override
ProgressivePromise<V> addListener(GenericFutureListener<? extends Future<? super V>> listener); ProgressivePromise<V> addListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
ProgressivePromise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override
ProgressivePromise<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
ProgressivePromise<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override @Override
ProgressivePromise<V> await() throws InterruptedException; ProgressivePromise<V> await() throws InterruptedException;

View File

@ -67,15 +67,6 @@ public interface Promise<V> extends Future<V> {
@Override @Override
Promise<V> addListener(GenericFutureListener<? extends Future<? super V>> listener); Promise<V> addListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
Promise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override
Promise<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
Promise<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override @Override
Promise<V> await() throws InterruptedException; Promise<V> await() throws InterruptedException;

View File

@ -130,21 +130,6 @@ class PromiseTask<V> extends DefaultPromise<V> implements RunnableFuture<V> {
return super.addListener(listener); return super.addListener(listener);
} }
@Override
public Promise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
return super.addListeners(listeners);
}
@Override
public Promise<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener) {
return super.removeListener(listener);
}
@Override
public Promise<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
return super.removeListeners(listeners);
}
@Override @Override
protected StringBuilder toStringBuilder() { protected StringBuilder toStringBuilder() {
StringBuilder buf = super.toStringBuilder(); StringBuilder buf = super.toStringBuilder();

View File

@ -24,15 +24,6 @@ public interface RunnableFuture<V> extends java.util.concurrent.RunnableFuture<V
@Override @Override
RunnableFuture<V> addListener(GenericFutureListener<? extends Future<? super V>> listener); RunnableFuture<V> addListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
RunnableFuture<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override
RunnableFuture<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
RunnableFuture<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override @Override
RunnableFuture<V> sync() throws InterruptedException; RunnableFuture<V> sync() throws InterruptedException;

View File

@ -60,24 +60,6 @@ final class RunnableFutureAdapter<V> implements RunnableFuture<V> {
return this; return this;
} }
@Override
public RunnableFuture<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
promise.addListeners(listeners);
return this;
}
@Override
public RunnableFuture<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener) {
promise.removeListener(listener);
return this;
}
@Override
public RunnableFuture<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
promise.removeListeners(listeners);
return this;
}
@Override @Override
public RunnableFuture<V> sync() throws InterruptedException { public RunnableFuture<V> sync() throws InterruptedException {
promise.sync(); promise.sync();

View File

@ -41,14 +41,5 @@ public interface RunnableScheduledFuture<V> extends
@Override @Override
RunnableScheduledFuture<V> addListener(GenericFutureListener<? extends Future<? super V>> listener); RunnableScheduledFuture<V> addListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
RunnableScheduledFuture<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
@Override
RunnableScheduledFuture<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener);
@Override
RunnableScheduledFuture<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners);
} }

View File

@ -164,24 +164,6 @@ final class RunnableScheduledFutureAdapter<V> implements RunnableScheduledFuture
return this; return this;
} }
@Override
public RunnableScheduledFuture<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
promise.addListeners(listeners);
return this;
}
@Override
public RunnableScheduledFuture<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener) {
promise.removeListener(listener);
return this;
}
@Override
public RunnableScheduledFuture<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
promise.removeListeners(listeners);
return this;
}
@Override @Override
public RunnableScheduledFuture<V> sync() throws InterruptedException { public RunnableScheduledFuture<V> sync() throws InterruptedException {
promise.sync(); promise.sync();

View File

@ -111,10 +111,6 @@ public abstract class AddressResolverGroup<T extends SocketAddress> implements C
executorTerminationListeners.clear(); executorTerminationListeners.clear();
} }
for (final Map.Entry<EventExecutor, GenericFutureListener<Future<Object>>> entry : listeners) {
entry.getKey().terminationFuture().removeListener(entry.getValue());
}
for (final AddressResolver<T> r: rArray) { for (final AddressResolver<T> r: rArray) {
try { try {
r.close(); r.close();

View File

@ -173,15 +173,6 @@ public interface ChannelFuture extends Future<Void> {
@Override @Override
ChannelFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener); ChannelFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelFuture addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override
ChannelFuture removeListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelFuture removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override @Override
ChannelFuture sync() throws InterruptedException; ChannelFuture sync() throws InterruptedException;

View File

@ -26,15 +26,6 @@ public interface ChannelProgressiveFuture extends ChannelFuture, ProgressiveFutu
@Override @Override
ChannelProgressiveFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener); ChannelProgressiveFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelProgressiveFuture addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override
ChannelProgressiveFuture removeListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelProgressiveFuture removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override @Override
ChannelProgressiveFuture sync() throws InterruptedException; ChannelProgressiveFuture sync() throws InterruptedException;

View File

@ -27,15 +27,6 @@ public interface ChannelProgressivePromise extends ProgressivePromise<Void>, Cha
@Override @Override
ChannelProgressivePromise addListener(GenericFutureListener<? extends Future<? super Void>> listener); ChannelProgressivePromise addListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelProgressivePromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override
ChannelProgressivePromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelProgressivePromise removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override @Override
ChannelProgressivePromise sync() throws InterruptedException; ChannelProgressivePromise sync() throws InterruptedException;

View File

@ -40,15 +40,6 @@ public interface ChannelPromise extends ChannelFuture, Promise<Void> {
@Override @Override
ChannelPromise addListener(GenericFutureListener<? extends Future<? super Void>> listener); ChannelPromise addListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelPromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override
ChannelPromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelPromise removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override @Override
ChannelPromise sync() throws InterruptedException; ChannelPromise sync() throws InterruptedException;

View File

@ -57,24 +57,6 @@ abstract class CompleteChannelFuture extends CompleteFuture<Void> implements Cha
return this; return this;
} }
@Override
public ChannelFuture addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.addListeners(listeners);
return this;
}
@Override
public ChannelFuture removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
super.removeListener(listener);
return this;
}
@Override
public ChannelFuture removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.removeListeners(listeners);
return this;
}
@Override @Override
public ChannelFuture syncUninterruptibly() { public ChannelFuture syncUninterruptibly() {
return this; return this;

View File

@ -94,25 +94,6 @@ public class DefaultChannelProgressivePromise
return this; return this;
} }
@Override
public ChannelProgressivePromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.addListeners(listeners);
return this;
}
@Override
public ChannelProgressivePromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
super.removeListener(listener);
return this;
}
@Override
public ChannelProgressivePromise removeListeners(
GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.removeListeners(listeners);
return this;
}
@Override @Override
public ChannelProgressivePromise sync() throws InterruptedException { public ChannelProgressivePromise sync() throws InterruptedException {
super.sync(); super.sync();

View File

@ -86,24 +86,6 @@ public class DefaultChannelPromise extends DefaultPromise<Void> implements Chann
return this; return this;
} }
@Override
public ChannelPromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.addListeners(listeners);
return this;
}
@Override
public ChannelPromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
super.removeListener(listener);
return this;
}
@Override
public ChannelPromise removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.removeListeners(listeners);
return this;
}
@Override @Override
public ChannelPromise sync() throws InterruptedException { public ChannelPromise sync() throws InterruptedException {
super.sync(); super.sync();

View File

@ -103,24 +103,6 @@ public final class DelegatingChannelPromiseNotifier implements ChannelPromise, C
return this; return this;
} }
@Override
public ChannelPromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
delegate.addListeners(listeners);
return this;
}
@Override
public ChannelPromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
delegate.removeListener(listener);
return this;
}
@Override
public ChannelPromise removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
delegate.removeListeners(listeners);
return this;
}
@Override @Override
public boolean tryFailure(Throwable cause) { public boolean tryFailure(Throwable cause) {
return delegate.tryFailure(cause); return delegate.tryFailure(cause);

View File

@ -143,15 +143,6 @@ public interface ChannelGroupFuture extends Future<Void>, Iterable<ChannelFuture
@Override @Override
ChannelGroupFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener); ChannelGroupFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelGroupFuture addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override
ChannelGroupFuture removeListener(GenericFutureListener<? extends Future<? super Void>> listener);
@Override
ChannelGroupFuture removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners);
@Override @Override
ChannelGroupFuture await() throws InterruptedException; ChannelGroupFuture await() throws InterruptedException;

View File

@ -178,7 +178,6 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
return false; return false;
} }
c.closeFuture().removeListener(remover);
return true; return true;
} }

View File

@ -151,25 +151,6 @@ final class DefaultChannelGroupFuture extends DefaultPromise<Void> implements Ch
return this; return this;
} }
@Override
public DefaultChannelGroupFuture addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.addListeners(listeners);
return this;
}
@Override
public DefaultChannelGroupFuture removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
super.removeListener(listener);
return this;
}
@Override
public DefaultChannelGroupFuture removeListeners(
GenericFutureListener<? extends Future<? super Void>>... listeners) {
super.removeListeners(listeners);
return this;
}
@Override @Override
public DefaultChannelGroupFuture await() throws InterruptedException { public DefaultChannelGroupFuture await() throws InterruptedException {
super.await(); super.await();

View File

@ -31,16 +31,6 @@ public class CompleteChannelFutureTest {
assertThrows(NullPointerException.class, () -> new CompleteChannelFutureImpl(null)); assertThrows(NullPointerException.class, () -> new CompleteChannelFutureImpl(null));
} }
@Test
public void shouldNotDoAnythingOnRemove() throws Exception {
Channel channel = Mockito.mock(Channel.class);
CompleteChannelFuture future = new CompleteChannelFutureImpl(channel);
ChannelFutureListener l = Mockito.mock(ChannelFutureListener.class);
future.removeListener(l);
Mockito.verifyNoMoreInteractions(l);
Mockito.verifyZeroInteractions(channel);
}
@Test @Test
public void testConstantProperties() throws InterruptedException { public void testConstantProperties() throws InterruptedException {
Channel channel = Mockito.mock(Channel.class); Channel channel = Mockito.mock(Channel.class);

View File

@ -1,37 +0,0 @@
/*
* Copyright 2017 The Netty Project
*
* The Netty Project 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:
*
* https://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 io.netty.channel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class DelegatingChannelPromiseNotifierTest {
@Test
public void varargsNotifiersAllowed() {
ChannelPromise promise = Mockito.mock(ChannelPromise.class);
DelegatingChannelPromiseNotifier promiseNotifier = new DelegatingChannelPromiseNotifier(promise);
GenericFutureListener<? extends Future<? super Void>> gfl =
(GenericFutureListener<? extends Future<? super Void>>) Mockito.mock(GenericFutureListener.class);
promiseNotifier.addListeners(gfl);
promiseNotifier.removeListeners(gfl);
Mockito.verify(promise).addListeners(gfl);
Mockito.verify(promise).removeListeners(gfl);
}
}