Search in sources :

Example 26 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class PostOfficeImpl method sendQueueInfoToQueue.

@Override
public void sendQueueInfoToQueue(final SimpleString queueName, final SimpleString address) throws Exception {
    // We send direct to the queue so we can send it to the same queue that is bound to the notifications address -
    // this is crucial for ensuring
    // that queue infos and notifications are received in a contiguous consistent stream
    Binding binding = addressManager.getBinding(queueName);
    if (binding == null) {
        throw new IllegalStateException("Cannot find queue " + queueName);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("PostOffice.sendQueueInfoToQueue on server=" + this.server + ", queueName=" + queueName + " and address=" + address);
    }
    Queue queue = (Queue) binding.getBindable();
    // Need to lock to make sure all queue info and notifications are in the correct order with no gaps
    synchronized (notificationLock) {
        // First send a reset message
        Message message = new CoreMessage(storageManager.generateID(), 50);
        message.setAddress(queueName);
        message.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA, true);
        routeQueueInfo(message, queue, false);
        for (QueueInfo info : queueInfos.values()) {
            if (logger.isTraceEnabled()) {
                logger.trace("QueueInfo on sendQueueInfoToQueue = " + info);
            }
            if (info.matchesAddress(address)) {
                message = createQueueInfoMessage(CoreNotificationType.BINDING_ADDED, queueName);
                message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                message.putLongProperty(ManagementHelper.HDR_BINDING_ID, info.getID());
                message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, info.getFilterString());
                message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                routeQueueInfo(message, queue, true);
                int consumersWithFilters = info.getFilterStrings() != null ? info.getFilterStrings().size() : 0;
                for (int i = 0; i < info.getNumberOfConsumers() - consumersWithFilters; i++) {
                    message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
                    message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                    message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                    message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                    message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                    routeQueueInfo(message, queue, true);
                }
                if (info.getFilterStrings() != null) {
                    for (SimpleString filterString : info.getFilterStrings()) {
                        message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
                        message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                        message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                        message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                        message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
                        message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                        routeQueueInfo(message, queue, true);
                    }
                }
            }
        }
        Message completeMessage = new CoreMessage(storageManager.generateID(), 50);
        completeMessage.setAddress(queueName);
        completeMessage.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA_COMPLETE, true);
        routeQueueInfo(completeMessage, queue, false);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueInfo(org.apache.activemq.artemis.core.postoffice.QueueInfo) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 27 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class MemorySizeTest method testObjectSizes.

@Test
public void testObjectSizes() throws Exception {
    UnitTestLogger.LOGGER.info("Server message size is " + MemorySize.calculateSize(new MemorySize.ObjectFactory() {

        @Override
        public Object createObject() {
            return new CoreMessage(1, 1000);
        }
    }));
    UnitTestLogger.LOGGER.info("Message reference size is " + MemorySize.calculateSize(new MemorySize.ObjectFactory() {

        @Override
        public Object createObject() {
            return new MessageReferenceImpl();
        }
    }));
}
Also used : MemorySize(org.apache.activemq.artemis.utils.MemorySize) MessageReferenceImpl(org.apache.activemq.artemis.core.server.impl.MessageReferenceImpl) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Test(org.junit.Test)

Example 28 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage 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 29 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class CoreMessageTest method testPassThroughMultipleThreads.

@Test
public void testPassThroughMultipleThreads() throws Throwable {
    CoreMessage coreMessage = new CoreMessage();
    coreMessage.receiveBuffer(BYTE_ENCODE);
    LinkedList<Throwable> errors = new LinkedList<>();
    Thread[] threads = new Thread[50];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(() -> {
            try {
                for (int j = 0; j < 50; j++) {
                    Assert.assertEquals(ADDRESS, coreMessage.getAddressSimpleString());
                    Assert.assertEquals(PROP1_VALUE.toString(), coreMessage.getStringProperty(PROP1_NAME));
                    ByteBuf destinedBuffer = Unpooled.buffer(BYTE_ENCODE.array().length);
                    coreMessage.sendBuffer(destinedBuffer, 0);
                    byte[] destinedArray = destinedBuffer.array();
                    byte[] sourceArray = BYTE_ENCODE.array();
                    Assert.assertArrayEquals(sourceArray, destinedArray);
                    Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(coreMessage.getReadOnlyBodyBuffer()).toString());
                }
            } catch (Throwable e) {
                e.printStackTrace();
                errors.add(e);
            }
        });
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    for (Throwable e : errors) {
        throw e;
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 30 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class CoreMessageTest method testPassThrough.

/**
 * The message is received, then sent to the other side untouched
 */
@Test
public void testPassThrough() {
    CoreMessage decodedMessage = decodeMessage();
    Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(decodedMessage.getReadOnlyBodyBuffer()).toString());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Test(org.junit.Test)

Aggregations

CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)48 Test (org.junit.Test)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)16 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 Message (org.apache.activemq.artemis.api.core.Message)11 Configuration (org.apache.activemq.artemis.core.config.Configuration)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 ByteBuf (io.netty.buffer.ByteBuf)5 LinkedList (java.util.LinkedList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)3 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)3 RoutingContext (org.apache.activemq.artemis.core.server.RoutingContext)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)2 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)2