Search in sources :

Example 11 with ProtobaseFutureImpl

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

the class Test404 method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "22";
    LoggerFactory.configure();
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    ServerConfiguration configuration = new ServerConfiguration(8300);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandle);
    context.setProtocolFactory(new ParamedProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    ProtobaseFuture future = session.request(serviceKey, null);
    System.out.println(future.getReadText());
    Future future1 = new ProtobaseFutureImpl(connector.getContext()).setPING();
    session.getSession().flush(future1);
    CloseUtil.close(connector);
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) FixedSession(com.generallycloud.baseio.container.FixedSession) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) ParamedProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 12 with ProtobaseFutureImpl

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

the class TestBeat method main.

public static void main(String[] args) throws Exception {
    DebugUtil.setEnableDebug(true);
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            DebugUtil.debug("______________" + future.getReadText());
        }
    };
    String serviceKey = "TestSimpleServlet";
    ServerConfiguration configuration = new ServerConfiguration(18300);
    configuration.setSERVER_SESSION_IDLE_TIME(10);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.addSessionIdleEventListener(new SocketSessionActiveSEListener());
    context.setBeatFutureFactory(new ProtobaseBeatFutureFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    SocketSession session = connector.connect();
    String param = "tttt";
    long old = System.currentTimeMillis();
    for (int i = 0; i < 5; i++) {
        Future future = new ProtobaseFutureImpl(context, serviceKey);
        future.write(param);
        session.flush(future);
        ThreadUtil.sleep(300);
    }
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    Thread.sleep(2000);
    CloseUtil.close(connector);
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) ProtobaseBeatFutureFactory(com.generallycloud.baseio.codec.protobase.future.ProtobaseBeatFutureFactory) SocketSession(com.generallycloud.baseio.component.SocketSession) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) Future(com.generallycloud.baseio.protocol.Future) SocketSessionActiveSEListener(com.generallycloud.baseio.component.SocketSessionActiveSEListener)

Aggregations

ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)12 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)10 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)8 SocketSession (com.generallycloud.baseio.component.SocketSession)8 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)7 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)7 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)7 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)7 Future (com.generallycloud.baseio.protocol.Future)7 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)6 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)6 JSONObject (com.alibaba.fastjson.JSONObject)1 BalanceClientSocketSession (com.generallycloud.baseio.balance.BalanceClientSocketSession)1 BalanceClientSocketSessionFactory (com.generallycloud.baseio.balance.BalanceClientSocketSessionFactory)1 ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)1 ByteBufAllocator (com.generallycloud.baseio.buffer.ByteBufAllocator)1 ParamedProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)1 ParamedProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)1 ProtobaseBeatFutureFactory (com.generallycloud.baseio.codec.protobase.future.ProtobaseBeatFutureFactory)1 ProtobufUtil (com.generallycloud.baseio.codec.protobuf.ProtobufUtil)1