Search in sources :

Example 16 with ProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.

the class TestSimple method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "/test-simple";
    String param = "ttt";
    IoEventHandleAdaptor eventHandle = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            System.out.println("________________________" + future.getReadText());
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setIoEventHandleAdaptor(eventHandle);
    SocketSession session = connector.connect();
    ProtobaseFuture f = new ProtobaseFutureImpl(connector.getContext(), serviceKey);
    f.write(param);
    session.flush(f);
    ThreadUtil.sleep(500);
    CloseUtil.close(connector);
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 17 with ProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.

the class SimpleTestProtobaseClient method main.

public static void main(String[] args) throws Exception {
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            System.out.println();
            System.out.println("____________________" + future.getReadText());
            System.out.println();
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration("localhost", 18300));
    context.getServerConfiguration().setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    connector.setTimeout(99999999);
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    SocketSession session = connector.connect();
    ProtobaseFuture future = new ProtobaseFutureImpl(context, "test222");
    future.write("hello server!");
    session.flush(future);
    ThreadUtil.sleep(100);
    CloseUtil.close(connector);
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 18 with ProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.

the class TestTransaction method main.

public static void main(String[] args) throws Exception {
    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 ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    session.login("admin", "admin100");
    MessageConsumer consumer = new DefaultMessageConsumer(session);
    rollback(consumer);
    // commit(consumer);
    connector.close();
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) DefaultMessageConsumer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer) MessageConsumer(com.generallycloud.baseio.container.jms.client.MessageConsumer) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) DefaultMessageConsumer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 19 with ProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory 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)

Example 20 with ProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory in project baseio by generallycloud.

the class TestDownload method main.

public static void main(String[] args) throws Exception {
    String serviceName = "TestDownloadServlet";
    String fileName = "upload-flashmail-2.4.exe";
    JSONObject j = new JSONObject();
    j.put(FileReceiveUtil.FILE_NAME, fileName);
    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 ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    connector.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
    FixedSession session = new FixedSession(connector.connect());
    final FileReceiveUtil fileReceiveUtil = new FileReceiveUtil("download-");
    session.listen(serviceName, new OnFuture() {

        @Override
        public void onResponse(SocketSession session, Future future) {
            try {
                fileReceiveUtil.accept(session, (ParamedProtobaseFuture) future, false);
            } catch (Exception e) {
                DebugUtil.debug(e);
            }
        }
    });
    long old = System.currentTimeMillis();
    session.write(serviceName, j.toJSONString());
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    ThreadUtil.sleep(5000);
    CloseUtil.close(connector);
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) OnFuture(com.generallycloud.baseio.container.OnFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) 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) JSONObject(com.alibaba.fastjson.JSONObject) SocketSession(com.generallycloud.baseio.component.SocketSession) FileReceiveUtil(com.generallycloud.baseio.container.FileReceiveUtil) Future(com.generallycloud.baseio.protocol.Future) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture) OnFuture(com.generallycloud.baseio.container.OnFuture) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)

Aggregations

ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)28 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)28 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)27 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)27 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)26 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)25 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)15 SocketSession (com.generallycloud.baseio.component.SocketSession)15 FixedSession (com.generallycloud.baseio.container.FixedSession)15 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)15 Future (com.generallycloud.baseio.protocol.Future)15 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)12 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)6 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)5 DefaultMessageConsumer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer)5 Message (com.generallycloud.baseio.container.jms.Message)4 OnMessage (com.generallycloud.baseio.container.jms.client.OnMessage)4 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)2 ProtobaseBeatFutureFactory (com.generallycloud.baseio.codec.protobase.future.ProtobaseBeatFutureFactory)2 ProtobufUtil (com.generallycloud.baseio.codec.protobuf.ProtobufUtil)2