Search in sources :

Example 1 with TextByteMessage

use of com.generallycloud.baseio.container.jms.TextByteMessage 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 2 with TextByteMessage

use of com.generallycloud.baseio.container.jms.TextByteMessage 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 3 with TextByteMessage

use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.

the class FixedMessageConsumer method onReceive.

@Override
public void onReceive(Message message) {
    int msgType = message.getMsgType();
    if (Message.TYPE_MAP == msgType) {
        MapMessage m = (MapMessage) message;
        String eventName = m.getParameter("eventName");
        OnMappedMessage onMessage = onMappedMessages.get(eventName);
        if (onMessage == null) {
            return;
        }
        onMessage.onReceive(m);
    } else if (Message.TYPE_MAP_BYTE == msgType) {
        MapByteMessage m = (MapByteMessage) message;
        String eventName = m.getParameter("eventName");
        OnMappedMessage onMessage = onMappedMessages.get(eventName);
        if (onMessage == null) {
            return;
        }
        onMessage.onReceive(m);
    } else if (Message.TYPE_TEXT == msgType) {
        if (onTextMessage != null) {
            onTextMessage.onReceive((TextMessage) message);
        }
    } else if (Message.TYPE_TEXT_BYTE == msgType) {
        if (onTextByteMessage != null) {
            onTextByteMessage.onReceive((TextByteMessage) message);
        }
    } else if (Message.TYPE_ERROR == msgType) {
        if (onErrorMessage != null) {
            onErrorMessage.onReceive((ErrorMessage) message);
        }
    } else if (Message.TYPE_NULL == msgType) {
        if (onNullMessage != null) {
            onNullMessage.onReceive((NullMessage) message);
        }
    }
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) NullMessage(com.generallycloud.baseio.container.jms.NullMessage) MapMessage(com.generallycloud.baseio.container.jms.MapMessage) MapByteMessage(com.generallycloud.baseio.container.jms.MapByteMessage)

Example 4 with TextByteMessage

use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.

the class TextByteMessageDecoder method decode.

@Override
public Message decode(ParamedProtobaseFuture future) {
    Parameters param = future.getParameters();
    String messageId = param.getParameter("msgId");
    String queueName = param.getParameter("queueName");
    String text = param.getParameter("text");
    byte[] array = future.getReadBinary();
    return new TextByteMessage(messageId, queueName, text, array);
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) Parameters(com.generallycloud.baseio.component.Parameters)

Example 5 with TextByteMessage

use of com.generallycloud.baseio.container.jms.TextByteMessage in project baseio by generallycloud.

the class MQBrowserServlet method doAccept.

@Override
public void doAccept(SocketSession session, ParamedProtobaseFuture future, MQSessionAttachment attachment) throws Exception {
    Parameters param = future.getParameters();
    String messageId = param.getParameter("messageId");
    Message message = NullMessage.NULL_MESSAGE;
    MQContext context = getMQContext();
    String cmd = param.getParameter("cmd");
    if (StringUtil.isNullOrBlank(cmd)) {
        message = ErrorMessage.CMD_NOT_FOUND_MESSAGE;
    } else {
        if (SIZE.equals(cmd)) {
            future.write(String.valueOf(context.messageSize()));
        } else if (BROWSER.equals(cmd)) {
            if (!StringUtil.isNullOrBlank(messageId)) {
                message = context.browser(messageId);
                if (message == null) {
                    message = NullMessage.NULL_MESSAGE;
                    future.write(message.toString());
                } else {
                    int msgType = message.getMsgType();
                    String content = message.toString();
                    future.write(content);
                    if (msgType == 3) {
                        TextByteMessage byteMessage = (TextByteMessage) message;
                        byte[] bytes = byteMessage.getByteArray();
                        future.writeBinary(bytes);
                    }
                }
            }
        } else if (ONLINE.equals(cmd)) {
            boolean bool = context.isOnLine(param.getParameter("queueName"));
            future.write(String.valueOf(bool));
        }
    }
    session.flush(future);
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) Parameters(com.generallycloud.baseio.component.Parameters) ErrorMessage(com.generallycloud.baseio.container.jms.ErrorMessage) NullMessage(com.generallycloud.baseio.container.jms.NullMessage) TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) Message(com.generallycloud.baseio.container.jms.Message)

Aggregations

TextByteMessage (com.generallycloud.baseio.container.jms.TextByteMessage)5 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)2 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)2 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)2 Parameters (com.generallycloud.baseio.component.Parameters)2 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)2 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)2 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)2 FixedSession (com.generallycloud.baseio.container.FixedSession)2 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)2 Message (com.generallycloud.baseio.container.jms.Message)2 NullMessage (com.generallycloud.baseio.container.jms.NullMessage)2 ErrorMessage (com.generallycloud.baseio.container.jms.ErrorMessage)1 MapByteMessage (com.generallycloud.baseio.container.jms.MapByteMessage)1 MapMessage (com.generallycloud.baseio.container.jms.MapMessage)1 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)1 MessageProducer (com.generallycloud.baseio.container.jms.client.MessageProducer)1 OnMessage (com.generallycloud.baseio.container.jms.client.OnMessage)1 DefaultMessageConsumer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer)1 DefaultMessageProducer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer)1