Search in sources :

Example 16 with NioSocketChannelContext

use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.

the class TestListenerPower 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);
    long old = System.currentTimeMillis();
    OnMessage onMessage = new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    };
    for (int i = 0; i < 10000; i++) {
        consumer.receive(onMessage);
    }
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    connector.close();
}
Also used : 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) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) Message(com.generallycloud.baseio.container.jms.Message) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) DefaultMessageConsumer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) 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)

Example 17 with NioSocketChannelContext

use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.

the class TestTellerByteMessage method main.

public static void main(String[] args) throws Exception {
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(8300));
    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");
    MessageProducer producer = new DefaultMessageProducer(session);
    TextByteMessage message = new TextByteMessage("msgId", "uuid", "============", "你好!".getBytes(session.getContext().getEncoding()));
    long old = System.currentTimeMillis();
    for (int i = 0; i < 5; i++) {
        producer.offer(message);
    }
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    connector.close();
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) DefaultMessageProducer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) 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) DefaultMessageProducer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer) MessageProducer(com.generallycloud.baseio.container.jms.client.MessageProducer)

Example 18 with NioSocketChannelContext

use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.

the class BalanceServerBootStrap method getBalanceReverseChannelContext.

private SocketChannelContext getBalanceReverseChannelContext(BalanceContext balanceContext, ServerConfiguration configuration, ProtocolFactory protocolFactory) {
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    // SocketChannelContext context = new AioSocketChannelContext(configuration);
    context.setIoEventHandleAdaptor(balanceContext.getBalanceReverseAcceptorHandler());
    context.addSessionEventListener(balanceContext.getBalanceReverseAcceptorSEListener());
    context.setProtocolFactory(protocolFactory);
    context.setBeatFutureFactory(balanceReverseBeatFutureFactory);
    if (balanceReverseSessionEventListeners != null) {
        addSessionEventListener2Context(context, balanceReverseSessionEventListeners);
    }
    if (balanceReverseSessionIdleEventListeners != null) {
        addSessionIdleEventListener2Context(context, balanceReverseSessionIdleEventListeners);
    }
    return context;
}
Also used : NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 19 with NioSocketChannelContext

use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.

the class BalanceServerBootStrap method getBalanceChannelContext.

private SocketChannelContext getBalanceChannelContext(BalanceContext balanceContext, ServerConfiguration configuration, ProtocolFactory protocolFactory) {
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    // SocketChannelContext context = new AioSocketChannelContext(configuration);
    context.setIoEventHandleAdaptor(balanceContext.getBalanceFacadeAcceptorHandler());
    context.addSessionEventListener(balanceContext.getBalanceFacadeAcceptorSEListener());
    context.setProtocolFactory(protocolFactory);
    context.setBeatFutureFactory(balanceBeatFutureFactory);
    if (balanceSessionEventListeners != null) {
        addSessionEventListener2Context(context, balanceSessionEventListeners);
    }
    if (balanceSessionIdleEventListeners != null) {
        addSessionIdleEventListener2Context(context, balanceSessionIdleEventListeners);
    }
    if (sslContext != null) {
        context.setSslContext(sslContext);
    }
    return context;
}
Also used : NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 20 with NioSocketChannelContext

use of com.generallycloud.baseio.component.NioSocketChannelContext in project baseio by generallycloud.

the class TestProtobufClient 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 res = (SearchRequest) protobufUtil.getMessage(f);
            System.out.println();
            System.out.println("________" + res);
            System.out.println();
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    // context.addSessionEventListener(new SessionActiveSEListener());
    // context.setBeatFutureFactory(new FLBeatFutureFactory());
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    SocketSession session = connector.connect();
    ProtobaseFuture f = new ProtobaseFutureImpl(context);
    ByteString byteString = ByteString.copyFrom("222".getBytes());
    SearchRequest request = SearchRequest.newBuilder().setCorpus(Corpus.IMAGES).setPageNumber(100).setQuery("test").setQueryBytes(byteString).setResultPerPage(-1).build();
    protobufUtil.writeProtobuf(request, f);
    session.flush(f);
    ThreadUtil.sleep(100);
    CloseUtil.close(connector);
}
Also used : SearchRequest(com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ByteString(com.google.protobuf.ByteString) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) ProtobufUtil(com.generallycloud.baseio.codec.protobuf.ProtobufUtil) 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) 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)

Aggregations

NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)56 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)54 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)54 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)51 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)40 SocketSession (com.generallycloud.baseio.component.SocketSession)33 Future (com.generallycloud.baseio.protocol.Future)31 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)27 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)26 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)11 FixedLengthProtocolFactory (com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory)11 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