org.zodiac.sdk.simplenetty.concurrent.AbstractChannelFuture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zodiac-sdk-nio Show documentation
Show all versions of zodiac-sdk-nio Show documentation
Zodiac SDK NIO2(New Non-Blocking IO)
package org.zodiac.sdk.simplenetty.concurrent;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.zodiac.sdk.simplenetty.channel.Channel;
import org.zodiac.sdk.simplenetty.core.EventExecutor;
import org.zodiac.sdk.simplenetty.listener.Listener;
import org.zodiac.sdk.simplenetty.listener.ListenerWrapper;
public abstract class AbstractChannelFuture extends AbstractFuture implements ChannelFuture {
protected Channel channel;
protected TreeSet listeners;
public AbstractChannelFuture(EventExecutor executor, Channel channel, boolean isCancellable) {
super(executor, isCancellable);
FutureHolder.put(executor, this);
listeners = new TreeSet<>();
this.channel = channel;
}
@Override
public Channel channel() {
return channel;
}
@Override
public boolean isCancellable() {
return isCancellable;
}
@Override
public ChannelFuture addListener(Listener listener, int op) {
listeners.add(new ListenerWrapper(listener, op));
return this;
}
@Override
public ChannelFuture addListeners(Map, Integer> listeners) {
listeners.forEach((l, op) -> {
this.listeners.add(new ListenerWrapper(l, op));
});
return this;
}
@Override
public ChannelFuture removeListener(Listener listener) {
listeners.remove(listener);
return this;
}
@Override
public ChannelFuture removeListeners(List> listeners) {
this.listeners.removeAll(listeners);
return this;
}
@Override
public Throwable cause() {
return super.cause();
}
@Override
public ChannelFuture sync() throws InterruptedException {
super.sync();
return this;
}
@Override
public ChannelFuture syncUninterruptibly() {
super.syncUninterruptibly();
return this;
}
@Override
public ChannelFuture await() throws InterruptedException {
super.await();
return this;
}
@Override
public ChannelFuture awaitUninterruptibly() {
super.awaitUninterruptibly();
return this;
}
@Override
public boolean await(long timeout, TimeUnit timeUnit) throws InterruptedException {
return super.await(timeout, timeUnit);
}
@Override
public boolean awaitUninterruptibly(long timeout, TimeUnit timeUnit) {
return super.awaitUninterruptibly(timeout, timeUnit);
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return super.cancel(mayInterruptIfRunning);
}
@Override
public boolean isCancelled() {
return super.isCancelled();
}
@Override
public boolean isDone() {
return super.isDone();
}
@Override
public V get() throws InterruptedException, ExecutionException {
return super.get();
}
@Override
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return super.get(timeout, unit);
}
public void fireListen() {
listeners.forEach(item -> item.listen(this));
}
}