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;
}
@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
public boolean isPeriodic() {
return future.isPeriodic();

View File

@ -55,34 +55,6 @@ public abstract class CompleteFuture<V> implements Future<V> {
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
public Future<V> await() throws InterruptedException {
if (Thread.interrupted()) {

View File

@ -72,24 +72,6 @@ public class DefaultProgressivePromise<V> extends DefaultPromise<V> implements P
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
public ProgressivePromise<V> sync() throws InterruptedException {
super.sync();

View File

@ -175,53 +175,6 @@ public class DefaultPromise<V> implements Promise<V> {
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
public Promise<V> await() throws InterruptedException {
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);
/**
* 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
* failed.

View File

@ -24,15 +24,6 @@ public interface ProgressiveFuture<V> extends Future<V> {
@Override
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
ProgressiveFuture<V> sync() throws InterruptedException;

View File

@ -42,15 +42,6 @@ public interface ProgressivePromise<V> extends Promise<V>, ProgressiveFuture<V>
@Override
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
ProgressivePromise<V> await() throws InterruptedException;

View File

@ -67,15 +67,6 @@ public interface Promise<V> extends Future<V> {
@Override
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
Promise<V> await() throws InterruptedException;

View File

@ -130,21 +130,6 @@ class PromiseTask<V> extends DefaultPromise<V> implements RunnableFuture<V> {
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
protected StringBuilder toStringBuilder() {
StringBuilder buf = super.toStringBuilder();

View File

@ -24,15 +24,6 @@ public interface RunnableFuture<V> extends java.util.concurrent.RunnableFuture<V
@Override
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
RunnableFuture<V> sync() throws InterruptedException;

View File

@ -60,24 +60,6 @@ final class RunnableFutureAdapter<V> implements RunnableFuture<V> {
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
public RunnableFuture<V> sync() throws InterruptedException {
promise.sync();

View File

@ -41,14 +41,5 @@ public interface RunnableScheduledFuture<V> extends
@Override
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;
}
@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
public RunnableScheduledFuture<V> sync() throws InterruptedException {
promise.sync();

View File

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

View File

@ -173,15 +173,6 @@ public interface ChannelFuture extends Future<Void> {
@Override
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
ChannelFuture sync() throws InterruptedException;

View File

@ -26,15 +26,6 @@ public interface ChannelProgressiveFuture extends ChannelFuture, ProgressiveFutu
@Override
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
ChannelProgressiveFuture sync() throws InterruptedException;

View File

@ -27,15 +27,6 @@ public interface ChannelProgressivePromise extends ProgressivePromise<Void>, Cha
@Override
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
ChannelProgressivePromise sync() throws InterruptedException;

View File

@ -40,15 +40,6 @@ public interface ChannelPromise extends ChannelFuture, Promise<Void> {
@Override
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
ChannelPromise sync() throws InterruptedException;

View File

@ -57,24 +57,6 @@ abstract class CompleteChannelFuture extends CompleteFuture<Void> implements Cha
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
public ChannelFuture syncUninterruptibly() {
return this;

View File

@ -94,25 +94,6 @@ public class DefaultChannelProgressivePromise
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
public ChannelProgressivePromise sync() throws InterruptedException {
super.sync();

View File

@ -86,24 +86,6 @@ public class DefaultChannelPromise extends DefaultPromise<Void> implements Chann
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
public ChannelPromise sync() throws InterruptedException {
super.sync();

View File

@ -103,24 +103,6 @@ public final class DelegatingChannelPromiseNotifier implements ChannelPromise, C
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
public boolean tryFailure(Throwable cause) {
return delegate.tryFailure(cause);

View File

@ -143,15 +143,6 @@ public interface ChannelGroupFuture extends Future<Void>, Iterable<ChannelFuture
@Override
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
ChannelGroupFuture await() throws InterruptedException;

View File

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

View File

@ -151,25 +151,6 @@ final class DefaultChannelGroupFuture extends DefaultPromise<Void> implements Ch
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
public DefaultChannelGroupFuture await() throws InterruptedException {
super.await();

View File

@ -31,16 +31,6 @@ public class CompleteChannelFutureTest {
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
public void testConstantProperties() throws InterruptedException {
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);
}
}