Package org.apache.activemq.broker

Examples of org.apache.activemq.broker.ConnectionContext


      }
    }
  }

    public void send(final ProducerBrokerExchange producerExchange, final Message message) throws Exception {
        final ConnectionContext context = producerExchange.getConnectionContext();
        // There is delay between the client sending it and it arriving at the
        // destination.. it may have expired.

        final ProducerInfo producerInfo = producerExchange.getProducerState().getInfo();
        final boolean sendProducerAck = !message.isResponseRequired() && producerInfo.getWindowSize() > 0 && !context.isInRecoveryMode();
        if (message.isExpired()) {
            broker.messageExpired(context, message);
            destinationStatistics.getMessages().decrement();
            if (sendProducerAck) {
                ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize());
                context.getConnection().dispatchAsync(ack);
            }
            return;
        }
        if (isProducerFlowControl() && context.isProducerFlowControl() && memoryUsage.isFull()) {
            if (systemUsage.isSendFailIfNoSpace()) {
                throw new javax.jms.ResourceAllocationException("SystemUsage memory limit reached");
            }

            // We can avoid blocking due to low usage if the producer is sending
            // a sync message or
            // if it is using a producer window
            if (producerInfo.getWindowSize() > 0 || message.isResponseRequired()) {
                synchronized (messagesWaitingForSpace) {
                    messagesWaitingForSpace.add(new Runnable() {
                        public void run() {

                            try {

                                // While waiting for space to free up... the
                                // message may have expired.
                                if (broker.isExpired(message)) {
                                    broker.messageExpired(context, message);
                                    destinationStatistics.getMessages().decrement();
                                } else {
                                    doMessageSend(producerExchange, message);
                                }

                                if (sendProducerAck) {
                                    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);
                                }

                            } catch (Exception e) {
                                if (!sendProducerAck && !context.isInRecoveryMode()) {
                                    ExceptionResponse response = new ExceptionResponse(e);
                                    response.setCorrelationId(message.getCommandId());
                                    context.getConnection().dispatchAsync(response);
                                }
                            }
                        }
                    });

                    // If the user manager is not full, then the task will not
                    // get called..
                    if (!memoryUsage.notifyCallbackWhenNotFull(sendMessagesWaitingForSpaceTask)) {
                        // so call it directly here.
                        sendMessagesWaitingForSpaceTask.run();
                    }
                    context.setDontSendReponse(true);
                    return;
                }

            } else {

                // Producer flow control cannot be used, so we have do the flow
                // control at the broker
                // by blocking this thread until there is space available.
                while (!memoryUsage.waitForSpace(1000)) {
                    if (context.getStopping().get()) {
                        throw new IOException("Connection closed, send aborted.");
                    }
                }

                // The usage manager could have delayed us by the time
                // we unblock the message could have expired..
                if (message.isExpired()) {
                    if (log.isDebugEnabled()) {
                        log.debug("Expired message: " + message);
                    }
                    return;
                }
            }
        }
        doMessageSend(producerExchange, message);
        if (sendProducerAck) {
            ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), message.getSize());
            context.getConnection().dispatchAsync(ack);
        }
    }
View Full Code Here


            context.getConnection().dispatchAsync(ack);
        }
    }

    synchronized void doMessageSend(final ProducerBrokerExchange producerExchange, final Message message) throws IOException, Exception {
        final ConnectionContext context = producerExchange.getConnectionContext();
        message.setRegionDestination(this);
        if (store != null && message.isPersistent()) {
            while (!systemUsage.getStoreUsage().waitForSpace(1000)) {
                if (context.getStopping().get()) {
                    throw new IOException("Connection closed, send aborted.");
                }
            }
            store.addMessage(context, message);
        }
        if (context.isInTransaction()) {
            // If this is a transacted message.. increase the usage now so that
            // a big TX does not blow up
            // our memory. This increment is decremented once the tx finishes..
            message.incrementReferenceCount();
            context.getTransaction().addSynchronization(new Synchronization() {
                public void afterCommit() throws Exception {
                    try {
                        // It could take while before we receive the commit
                        // op, by that time the message could have expired..
                        if (broker.isExpired(message)) {
View Full Code Here

    public void purge() throws Exception {

        pageInMessages();

        synchronized (pagedInMessages) {
            ConnectionContext c = createConnectionContext();
            for (Iterator<MessageReference> i = pagedInMessages.iterator(); i.hasNext();) {
                try {
                    QueueMessageReference r = (QueueMessageReference)i.next();

                    // We should only delete messages that can be locked.
View Full Code Here

     */
    public int removeMatchingMessages(MessageReferenceFilter filter, int maximumMessages) throws Exception {
        pageInMessages();
        int counter = 0;
        synchronized (pagedInMessages) {
            ConnectionContext c = createConnectionContext();
            for (Iterator<MessageReference> i = pagedInMessages.iterator(); i.hasNext();) {
                IndirectMessageReference r = (IndirectMessageReference)i.next();
                if (filter.evaluate(c, r)) {
                    removeMessage(c, r);
                    if (++counter >= maximumMessages && maximumMessages > 0) {
View Full Code Here

    protected boolean lockMessage(IndirectMessageReference r) {
        return r.lock(LockOwner.HIGH_PRIORITY_LOCK_OWNER);
    }

    protected ConnectionContext createConnectionContext() {
        ConnectionContext answer = new ConnectionContext();
        answer.getMessageEvaluationContext().setDestination(getActiveMQDestination());
        return answer;
    }
View Full Code Here

                                 1000);
    }

    public ObjectName createDurableSubscriber(String clientId, String subscriberName, String topicName,
                                              String selector) throws Exception {
        ConnectionContext context = new ConnectionContext();
        context.setBroker(broker);
        context.setClientId(clientId);
        ConsumerInfo info = new ConsumerInfo();
        ConsumerId consumerId = new ConsumerId();
        consumerId.setConnectionId(clientId);
        consumerId.setSessionId(sessionIdCounter.incrementAndGet());
        consumerId.setValue(0);
View Full Code Here

    public void destroyDurableSubscriber(String clientId, String subscriberName) throws Exception {
        RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
        info.setClientId(clientId);
        info.setSubscriptionName(subscriberName);
        ConnectionContext context = new ConnectionContext();
        context.setBroker(broker);
        context.setClientId(clientId);
        broker.removeSubscription(context, info);
    }
View Full Code Here

    /**
     * Returns the broker's administration connection context used for
     * configuring the broker at startup
     */
    public static ConnectionContext getConnectionContext(Broker broker) {
        ConnectionContext adminConnectionContext = broker.getAdminConnectionContext();
        if (adminConnectionContext == null) {
            adminConnectionContext = createAdminConnectionContext(broker);
            broker.setAdminConnectionContext(adminConnectionContext);
        }
        return adminConnectionContext;
View Full Code Here

     * 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);
        return context;
    }
View Full Code Here

                // A single durable sub may be subscribing to multiple topics.
                // so it might exist already.
                DurableTopicSubscription sub = durableSubscriptions.get(key);
                ConsumerInfo consumerInfo = createInactiveConsumerInfo(info);
                if (sub == null) {
                    ConnectionContext c = new ConnectionContext();
                    c.setBroker(context.getBroker());
                    c.setClientId(key.getClientId());
                    c.setConnectionId(consumerInfo.getConsumerId().getParentId().getParentId());
                    sub = (DurableTopicSubscription)createSubscription(c, consumerInfo);
                }

                if (dupChecker.contains(sub)) {
                    continue;
View Full Code Here

TOP

Related Classes of org.apache.activemq.broker.ConnectionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.