Search in sources :

Example 6 with ChannelFuture

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

the class AbstractFutureAcceptor method acceptHeartBeat.

private void acceptHeartBeat(final SocketSession session, final ChannelFuture future) {
    if (future.isPING()) {
        heartBeatLogger.logRequest(session);
        SocketChannelContext context = session.getContext();
        BeatFutureFactory factory = context.getBeatFutureFactory();
        if (factory == null) {
            RuntimeException e = new RuntimeException("none factory of BeatFuture");
            CloseUtil.close(session);
            logger.error(e.getMessage(), e);
            return;
        }
        Future f = factory.createPONGPacket(session);
        session.flush(f);
    } else {
        heartBeatLogger.logResponse(session);
    }
}
Also used : ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture) Future(com.generallycloud.baseio.protocol.Future)

Example 7 with ChannelFuture

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

the class AbstractFutureAcceptor method accept.

@Override
public void accept(final SocketSession session, final Future future) throws Exception {
    ChannelFuture f = (ChannelFuture) future;
    if (f.isSilent()) {
        return;
    }
    if (f.isHeartbeat()) {
        acceptHeartBeat(session, f);
        return;
    }
    SocketChannelContext context = session.getContext();
    IoEventHandle eventHandle = context.getIoEventHandleAdaptor();
    accept(eventHandle, session, f);
}
Also used : ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture)

Example 8 with ChannelFuture

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

the class AioSocketChannel method writeCallback.

// FIXME __hebing
protected void writeCallback(int length) {
    ReentrantLock lock = getCloseLock();
    lock.lock();
    try {
        if (!isOpened()) {
            return;
        }
        ChannelFuture f = this.writeFuture;
        f.getByteBuf().reverse();
        if (!f.isWriteCompleted()) {
            flush(true);
            return;
        }
        writeFutureLength(-f.getByteBufLimit());
        ReleaseUtil.release(f);
        writeFuture = null;
        flush(true);
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ChannelFuture(com.generallycloud.baseio.protocol.ChannelFuture)

Example 9 with ChannelFuture

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

the class TransparentByteBufReader2 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,temporary.clear());
            setFutureNull = false;
        }
        try {
            if (!future.read(channel, buffer)) {
                if (!setFutureNull) {
                    if (future.getByteBuf() == this.temporary) {
                        ByteBuf src = future.getByteBuf();
                        ByteBuf buf = allocate(channel, src.limit());
                        buf.read(src.flip());
                        future.setByteBuf(buf);
                    }
                    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) FixedUnpooledByteBuf(com.generallycloud.baseio.buffer.FixedUnpooledByteBuf) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf)

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