001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.advisory;
018    
019    import java.util.EventObject;
020    
021    import javax.jms.Destination;
022    
023    import org.apache.activemq.command.ConsumerId;
024    
025    /**
026     * An event when the number of consumers on a given destination changes.
027     * 
028     * 
029     */
030    public abstract class ConsumerEvent extends EventObject {
031        private static final long serialVersionUID = 2442156576867593780L;
032        private final Destination destination;
033        private final ConsumerId consumerId;
034        private final int consumerCount;
035    
036        public ConsumerEvent(ConsumerEventSource source, Destination destination, ConsumerId consumerId, int consumerCount) {
037            super(source);
038            this.destination = destination;
039            this.consumerId = consumerId;
040            this.consumerCount = consumerCount;
041        }
042    
043        public ConsumerEventSource getAdvisor() {
044            return (ConsumerEventSource) getSource();
045        }
046    
047        public Destination getDestination() {
048            return destination;
049        }
050    
051        /**
052         * Returns the current number of consumers active at the time this advisory was sent.
053         * 
054         * Note that this is not the number of consumers active when the consumer started consuming.
055         * It is usually more vital to know how many consumers there are now - rather than historically
056         * how many there were when a consumer started. So if you create a {@link ConsumerListener}
057         * after many consumers have started, you will receive a ConsumerEvent for each consumer. However the
058         * {@link #getConsumerCount()} method will always return the current active consumer count on each event.
059         */
060        public int getConsumerCount() {
061            return consumerCount;
062        }
063    
064        public ConsumerId getConsumerId() {
065            return consumerId;
066        }
067    
068        public abstract boolean isStarted();
069    }