Search in sources :

Example 6 with ParamedProtobaseFuture

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

the class TestListenSimpleServlet method doAccept.

@Override
protected void doAccept(SocketSession session, ParamedProtobaseFuture future) throws Exception {
    String test = future.getReadText();
    if (StringUtil.isNullOrBlank(test)) {
        test = "test";
    }
    future.write(test);
    future.write("$");
    session.flush(future);
    for (int i = 0; i < 5; i++) {
        ProtobaseFuture f = new ProtobaseFutureImpl(session.getContext(), future.getFutureId(), future.getFutureName());
        f.write(test);
        f.write("$");
        session.flush(f);
    }
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)

Example 7 with ParamedProtobaseFuture

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

ParamedProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)7 JSONObject (com.alibaba.fastjson.JSONObject)3 TimeoutException (com.generallycloud.baseio.TimeoutException)2 ParamedProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl)2 MQException (com.generallycloud.baseio.container.jms.MQException)2 IOException (java.io.IOException)2 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)1 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)1 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)1 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)1 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)1 FileReceiveUtil (com.generallycloud.baseio.container.FileReceiveUtil)1 FixedSession (com.generallycloud.baseio.container.FixedSession)1 OnFuture (com.generallycloud.baseio.container.OnFuture)1 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)1 Authority (com.generallycloud.baseio.container.authority.Authority)1