Search in sources :

Example 1 with ChannelFuture

use of com.generallycloud.baseio.protocol.ChannelFuture in project baseio by generallycloud.

the class AioSocketSessionManager method broadcast.

@Override
public void broadcast(Future future) throws IOException {
    if (getManagedSessionSize() == 0) {
        return;
    }
    SocketChannel channel = context.getSimulateSocketChannel();
    ChannelFuture f = (ChannelFuture) future;
    context.getProtocolEncoder().encode(channel, f);
    broadcastChannelFuture(f);
}
Also used : ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture)

Example 2 with ChannelFuture

use of com.generallycloud.baseio.protocol.ChannelFuture in project baseio by generallycloud.

the class AbstractSocketChannel method releaseFutures.

protected void releaseFutures() {
    ReleaseUtil.release(readFuture);
    ReleaseUtil.release(sslReadFuture);
    ClosedChannelException e = null;
    if (writeFuture != null && !writeFuture.isReleased()) {
        e = new ClosedChannelException(session.toString());
        onFutureException(writeFuture, e);
    }
    LinkedQueue<ChannelFuture> writeFutures = this.writeFutures;
    if (writeFutures.size() == 0) {
        return;
    }
    ChannelFuture f = writeFutures.poll();
    UnsafeSocketSession session = this.session;
    if (e == null) {
        e = new ClosedChannelException(session.toString());
    }
    for (; f != null; ) {
        onFutureException(f, e);
        ReleaseUtil.release(f);
        f = writeFutures.poll();
    }
}
Also used : DefaultChannelFuture(com.generallycloud.baseio.protocol.DefaultChannelFuture) ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture) ClosedChannelException(com.generallycloud.baseio.ClosedChannelException)

Example 3 with ChannelFuture

use of com.generallycloud.baseio.protocol.ChannelFuture in project baseio by generallycloud.

the class NioGlobalSocketSessionManager method broadcast.

@Override
public void broadcast(Future future) throws IOException {
    if (getManagedSessionSize() == 0) {
        return;
    }
    SocketChannel channel = context.getSimulateSocketChannel();
    ChannelFuture f = (ChannelFuture) future;
    context.getProtocolEncoder().encode(channel, f);
    broadcastChannelFuture(f);
}
Also used : ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture)

Example 4 with ChannelFuture

use of com.generallycloud.baseio.protocol.ChannelFuture in project baseio by generallycloud.

the class NioSocketChannel method flush.

protected void flush(SocketSelectorEventLoop selectorLoop) throws IOException {
    ChannelFuture f = writeFuture;
    if (f == null) {
        f = writeFutures.poll();
    }
    if (f == null) {
        return;
    }
    for (; ; ) {
        try {
            f.write(this);
        } catch (Throwable e) {
            writeFuture = null;
            ReleaseUtil.release(f);
            throw e;
        }
        if (!f.isWriteCompleted()) {
            writeFuture = f;
            interestWrite(selectionKey);
            return;
        }
        writeFutureLength(-f.getByteBufLimit());
        ReleaseUtil.release(f);
        f = writeFutures.poll();
        if (f == null) {
            break;
        }
    }
    interestRead(selectionKey);
    writeFuture = null;
}
Also used : ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture)

Example 5 with ChannelFuture

use of com.generallycloud.baseio.protocol.ChannelFuture in project baseio by generallycloud.

the class TransparentByteBufReader method accept.

@Override
public void accept(SocketChannel channel, ByteBuf buffer) throws Exception {
    for (; ; ) {
        if (!buffer.hasRemaining()) {
            return;
        }
        ChannelFuture future = channel.getReadFuture();
        boolean setFutureNull = true;
        if (future == null) {
            future = channel.getProtocolDecoder().decode(channel, buffer);
            setFutureNull = false;
        }
        try {
            if (!future.read(channel, buffer)) {
                if (!setFutureNull) {
                    channel.setReadFuture(future);
                }
                return;
            }
        } catch (Throwable e) {
            ReleaseUtil.release(future);
            if (e instanceof IOException) {
                throw (IOException) e;
            }
            throw new IOException("exception occurred when do decode," + e.getMessage(), e);
        }
        if (setFutureNull) {
            channel.setReadFuture(null);
        }
        ReleaseUtil.release(future);
        foreReadFutureAcceptor.accept(channel.getSession(), future);
    }
}
Also used : ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture) IOException(java.io.IOException)

Aggregations

ChannelFuture (com.generallycloud.baseio.protocol.ChannelFuture)9 IOException (java.io.IOException)2 ClosedChannelException (com.generallycloud.baseio.ClosedChannelException)1 ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)1 FixedUnpooledByteBuf (com.generallycloud.baseio.buffer.FixedUnpooledByteBuf)1 DefaultChannelFuture (com.generallycloud.baseio.protocol.DefaultChannelFuture)1 Future (com.generallycloud.baseio.protocol.Future)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1