Search in sources :

Example 1 with OnMessage

use of com.generallycloud.baseio.container.jms.client.OnMessage in project baseio by generallycloud.

the class TestTransaction method commit.

static void commit(MessageConsumer consumer) throws MQException {
    long old = System.currentTimeMillis();
    consumer.beginTransaction();
    consumer.receive(new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    });
    consumer.commit();
    System.out.println("Time:" + (System.currentTimeMillis() - old));
}
Also used : OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) Message(com.generallycloud.baseio.container.jms.Message) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage)

Example 2 with OnMessage

use of com.generallycloud.baseio.container.jms.client.OnMessage in project baseio by generallycloud.

the class TestListener method main.

public static void main(String[] args) throws Exception {
    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());
    session.login("admin", "admin100");
    MessageConsumer consumer = new DefaultMessageConsumer(session);
    long old = System.currentTimeMillis();
    consumer.receive(new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    });
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    ThreadUtil.sleep(1500000);
    CloseUtil.close(connector);
}
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) ParamedProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)

Example 3 with OnMessage

use of com.generallycloud.baseio.container.jms.client.OnMessage in project baseio by generallycloud.

the class TestListenerByteMessage 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");
    MessageConsumer consumer = new DefaultMessageConsumer(session);
    final long old = System.currentTimeMillis();
    consumer.receive(new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
            if (message.getMsgType() == Message.TYPE_TEXT_BYTE) {
                TextByteMessage _Message = (TextByteMessage) message;
                System.out.println(new String(_Message.getByteArray(), Encoding.UTF8));
            }
            System.out.println("Time:" + (System.currentTimeMillis() - old));
        }
    });
    ThreadUtil.sleep(30000000);
    connector.close();
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) 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) TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) 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 4 with OnMessage

use of com.generallycloud.baseio.container.jms.client.OnMessage in project baseio by generallycloud.

the class TestListenerCallBack 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);
    consumer.receive(new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    });
    ThreadUtil.sleep(1000);
    CloseUtil.close(connector);
}
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 5 with OnMessage

use of com.generallycloud.baseio.container.jms.client.OnMessage 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)

Aggregations

Message (com.generallycloud.baseio.container.jms.Message)7 OnMessage (com.generallycloud.baseio.container.jms.client.OnMessage)7 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)5 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)5 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)5 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)5 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)5 FixedSession (com.generallycloud.baseio.container.FixedSession)5 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)5 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)5 DefaultMessageConsumer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer)5 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)4 ParamedProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)1 TextByteMessage (com.generallycloud.baseio.container.jms.TextByteMessage)1