Search in sources :

Example 1 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class ServerPacketDecoder method decodeSessionSendMessage.

private SessionSendMessage decodeSessionSendMessage(final ActiveMQBuffer in, CoreRemotingConnection connection) {
    final SessionSendMessage sendMessage;
    if (connection.isVersionBeforeAddressChange()) {
        sendMessage = new SessionSendMessage_1X(new CoreMessage(this.coreMessageObjectPools));
    } else {
        sendMessage = new SessionSendMessage(new CoreMessage(this.coreMessageObjectPools));
    }
    sendMessage.decode(in);
    return sendMessage;
}
Also used : SessionSendMessage_1X(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage_1X) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 2 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class JMSBridgeReconnectionTest method pause.

public static void pause(Packet packet) {
    if (packet.getType() == PacketImpl.SESS_SEND) {
        SessionSendMessage sendMessage = (SessionSendMessage) packet;
        if (sendMessage.getMessage().containsProperty("__AMQ_CID") && count < 0 && !stopped) {
            try {
                activeMQServer.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
            stopped = true;
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            stopLatch.countDown();
        }
    }
}
Also used : SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage)

Example 3 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class ServerSessionPacketHandler method onSessionSend.

private void onSessionSend(Packet packet) {
    this.storageManager.setContext(session.getSessionContext());
    try {
        Packet response = null;
        boolean requiresResponse = false;
        try {
            final SessionSendMessage message = (SessionSendMessage) packet;
            requiresResponse = message.isRequiresResponse();
            this.session.send(EmbedMessageUtil.extractEmbedded(message.getMessage()), this.direct);
            if (requiresResponse) {
                response = new NullResponseMessage();
            }
        } catch (ActiveMQIOErrorException e) {
            response = onActiveMQIOErrorExceptionWhileHandlePacket(e, requiresResponse, response, this.session);
        } catch (ActiveMQXAException e) {
            response = onActiveMQXAExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQQueueMaxConsumerLimitReached e) {
            response = onActiveMQQueueMaxConsumerLimitReachedWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQException e) {
            response = onActiveMQExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (Throwable t) {
            response = onCatchThrowableWhileHandlePacket(t, requiresResponse, response, this.session);
        }
        sendResponse(packet, response, false, false);
    } finally {
        this.storageManager.clearContext();
    }
}
Also used : ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) NullResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.NullResponseMessage) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQQueueMaxConsumerLimitReached(org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)

Example 4 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class MessageImplTest method internalMessageCopy.

private void internalMessageCopy() throws Exception {
    final long RUNS = 2;
    final CoreMessage msg = new CoreMessage(123, 18);
    msg.setMessageID(RandomUtil.randomLong());
    msg.setAddress(new SimpleString("Batatantkashf aksjfh aksfjh askfdjh askjfh "));
    final AtomicInteger errors = new AtomicInteger(0);
    int T1_number = 10;
    int T2_number = 10;
    final CountDownLatch latchAlign = new CountDownLatch(T1_number + T2_number);
    final CountDownLatch latchReady = new CountDownLatch(1);
    class T1 extends Thread {

        @Override
        public void run() {
            latchAlign.countDown();
            try {
                latchReady.await();
            } catch (Exception ignored) {
            }
            for (int i = 0; i < RUNS; i++) {
                try {
                    Message newMsg = msg.copy();
                } catch (Throwable e) {
                    e.printStackTrace();
                    errors.incrementAndGet();
                }
            }
        }
    }
    final String bigString;
    {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < 500; i++) {
            buffer.append(" ");
        }
        bigString = buffer.toString();
    }
    class T2 extends Thread {

        @Override
        public void run() {
            latchAlign.countDown();
            try {
                latchReady.await();
            } catch (Exception ignored) {
            }
            for (int i = 0; i < RUNS; i++) {
                ActiveMQBuffer buf = null;
                try {
                    SessionSendMessage ssm = new SessionSendMessage(msg);
                    buf = ssm.encode(null);
                    simulateRead(buf);
                } catch (Throwable e) {
                    e.printStackTrace();
                    errors.incrementAndGet();
                } finally {
                    if (buf != null) {
                        buf.release();
                    }
                }
            }
        }
    }
    ArrayList<Thread> threads = new ArrayList<>();
    for (int i = 0; i < T1_number; i++) {
        T1 t = new T1();
        threads.add(t);
        t.start();
    }
    for (int i = 0; i < T2_number; i++) {
        T2 t2 = new T2();
        threads.add(t2);
        t2.start();
    }
    latchAlign.await();
    latchReady.countDown();
    for (Thread t : threads) {
        t.join();
    }
    Assert.assertEquals(0, errors.get());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 5 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class CoreMessageTest method sendThroughPackets.

/**
 * The message is received, then sent to the other side untouched
 */
@Test
public void sendThroughPackets() {
    CoreMessage decodedMessage = decodeMessage();
    int encodeSize = decodedMessage.getEncodeSize();
    Assert.assertEquals(BYTE_ENCODE.capacity(), encodeSize);
    SessionSendMessage sendMessage = new SessionSendMessage(decodedMessage, true, null);
    sendMessage.setChannelID(777);
    ActiveMQBuffer buffer = sendMessage.encode(null);
    byte[] byteArray = buffer.byteBuf().array();
    System.out.println("Sending " + ByteUtil.bytesToHex(buffer.toByteBuffer().array(), 1) + ", bytes = " + byteArray.length);
    buffer.readerIndex(5);
    SessionSendMessage sendMessageReceivedSent = new SessionSendMessage(new CoreMessage());
    sendMessageReceivedSent.decode(buffer);
    Assert.assertEquals(encodeSize, sendMessageReceivedSent.getMessage().getEncodeSize());
    Assert.assertTrue(sendMessageReceivedSent.isRequiresResponse());
    Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(sendMessageReceivedSent.getMessage().getReadOnlyBodyBuffer()).toString());
}
Also used : SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

SessionSendMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)2 Message (org.apache.activemq.artemis.api.core.Message)2 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)1 ActiveMQQueueMaxConsumerLimitReached (org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1