Package org.codehaus.activemq.service

Examples of org.codehaus.activemq.service.Subscription


        // unless via the deleteSubscription() method
       
//        subscriptionContainer.removeSubscription(info.getConsumerId());
//        subscription.clear();
       
        Subscription sub = (Subscription) activeSubscriptions.remove(info.getConsumerId());
        if (sub != null) {
            sub.setActive(false);
            dispatcher.removeActiveSubscription(client, sub);
        }
    }
View Full Code Here


     * @throws javax.jms.JMSException if the subscriber doesn't exist or is still active
     */
    public void deleteSubscription(String clientId, String subscriberName) throws JMSException {
       
        String consumerKey = ConsumerInfo.generateConsumerKey(clientId, subscriberName);       
        Subscription sub = (Subscription) durableSubscriptions.remove(consumerKey);
        if( sub!=null ) {
            //only delete if not active
            if (sub.isActive()) {
                throw new JMSException("The Consummer " + subscriberName + " is still active");
            }
            else {
                subscriptionContainer.removeSubscription(sub.getConsumerId());
                sub.clear();
               
                Set containers = destinationMap.get(sub.getDestination());
                for (Iterator iter = containers.iterator();iter.hasNext();) {
                    TopicMessageContainer container = (TopicMessageContainer) iter.next();
                    if (container instanceof DurableTopicMessageContainer) {
                        ((DurableTopicMessageContainer) container).deleteSubscription(sub.getPersistentKey());
                    }
                }
               
            }
        } else {
View Full Code Here

     */
    private void doSendMessage(BrokerClient client, ActiveMQMessage message, MessageContainer container) throws JMSException {
        Set matchingSubscriptions = subscriptionContainer.getSubscriptions(message.getJMSActiveMQDestination());
        if (!matchingSubscriptions.isEmpty()) {
            for (Iterator i = matchingSubscriptions.iterator();i.hasNext();) {
                Subscription sub = (Subscription) i.next();
                if (sub.isTarget(message)) {
                    sub.addMessage(container, message);
                }
            }
            updateSendStats(client, message);
        }       
    }
View Full Code Here

     * @return
     */
    public Map getLocalDestinations() {
        Map localDestinations = new HashMap();
        for (Iterator iter = subscriptionContainer.subscriptionIterator(); iter.hasNext();) {
            Subscription sub = (Subscription) iter.next();
            if (sub.isLocalSubscription()) {
                final ActiveMQDestination dest = sub.getDestination();
                localDestinations.put(dest.getPhysicalName(), dest);
            }
        }
        return Collections.unmodifiableMap(localDestinations);
    }
View Full Code Here

     */
    public void acknowledgeMessage(BrokerClient client, final MessageAck ack) throws JMSException {
        if ( !ack.getDestination().isTopic() )
            return;
           
        Subscription sub = (Subscription) activeSubscriptions.get(ack.getConsumerId());
        if (sub == null) {
            return;
        }
       
        sub.messageConsumed(ack);
    }
View Full Code Here

    protected void doAddMessageConsumer(BrokerClient client, ConsumerInfo info) throws JMSException {
        boolean shouldRecover = false;
        if (info.getConsumerName() != null && info.getClientId() != null) {
            for (Iterator iter = activeSubscriptions.values().iterator();iter.hasNext();) {
                Subscription subscription = (Subscription) iter.next();
                if (subscription.isSameDurableSubscription(info)) {
                    throw new DuplicateDurableSubscriptionException(info);
                }
            }
        }       
        Subscription subscription = (Subscription) durableSubscriptions.get(info.getConsumerKey())
        //subscriptionContainer.getSubscription(info.getConsumerId());
        if (subscription != null) {
            //check the subscription hasn't changed
            if (!subscription.getDestination().equals(info.getDestination())
                    || !subscription.getSelector().equals(info.getSelector())) {
                subscriptionContainer.removeSubscription(info.getConsumerId());
                subscription.clear();
                subscription = subscriptionContainer.makeSubscription(dispatcher, client, info, createFilter(info));
                durableSubscriptions.put(info.getConsumerKey(), subscription);
            }
        }
        else {
            subscription = subscriptionContainer.makeSubscription(dispatcher, client,info, createFilter(info));
            shouldRecover = true;
            durableSubscriptions.put(info.getConsumerKey(), subscription);
        }
        subscription.setActiveConsumer(client,info);
        activeSubscriptions.put(info.getConsumerId(), subscription);
        dispatcher.addActiveSubscription(client, subscription);
       
        // load the container
        getContainer(subscription.getDestination().getPhysicalName());
       
        Set containers = destinationMap.get(subscription.getDestination());
        for (Iterator iter = containers.iterator();iter.hasNext();) {
            TopicMessageContainer container = (TopicMessageContainer) iter.next();
            if (container instanceof DurableTopicMessageContainer) {
                ((DurableTopicMessageContainer) container).storeSubscription(info, subscription);
            }
        }
        if (shouldRecover) {
            recoverSubscriptions(subscription);
        }
        // lets not make the subscription active until later
        // as we can't start dispatching until we've sent back the receipt
        // TODO we might wish to register a post-receipt action here
        // to perform the wakeup
        subscription.setActive(true);
        //dispatcher.wakeup(subscription);
    }
View Full Code Here

            doPoll();
            boolean dispatched = false;
            try {
                // our collection will not throw concurrent modification exception
                for (Iterator iter = subscriptions.keySet().iterator(); iter.hasNext();) {
                    Subscription sub = (Subscription) iter.next();
                    if (sub != null && sub.isReadyToDispatch()) {
                        dispatched = dispatchMessages(sub, dispatched);
                    }
                }
            }
            catch (JMSException jmsEx) {
View Full Code Here

      // Are we not intrested in handling that destination?
        if( !isManagerFor(ack.getDestination(), ack.isPersistent()) ) {
          return;
        }

        Subscription sub = subscriptionContainer.getSubscription(ack.getConsumerId());
        if (sub != null) {
            sub.onAcknowledgeTransactedMessageBeforeCommit(ack);
        }
    }
View Full Code Here

    public void redeliverMessage(BrokerClient client, MessageAck ack) throws JMSException {
        if( !isManagerFor(ack.getDestination(), ack.isPersistent()) ) {
          return;
        }

        Subscription sub = subscriptionContainer.getSubscription(ack.getConsumerId());
        if (sub != null) {
            sub.redeliverMessage(null, ack);
        }

    }
View Full Code Here

    protected MessageContainer createContainer(String destinationName) throws JMSException {
        QueueMessageContainer container = persistenceAdapter.createQueueMessageContainer(destinationName);

        //Add any interested Subscriptions to the new Container
        for (Iterator iter = subscriptionContainer.subscriptionIterator(); iter.hasNext();) {
            Subscription sub = (Subscription) iter.next();
            if (sub.isBrowser()) {
                updateBrowsers(container, sub);
            }
            else {
                updateActiveSubscriptions(container, sub);
            }
View Full Code Here

TOP

Related Classes of org.codehaus.activemq.service.Subscription

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.