io.windmill.net.TransferTask Maven / Gradle / Ivy
package io.windmill.net;
import java.nio.channels.ClosedChannelException;
import java.util.Optional;
import io.windmill.core.Future;
import io.netty.buffer.ByteBuf;
public abstract class TransferTask implements AutoCloseable
{
protected final ByteBuf buffer;
protected final Optional> onComplete;
public TransferTask(ByteBuf buffer, Optional> onComplete)
{
this.buffer = buffer;
this.onComplete = onComplete;
}
public abstract boolean compute(I channel);
public Future getFuture()
{
return onComplete.isPresent() ? onComplete.get() : null;
}
@Override
public void close()
{
if (buffer != null)
buffer.release();
onComplete.ifPresent((f) -> f.setFailure(new ClosedChannelException()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy