Search in sources :

Example 61 with ServerConfiguration

use of com.generallycloud.baseio.configuration.ServerConfiguration in project baseio by generallycloud.

the class TestUpload method main.

public static void main(String[] args) throws Exception {
    String serviceName = "/test-upload";
    IoEventHandleAdaptor eventHandle = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            ProtobaseFuture f = (ProtobaseFuture) future;
            System.out.println();
            System.out.println(f.getReadText());
            System.out.println();
            CloseUtil.close(connector);
        }
    };
    LoggerFactory.configure();
    ServerConfiguration configuration = new ServerConfiguration(8300);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandle);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    SocketSession session = connector.connect();
    String fileName = "lantern-installer-beta.exe";
    fileName = "content.rar";
    // fileName = "jdk-8u102-windows-x64.exe";
    File file = new File("c:/ryms/" + fileName);
    FileSendUtil fileSendUtil = new FileSendUtil();
    fileSendUtil.sendFile(session, serviceName, file, 1024 * 800);
    ThreadUtil.sleep(10000000);
}
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) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) FileSendUtil(com.generallycloud.baseio.container.FileSendUtil) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) File(java.io.File)

Example 62 with ServerConfiguration

use of com.generallycloud.baseio.configuration.ServerConfiguration in project baseio by generallycloud.

the class TestProtobufServer method main.

public static void main(String[] args) throws Exception {
    ProtobufUtil protobufUtil = new ProtobufUtil();
    protobufUtil.regist(SearchRequest.getDefaultInstance());
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            ProtobaseFuture f = (ProtobaseFuture) future;
            SearchRequest req = (SearchRequest) protobufUtil.getMessage(f);
            String message = "yes server already accept your message:\n" + req;
            System.out.println(message);
            SearchRequest res = SearchRequest.newBuilder().mergeFrom(req).setQuery("query_______").build();
            protobufUtil.writeProtobuf(res.getClass().getName(), res, f);
            session.flush(future);
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
    context.addSessionEventListener(new LoggerSocketSEListener());
    // context.addSessionEventListener(new SessionAliveSEListener());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    // context.setBeatFutureFactory(new NIOBeatFutureFactory());
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    acceptor.bind();
}
Also used : SearchRequest(com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) ProtobufUtil(com.generallycloud.baseio.codec.protobuf.ProtobufUtil) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) SocketChannelAcceptor(com.generallycloud.baseio.acceptor.SocketChannelAcceptor)

Aggregations

ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)62 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)55 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)54 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)53 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)41 SocketSession (com.generallycloud.baseio.component.SocketSession)35 Future (com.generallycloud.baseio.protocol.Future)33 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)29 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)28 FixedSession (com.generallycloud.baseio.container.FixedSession)21 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)21 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)16 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)12 FixedLengthProtocolFactory (com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory)12 FixedLengthFuture (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)7 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)7 FixedLengthFutureImpl (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl)6 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)6 DefaultMessageConsumer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer)6 ParamedProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)5