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);
}
}
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);
}
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();
}
}
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);
}
}
Aggregations