Search in sources :

Example 1 with ParamedProtobaseFutureImpl

use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl in project baseio by generallycloud.

the class FixedSession method request.

public ParamedProtobaseFuture request(String serviceName, String content, byte[] binary) throws IOException {
    ParamedProtobaseFuture future = new ParamedProtobaseFutureImpl(context, serviceName);
    if (!StringUtil.isNullOrBlank(content)) {
        future.write(content);
    }
    if (binary != null) {
        future.writeBinary(binary);
    }
    WaiterOnFuture onReadFuture = new WaiterOnFuture();
    waiterListen(serviceName, onReadFuture);
    session.flush(future);
    // FIXME 连接丢失时叫醒我
    if (onReadFuture.await(timeout)) {
        CloseUtil.close(session);
        throw new TimeoutException("timeout");
    }
    return (ParamedProtobaseFuture) onReadFuture.getReadFuture();
}
Also used : ParamedProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture) TimeoutException(com.generallycloud.baseio.TimeoutException)

Example 2 with ParamedProtobaseFutureImpl

use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl in project baseio by generallycloud.

the class ParamedProtobaseProtocolDecoder method decode.

@Override
public ChannelFuture decode(SocketChannel channel, ByteBuf buffer) throws IOException {
    ByteBufAllocator allocator = channel.getByteBufAllocator();
    ByteBuf buf = allocator.allocate(2);
    return new ParamedProtobaseFutureImpl(channel, buf);
}
Also used : ByteBufAllocator(com.generallycloud.baseio.buffer.ByteBufAllocator) ParamedProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf)

Example 3 with ParamedProtobaseFutureImpl

use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl in project baseio by generallycloud.

the class FixedSession method write.

public void write(String serviceName, String content, byte[] binary) throws IOException {
    ParamedProtobaseFuture future = new ParamedProtobaseFutureImpl(context, serviceName);
    if (!StringUtil.isNullOrBlank(content)) {
        future.write(content);
    }
    if (binary != null) {
        future.writeBinary(binary);
    }
    session.flush(future);
}
Also used : ParamedProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)

Aggregations

ParamedProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl)3 ParamedProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)2 TimeoutException (com.generallycloud.baseio.TimeoutException)1 ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)1 ByteBufAllocator (com.generallycloud.baseio.buffer.ByteBufAllocator)1