@Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); if (securityContexts.remove(context.getSecurityContext())) { context.setSecurityContext(null); } }
/** * inform the MessageConsumer on the client to change it's prefetch * * @param newPrefetch */ @Override public void updateConsumerPrefetch(int newPrefetch) { if (context != null && context.getConnection() != null && context.getConnection().isManageable()) { ConsumerControl cc = new ConsumerControl(); cc.setConsumerId(info.getConsumerId()); cc.setPrefetch(newPrefetch); context.getConnection().dispatchAsync(cc); } }
private void fireFailedForwardAdvisory(MessageDispatch messageDispatch, Throwable error) { if (configuration.isAdvisoryForFailedForward()) { AdvisoryBroker advisoryBroker = null; try { advisoryBroker = (AdvisoryBroker) brokerService.getBroker().getAdaptor(AdvisoryBroker.class); if (advisoryBroker != null) { ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(brokerService.getBroker()); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty("cause", error.getLocalizedMessage()); advisoryBroker.fireAdvisory(context, AdvisorySupport.getNetworkBridgeForwardFailureAdvisoryTopic(), messageDispatch.getMessage(), null, advisoryMessage); } } catch (Exception e) { LOG.warn("failed to fire forward failure advisory, cause: {}", e); LOG.debug("detail", e); } } }
/** * Factory method to create the new administration connection context * object. Note this method is here rather than inside a default broker * implementation to ensure that the broker reference inside it is the outer * most interceptor */ protected static ConnectionContext createAdminConnectionContext(Broker broker) { ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); return context; } }
private void commit(LocalTransactionId tx, ConnectionContext connectionContext, Message message) throws Exception { if (tx != null) { connectionContext.getBroker().commitTransaction(connectionContext, tx, true); connectionContext.getTransactions().remove(tx); connectionContext.setTransaction(null); message.setTransactionId(null); } }
public void setLastStoredSequenceId(long l) { auditProducerSequenceIds = true; if (connectionContext.isNetworkConnection()) { brokerService = connectionContext.getBroker().getBrokerService(); isNetworkProducer = true; } lastSendSequenceNumber.set(l); LOG.debug("last stored sequence id set: {}", l); }
public static void doResend(final ConnectionContext context, Message originalMessage, ActiveMQDestination deadLetterDestination, boolean copy) throws Exception { Message message = copy ? originalMessage.copy() : originalMessage; message.setOriginalDestination(message.getDestination()); message.setOriginalTransactionId(message.getTransactionId()); message.setDestination(deadLetterDestination); message.setTransactionId(null); message.setMemoryUsage(null); message.setRedeliveryCounter(0); message.getMessageId().setDataLocator(null); boolean originalFlowControl = context.isProducerFlowControl(); try { context.setProducerFlowControl(false); ProducerInfo info = new ProducerInfo(); ProducerState state = new ProducerState(info); ProducerBrokerExchange producerExchange = new ProducerBrokerExchange(); producerExchange.setProducerState(state); producerExchange.setMutable(true); producerExchange.setConnectionContext(context); context.getBroker().send(producerExchange, message); } finally { context.setProducerFlowControl(originalFlowControl); } }
if (!msg.isPersistent()) { if (isSendAdvisoryIfNoConsumers()) { if (destination.isQueue() || !AdvisorySupport.isAdvisoryTopic(destination)) { Message message = msg.copy(); if (message.getOriginalDestination() != null) { message.setOriginalDestination(message.getDestination()); if (destination.isQueue()) { advisoryTopic = AdvisorySupport.getNoQueueConsumersAdvisoryTopic(destination); } else { boolean originalFlowControl = context.isProducerFlowControl(); try { context.setProducerFlowControl(false); ProducerBrokerExchange producerExchange = new ProducerBrokerExchange(); producerExchange.setMutable(false); producerExchange.setConnectionContext(context); producerExchange.setProducerState(new ProducerState(new ProducerInfo())); context.getBroker().send(producerExchange, message); } finally { context.setProducerFlowControl(originalFlowControl);
private LocalTransactionId beginLocalTransaction(int numDestinations, ConnectionContext connectionContext, Message message) throws Exception { LocalTransactionId result = null; if (transactedSend && numDestinations > 1 && message.isPersistent() && message.getTransactionId() == null) { result = new LocalTransactionId(new ConnectionId(message.getMessageId().getProducerId().toString()), message.getMessageId().getProducerSequenceId()); connectionContext.getBroker().beginTransaction(connectionContext, result); connectionContext.setTransaction(connectionContext.getTransactions().get(result)); message.setTransactionId(result); } return result; }
final boolean sendProducerAck = !message.isResponseRequired() && producerInfo.getWindowSize() > 0 && !context.isInRecoveryMode(); if (message.isExpired()) { broker.getRoot().messageExpired(context, message, null); if (sendProducerAck) { ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize()); context.getConnection().dispatchAsync(ack); isFull(context, memoryUsage); fastProducer(context, producerInfo); if (isProducerFlowControl() && context.isProducerFlowControl()) { if (isFlowControlLogRequired()) { LOG.warn("Usage Manager Memory Limit ({}) reached on {}, size {}. Producers will be throttled to the rate at which messages are removed from this destination to prevent flooding it. See http://activemq.apache.org/producer-flow-control.html for more info.", memoryUsage.getLimit(), getActiveMQDestination().getQualifiedName(), destinationStatistics.getMessages().getCount()); } else { LOG.debug("Usage Manager Memory Limit ({}) reached on {}, size {}. Producers will be throttled to the rate at which messages are removed from this destination to prevent flooding it. See http://activemq.apache.org/producer-flow-control.html for more info.", memoryUsage.getLimit(), getActiveMQDestination().getQualifiedName(), destinationStatistics.getMessages().getCount()); if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) { ResourceAllocationException resourceAllocationException = sendMemAllocationException; if (resourceAllocationException == null) { if (!context.isNetworkConnection() && systemUsage.getSendFailIfNoSpaceAfterTimeout() != 0) { flowControlTimeoutMessages.add(new TimeoutMessage(message, context, systemUsage .getSendFailIfNoSpaceAfterTimeout())); context.setDontSendReponse(true); return;
int match = sub.getActiveMQDestination().compareTo(next.getActiveMQDestination()); if (match == 0 || (!next.getActiveMQDestination().isPattern() && match == 1)) { super.addSubscription(context, sub); final RegionBroker regionBroker = (RegionBroker) context.getBroker().getAdaptor(RegionBroker.class); final Set<Destination> virtualDests = regionBroker.getDestinations(virtualDestination); if (virtualDest.getActiveMQDestination().isTopic() && (virtualDest.isAlwaysRetroactive() || sub.getConsumerInfo().isRetroactive())) { final Message copy = message.copy(); copy.setOriginalDestination(message.getDestination()); copy.setDestination(newDestination); if (regionDest == null) {
final boolean sendProducerAck = !message.isResponseRequired() && producerInfo.getWindowSize() > 0 && !context.isInRecoveryMode(); if (message.isExpired()) { broker.messageExpired(context, message, null); getDestinationStatistics().getExpired().increment(); if (sendProducerAck) { ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize()); context.getConnection().dispatchAsync(ack); if (isProducerFlowControl() && context.isProducerFlowControl()) { if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) { context.setDontSendReponse(true); return; if (context.isInTransaction()) { if (context.getStopping().get()) { throw new IOException("Connection closed, send aborted."); if (count > 2 && context.isInTransaction()) { count = 0; int size = context.getTransaction().size(); LOG.warn("Waiting for space to send transacted message - transaction elements = {} need more space to commit. Message = {}", size, message); context.getConnection().dispatchAsync(ack);
Message message = node.getMessage(); if (message != null && node.getRegionDestination() != null) { DeadLetterStrategy deadLetterStrategy = ((Destination) node.getRegionDestination()).getDeadLetterStrategy(); if (deadLetterStrategy != null) { if (deadLetterStrategy.isSendToDeadLetterQueue(message)) { ActiveMQDestination deadLetterDestination = deadLetterStrategy.getDeadLetterQueueFor(message, subscription); if (deadLetterDestination.equals(message.getDestination())) { LOG.debug("Not re-adding to DLQ: {}, dest: {}", message.getMessageId(), message.getDestination()); return false; if (context.getSecurityContext() == null || !context.getSecurityContext().isBrokerContext()) { adminContext = BrokerSupport.getConnectionContext(this); addDestination(adminContext, deadLetterDestination, false).getActiveMQDestination().setDLQ(true); BrokerSupport.resendNoCopy(adminContext, message, deadLetterDestination); return true;
private void scheduleRedelivery(ConnectionContext context, MessageReference messageReference, long delay, int redeliveryCount) throws Exception { if (LOG.isTraceEnabled()) { Destination regionDestination = (Destination) messageReference.getRegionDestination(); LOG.trace("redelivery #{} of: {} with delay: {}, dest: {}", new Object[]{ redeliveryCount, messageReference.getMessageId(), delay, regionDestination.getActiveMQDestination() }); } final Message old = messageReference.getMessage(); Message message = old.copy(); message.setTransactionId(null); message.setMemoryUsage(null); message.removeProperty(ScheduledMessage.AMQ_SCHEDULED_ID); message.setProperty(REDELIVERY_DELAY, delay); message.setProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay); message.setRedeliveryCounter(redeliveryCount); boolean originalFlowControl = context.isProducerFlowControl(); try { context.setProducerFlowControl(false); ProducerInfo info = new ProducerInfo(); ProducerState state = new ProducerState(info); ProducerBrokerExchange producerExchange = new ProducerBrokerExchange(); producerExchange.setProducerState(state); producerExchange.setMutable(true); producerExchange.setConnectionContext(context); context.getBroker().send(producerExchange, message); } finally { context.setProducerFlowControl(originalFlowControl); } }
ConnectionContext context = producerExchange.getConnectionContext(); final String jobId = (String) messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_ID); final Object cronValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_CRON); final Object periodValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD); final Object delayValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY); String physicalName = messageSend.getDestination().getPhysicalName(); boolean schedularManage = physicalName.regionMatches(true, 0, ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION, 0, ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION.length()); long nextWarn = start; while (!usage.waitForSpace(1000)) { if (context.getStopping().get()) { throw new IOException("Connection closed, send aborted."); if (context.isInTransaction()) { context.getTransaction().addSynchronization(new Synchronization() { @Override public void afterCommit() throws Exception {
throws IOException, Exception { final ConnectionContext context = producerExchange.getConnectionContext(); message.getMessageId().setBrokerSequenceId(getDestinationSequenceId()); Future<Object> result = null; if (topicStore != null && message.isPersistent() && !canOptimizeOutPersistence()) { if (systemUsage.getStoreUsage().isFull(getStoreUsageHighWaterMark())) { final String logMessage = "Persistent store is Full, " + getStoreUsageHighWaterMark() + "% of " + systemUsage.getStoreUsage().getLimit() + ". Stopping producer (" + message.getProducerId() + ") to prevent flooding " + getActiveMQDestination().getQualifiedName() + "." + " See http://activemq.apache.org/producer-flow-control.html for more info"; if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) { throw new javax.jms.ResourceAllocationException(logMessage); message.incrementReferenceCount(); if (context.isInTransaction()) { context.getTransaction().addSynchronization(new Synchronization() { @Override public void afterCommit() throws Exception {
advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_ID, id); String url = getBrokerService().getVmConnectorURI().toString(); if (context.getConnector() instanceof TransportConnector && ((TransportConnector) context.getConnector()).getPublishableConnectString() != null) { url = ((TransportConnector) context.getConnector()).getPublishableConnectString(); } else if (getBrokerService().getDefaultSocketURIString() != null) { url = getBrokerService().getDefaultSocketURIString(); 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 ProducerBrokerExchange producerExchange = new ProducerBrokerExchange(); producerExchange.setConnectionContext(context); producerExchange.setMutable(true); producerExchange.setProducerState(new ProducerState(new ProducerInfo())); try { context.setProducerFlowControl(false); next.send(producerExchange, advisoryMessage); } finally { context.setProducerFlowControl(originalFlowControl);
protected void onDispatch(final MessageReference node, final Message message) { Destination nodeDest = (Destination) node.getRegionDestination(); if (nodeDest != null) { if (node != QueueMessageReference.NULL_MESSAGE) { nodeDest.getDestinationStatistics().getDispatched().increment(); nodeDest.getDestinationStatistics().getInflight().increment(); LOG.trace("{} dispatched: {} - {}, dispatched: {}, inflight: {}", new Object[]{ info.getConsumerId(), message.getMessageId(), message.getDestination(), getSubscriptionStatistics().getDispatched().getCount(), dispatched.size() }); } } if (info.isDispatchAsync()) { try { dispatchPending(); } catch (IOException e) { context.getConnection().serviceExceptionAsync(e); } } }
public ObjectName registerSubscription(ConnectionContext context, Subscription sub) { String connectionClientId = context.getClientId(); SubscriptionKey key = new SubscriptionKey(context.getClientId(), sub.getConsumerInfo().getSubscriptionName()); try { ObjectName objectName = BrokerMBeanSupport.createSubscriptionName(brokerObjectName, connectionClientId, sub.getConsumerInfo()); SubscriptionView view; if (sub.getConsumerInfo().getConsumerId().getConnectionId().equals("OFFLINE")) { info.setClientId(context.getClientId()); info.setSubscriptionName(sub.getConsumerInfo().getSubscriptionName()); info.setDestination(sub.getConsumerInfo().getDestination()); info.setSelector(sub.getSelector()); addInactiveSubscription(key, info, sub); } else { String userName = brokerService.isPopulateUserNameInMBeans() ? context.getUserName() : null; if (sub.getConsumerInfo().isDurable()) { view = new DurableSubscriptionView(this, brokerService, context.getClientId(), userName, sub); } else { if (sub instanceof TopicSubscription) { view = new TopicSubscriptionView(context.getClientId(), userName, (TopicSubscription) sub); } else { view = new SubscriptionView(context.getClientId(), userName, sub);
if (message.isInTransaction()) { if (context.getTransaction().getState() > IN_USE_STATE) { throw new JMSException("Send transaction completed while waiting for space"); if (message.isExpired()) { LOG.error("message expired waiting for space"); broker.messageExpired(context, message, null); destinationStatistics.getExpired().increment(); } else { ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message .getSize()); context.getConnection().dispatchAsync(ack); } else { Response response = new Response(); response.setCorrelationId(message.getCommandId()); context.getConnection().dispatchAsync(response); if (!sendProducerAck && !context.isInRecoveryMode() && !brokerService.isStopping()) { ExceptionResponse response = new ExceptionResponse(e); response.setCorrelationId(message.getCommandId()); context.getConnection().dispatchAsync(response); } else { LOG.debug("unexpected exception on deferred send of: {}", message, e);