Search in sources :

Example 1 with ProducerState

use of org.apache.activemq.state.ProducerState in project activemq-artemis by apache.

the class OpenWireConnection method getProducerBrokerExchange.

private AMQProducerBrokerExchange getProducerBrokerExchange(ProducerId id) throws IOException {
    AMQProducerBrokerExchange result = producerExchanges.get(id);
    if (result == null) {
        synchronized (producerExchanges) {
            result = new AMQProducerBrokerExchange();
            result.setConnectionContext(context);
            // todo: this used to check for  && this.acceptorUsed.isAuditNetworkProducers()
            if (context.isReconnect() || (context.isNetworkConnection())) {
                // once implemented ARTEMIS-194, we need to set the storedSequenceID here somehow
                // We have different semantics on Artemis Journal, but we could adapt something for this
                // TBD during the implementation of ARTEMIS-194
                result.setLastStoredSequenceId(0);
            }
            SessionState ss = state.getSessionState(id.getParentId());
            if (ss != null) {
                result.setProducerState(ss.getProducerState(id));
                ProducerState producerState = ss.getProducerState(id);
                if (producerState != null && producerState.getInfo() != null) {
                    ProducerInfo info = producerState.getInfo();
                }
            }
            producerExchanges.put(id, result);
        }
    }
    return result;
}
Also used : SessionState(org.apache.activemq.state.SessionState) ProducerInfo(org.apache.activemq.command.ProducerInfo) ProducerState(org.apache.activemq.state.ProducerState) AMQProducerBrokerExchange(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQProducerBrokerExchange)

Example 2 with ProducerState

use of org.apache.activemq.state.ProducerState in project activemq-artemis by apache.

the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.

@Test
public void TestOptimizedDispatchCME() throws Exception {
    final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConnectionContext contextNotInTx = new ConnectionContext();
    contextNotInTx.setConnection(new Connection() {

        @Override
        public void stop() throws Exception {
        }

        @Override
        public void start() throws Exception {
        }

        @Override
        public void updateClient(ConnectionControl control) {
        }

        @Override
        public void serviceExceptionAsync(IOException e) {
        }

        @Override
        public void serviceException(Throwable error) {
        }

        @Override
        public Response service(Command command) {
            return null;
        }

        @Override
        public boolean isSlow() {
            return false;
        }

        @Override
        public boolean isNetworkConnection() {
            return false;
        }

        @Override
        public boolean isManageable() {
            return false;
        }

        @Override
        public boolean isFaultTolerantConnection() {
            return false;
        }

        @Override
        public boolean isConnected() {
            return true;
        }

        @Override
        public boolean isBlocked() {
            return false;
        }

        @Override
        public boolean isActive() {
            return false;
        }

        @Override
        public ConnectionStatistics getStatistics() {
            return null;
        }

        @Override
        public String getRemoteAddress() {
            return null;
        }

        @Override
        public int getDispatchQueueSize() {
            return 0;
        }

        @Override
        public Connector getConnector() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getConnectionId() {
            return null;
        }

        @Override
        public void dispatchSync(Command message) {
        }

        @Override
        public void dispatchAsync(Command command) {
        }

        @Override
        public int getActiveTransactionCount() {
            return 0;
        }

        @Override
        public Long getOldestActiveTransactionDuration() {
            return null;
        }
    });
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
    final MockMemoryUsage usage = new MockMemoryUsage();
    queue.setOptimizedDispatch(true);
    queue.initialize();
    queue.start();
    queue.memoryUsage = usage;
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    ProducerInfo producerInfo = new ProducerInfo();
    ProducerState producerState = new ProducerState(producerInfo);
    producerExchange.setProducerState(producerState);
    producerExchange.setConnectionContext(contextNotInTx);
    // populate the queue store, exceed memory limit so that cache is disabled
    for (int i = 0; i < count; i++) {
        Message message = getMessage(i);
        queue.send(producerExchange, message);
    }
    usage.setFull(false);
    try {
        queue.wakeup();
    } catch (Exception e) {
        LOG.error("Queue threw an unexpected exception: " + e.toString());
        fail("Should not throw an exception.");
    }
}
Also used : MessageStore(org.apache.activemq.store.MessageStore) Connector(org.apache.activemq.broker.Connector) ProducerBrokerExchange(org.apache.activemq.broker.ProducerBrokerExchange) ProducerInfo(org.apache.activemq.command.ProducerInfo) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) Connection(org.apache.activemq.broker.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Response(org.apache.activemq.command.Response) ConnectionControl(org.apache.activemq.command.ConnectionControl) Command(org.apache.activemq.command.Command) ProducerState(org.apache.activemq.state.ProducerState) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) Test(org.junit.Test)

Example 3 with ProducerState

use of org.apache.activemq.state.ProducerState in project activemq-artemis by apache.

the class OpenWireProtocolManager method fireAdvisory.

/*
    * See AdvisoryBroker.fireAdvisory()
    */
public void fireAdvisory(AMQConnectionContext context, ActiveMQTopic topic, Command command, ConsumerId targetConsumerId, String originalConnectionId) throws Exception {
    if (!this.isSupportAdvisory()) {
        return;
    }
    ActiveMQMessage advisoryMessage = new ActiveMQMessage();
    if (originalConnectionId == null) {
        originalConnectionId = context.getConnectionId().getValue();
    }
    advisoryMessage.setStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString(), originalConnectionId);
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_NAME, getBrokerName());
    String id = getBrokerId() != null ? getBrokerId().getValue() : "NOT_SET";
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_ID, id);
    String url = context.getConnection().getLocalAddress();
    advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_URL, url);
    // set the data structure
    advisoryMessage.setDataStructure(command);
    advisoryMessage.setPersistent(false);
    advisoryMessage.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE);
    advisoryMessage.setMessageId(new MessageId(advisoryProducerId, messageIdGenerator.getNextSequenceId()));
    advisoryMessage.setTargetConsumerId(targetConsumerId);
    advisoryMessage.setDestination(topic);
    advisoryMessage.setResponseRequired(false);
    advisoryMessage.setProducerId(advisoryProducerId);
    boolean originalFlowControl = context.isProducerFlowControl();
    final AMQProducerBrokerExchange producerExchange = new AMQProducerBrokerExchange();
    producerExchange.setConnectionContext(context);
    producerExchange.setProducerState(new ProducerState(new ProducerInfo()));
    try {
        context.setProducerFlowControl(false);
        AMQSession sess = context.getConnection().getAdvisorySession();
        if (sess != null) {
            sess.send(producerExchange.getProducerState().getInfo(), advisoryMessage, false);
        }
    } finally {
        context.setProducerFlowControl(originalFlowControl);
    }
}
Also used : AMQSession(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession) ProducerInfo(org.apache.activemq.command.ProducerInfo) ProducerState(org.apache.activemq.state.ProducerState) AMQProducerBrokerExchange(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQProducerBrokerExchange) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) MessageId(org.apache.activemq.command.MessageId)

Example 4 with ProducerState

use of org.apache.activemq.state.ProducerState in project activemq-artemis by apache.

the class QueueDuplicatesFromStoreTest method doTestNoDuplicateAfterCacheFullAndAcked.

public void doTestNoDuplicateAfterCacheFullAndAcked(final int auditDepth) throws Exception {
    final PersistenceAdapter persistenceAdapter = brokerService.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConnectionContext contextNotInTx = new ConnectionContext();
    final ConsumerInfo consumerInfo = new ConsumerInfo();
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    consumerInfo.setExclusive(true);
    final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, brokerService.getTaskRunnerFactory());
    // a workaround for this issue
    // queue.setUseCache(false);
    queue.systemUsage.getMemoryUsage().setLimit(1024 * 1024 * 10);
    queue.setMaxAuditDepth(auditDepth);
    queue.initialize();
    queue.start();
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    ProducerInfo producerInfo = new ProducerInfo();
    ProducerState producerState = new ProducerState(producerInfo);
    producerExchange.setProducerState(producerState);
    producerExchange.setConnectionContext(contextNotInTx);
    final CountDownLatch receivedLatch = new CountDownLatch(count);
    final AtomicLong ackedCount = new AtomicLong(0);
    final AtomicLong enqueueCounter = new AtomicLong(0);
    final Vector<String> errors = new Vector<>();
    // populate the queue store, exceed memory limit so that cache is disabled
    for (int i = 0; i < count; i++) {
        Message message = getMessage(i);
        queue.send(producerExchange, message);
    }
    assertEquals("store count is correct", count, queueMessageStore.getMessageCount());
    // pull from store in small windows
    Subscription subscription = new Subscription() {

        private SubscriptionStatistics subscriptionStatistics = new SubscriptionStatistics();

        @Override
        public long getPendingMessageSize() {
            return 0;
        }

        @Override
        public void add(MessageReference node) throws Exception {
            if (enqueueCounter.get() != node.getMessageId().getProducerSequenceId()) {
                errors.add("Not in sequence at: " + enqueueCounter.get() + ", received: " + node.getMessageId().getProducerSequenceId());
            }
            assertEquals("is in order", enqueueCounter.get(), node.getMessageId().getProducerSequenceId());
            receivedLatch.countDown();
            enqueueCounter.incrementAndGet();
            node.decrementReferenceCount();
        }

        @Override
        public void add(ConnectionContext context, Destination destination) throws Exception {
        }

        @Override
        public int countBeforeFull() {
            if (isFull()) {
                return 0;
            } else {
                return fullWindow - (int) (enqueueCounter.get() - ackedCount.get());
            }
        }

        @Override
        public void destroy() {
        }

        @Override
        public void gc() {
        }

        @Override
        public ConsumerInfo getConsumerInfo() {
            return consumerInfo;
        }

        @Override
        public ConnectionContext getContext() {
            return null;
        }

        @Override
        public long getDequeueCounter() {
            return 0;
        }

        @Override
        public long getDispatchedCounter() {
            return 0;
        }

        @Override
        public int getDispatchedQueueSize() {
            return 0;
        }

        @Override
        public long getEnqueueCounter() {
            return 0;
        }

        @Override
        public int getInFlightSize() {
            return 0;
        }

        @Override
        public int getInFlightUsage() {
            return 0;
        }

        @Override
        public ObjectName getObjectName() {
            return null;
        }

        @Override
        public int getPendingQueueSize() {
            return 0;
        }

        @Override
        public int getPrefetchSize() {
            return 0;
        }

        @Override
        public String getSelector() {
            return null;
        }

        @Override
        public boolean isBrowser() {
            return false;
        }

        @Override
        public boolean isFull() {
            return (enqueueCounter.get() - ackedCount.get()) >= fullWindow;
        }

        @Override
        public boolean isHighWaterMark() {
            return false;
        }

        @Override
        public boolean isLowWaterMark() {
            return false;
        }

        @Override
        public boolean isRecoveryRequired() {
            return false;
        }

        @Override
        public boolean matches(MessageReference node, MessageEvaluationContext context) throws IOException {
            return true;
        }

        @Override
        public boolean matches(ActiveMQDestination destination) {
            return true;
        }

        @Override
        public void processMessageDispatchNotification(MessageDispatchNotification mdn) throws Exception {
        }

        @Override
        public Response pullMessage(ConnectionContext context, MessagePull pull) throws Exception {
            return null;
        }

        @Override
        public boolean isWildcard() {
            return false;
        }

        @Override
        public List<MessageReference> remove(ConnectionContext context, Destination destination) throws Exception {
            return null;
        }

        @Override
        public void setObjectName(ObjectName objectName) {
        }

        @Override
        public void setSelector(String selector) throws InvalidSelectorException, UnsupportedOperationException {
        }

        @Override
        public void updateConsumerPrefetch(int newPrefetch) {
        }

        @Override
        public boolean addRecoveredMessage(ConnectionContext context, MessageReference message) throws Exception {
            return false;
        }

        @Override
        public ActiveMQDestination getActiveMQDestination() {
            return destination;
        }

        @Override
        public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
        }

        @Override
        public int getCursorMemoryHighWaterMark() {
            return 0;
        }

        @Override
        public void setCursorMemoryHighWaterMark(int cursorMemoryHighWaterMark) {
        }

        @Override
        public boolean isSlowConsumer() {
            return false;
        }

        @Override
        public void unmatched(MessageReference node) throws IOException {
        }

        @Override
        public long getTimeOfLastMessageAck() {
            return 0;
        }

        @Override
        public long getConsumedCount() {
            return 0;
        }

        @Override
        public void incrementConsumedCount() {
        }

        @Override
        public void resetConsumedCount() {
        }

        @Override
        public SubscriptionStatistics getSubscriptionStatistics() {
            return subscriptionStatistics;
        }

        @Override
        public long getInFlightMessageSize() {
            return subscriptionStatistics.getInflightMessageSize().getTotalSize();
        }
    };
    queue.addSubscription(contextNotInTx, subscription);
    int removeIndex = 0;
    do {
        // Simulate periodic acks in small but recent windows
        long receivedCount = enqueueCounter.get();
        if (receivedCount > ackStartIndex) {
            if (receivedCount >= removeIndex + ackWindow) {
                for (int j = 0; j < ackBatchSize; j++, removeIndex++) {
                    ackedCount.incrementAndGet();
                    MessageAck ack = new MessageAck();
                    ack.setLastMessageId(new MessageId(mesageIdRoot + removeIndex));
                    ack.setMessageCount(1);
                    queue.removeMessage(contextNotInTx, subscription, new IndirectMessageReference(getMessage(removeIndex)), ack);
                    queue.wakeup();
                }
                if (removeIndex % 1000 == 0) {
                    LOG.info("acked: " + removeIndex);
                    persistenceAdapter.checkpoint(true);
                }
            }
        }
    } while (!receivedLatch.await(0, TimeUnit.MILLISECONDS) && errors.isEmpty());
    assertTrue("There are no errors: " + errors, errors.isEmpty());
    assertEquals(count, enqueueCounter.get());
    assertEquals("store count is correct", count - removeIndex, queueMessageStore.getMessageCount());
}
Also used : MessageStore(org.apache.activemq.store.MessageStore) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) MessagePull(org.apache.activemq.command.MessagePull) ProducerState(org.apache.activemq.state.ProducerState) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Vector(java.util.Vector) ProducerBrokerExchange(org.apache.activemq.broker.ProducerBrokerExchange) ProducerInfo(org.apache.activemq.command.ProducerInfo) MessageEvaluationContext(org.apache.activemq.filter.MessageEvaluationContext) MessageAck(org.apache.activemq.command.MessageAck) MessageDispatchNotification(org.apache.activemq.command.MessageDispatchNotification) CountDownLatch(java.util.concurrent.CountDownLatch) ObjectName(javax.management.ObjectName) AtomicLong(java.util.concurrent.atomic.AtomicLong) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) MessageId(org.apache.activemq.command.MessageId)

Aggregations

ProducerInfo (org.apache.activemq.command.ProducerInfo)4 ProducerState (org.apache.activemq.state.ProducerState)4 AMQProducerBrokerExchange (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQProducerBrokerExchange)2 ConnectionContext (org.apache.activemq.broker.ConnectionContext)2 ProducerBrokerExchange (org.apache.activemq.broker.ProducerBrokerExchange)2 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)2 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)2 Message (org.apache.activemq.command.Message)2 MessageId (org.apache.activemq.command.MessageId)2 MessageStore (org.apache.activemq.store.MessageStore)2 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)2 IOException (java.io.IOException)1 Vector (java.util.Vector)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ObjectName (javax.management.ObjectName)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 AMQSession (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession)1 Connection (org.apache.activemq.broker.Connection)1 Connector (org.apache.activemq.broker.Connector)1