org.apache.activemq.artemis.core.server.RoutingContext

Here are the examples of the java api class org.apache.activemq.artemis.core.server.RoutingContext taken from open source projects.

1. PageCursorStressTest#pgMessages()

Project: activemq-artemis
File: PageCursorStressTest.java
/**
    * @param storage
    * @param pageStore
    * @param pgParameter
    * @param start
    * @param NUM_MESSAGES
    * @param messageSize
    * @throws Exception
    */
private Transaction pgMessages(StorageManager storage, PagingStoreImpl pageStore, long pgParameter, int start, final int NUM_MESSAGES, final int messageSize) throws Exception {
    TransactionImpl txImpl = new TransactionImpl(pgParameter, null, storage);
    RoutingContext ctx = generateCTX(txImpl);
    for (int i = start; i < start + NUM_MESSAGES; i++) {
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        ServerMessage msg = new ServerMessageImpl(storage.generateID(), buffer.writerIndex());
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        msg.putIntProperty("key", i);
        pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock);
    }
    return txImpl;
}

2. PageCursorStressTest#addMessages()

Project: activemq-artemis
File: PageCursorStressTest.java
private int addMessages(final int start, final int numMessages, final int messageSize) throws Exception {
    PagingStoreImpl pageStore = lookupPageStore(ADDRESS);
    pageStore.startPaging();
    RoutingContext ctx = generateCTX();
    for (int i = start; i < start + numMessages; i++) {
        if (i % 100 == 0)
            System.out.println("Paged " + i);
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        ServerMessage msg = new ServerMessageImpl(i, buffer.writerIndex());
        msg.putIntProperty("key", i);
        // to be used on tests that are validating filters
        msg.putBooleanProperty("even", i % 2 == 0);
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        Assert.assertTrue(pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock));
    }
    return pageStore.getNumberOfPages();
}

3. QueueImpl#moveBetweenSnFQueues()

Project: activemq-artemis
File: QueueImpl.java
@SuppressWarnings({ "ArrayToString", "ArrayToStringConcatentation" })
private void moveBetweenSnFQueues(final SimpleString queueSuffix, final Transaction tx, final MessageReference ref) throws Exception {
    ServerMessage copyMessage = makeCopy(ref, false, false);
    byte[] oldRouteToIDs = null;
    String targetNodeID;
    Binding targetBinding;
    // remove the old route
    for (SimpleString propName : copyMessage.getPropertyNames()) {
        if (propName.startsWith(MessageImpl.HDR_ROUTE_TO_IDS)) {
            oldRouteToIDs = (byte[]) copyMessage.removeProperty(propName);
            // don't use Arrays.toString(..) here
            final String hashcodeToString = oldRouteToIDs.toString();
            logger.debug("Removed property from message: " + propName + " = " + hashcodeToString + " (" + ByteBuffer.wrap(oldRouteToIDs).getLong() + ")");
            // there should only be one of these properties so potentially save some loop iterations
            break;
        }
    }
    ByteBuffer oldBuffer = ByteBuffer.wrap(oldRouteToIDs);
    RoutingContext routingContext = new RoutingContextImpl(tx);
    /* this algorithm will look at the old route and find the new remote queue bindings where the messages should go
       * and route them there directly
       */
    while (oldBuffer.hasRemaining()) {
        long oldQueueID = oldBuffer.getLong();
        // look at all the bindings
        Pair<String, Binding> result = locateTargetBinding(queueSuffix, copyMessage, oldQueueID);
        targetBinding = result.getB();
        targetNodeID = result.getA();
        if (targetBinding == null) {
            ActiveMQServerLogger.LOGGER.unableToFindTargetQueue(targetNodeID);
        } else {
            logger.debug("Routing on binding: " + targetBinding);
            targetBinding.route(copyMessage, routingContext);
        }
    }
    postOffice.processRoute(copyMessage, routingContext, false);
    ref.handled();
    acknowledge(tx, ref);
    storageManager.afterCompleteOperations(new IOCallback() {

        @Override
        public void onError(final int errorCode, final String errorMessage) {
            ActiveMQServerLogger.LOGGER.ioErrorRedistributing(errorCode, errorMessage);
        }

        @Override
        public void done() {
            deliverAsync();
        }
    });
}