KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > advisory > ConsumerEvent


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.advisory;
19
20 import org.apache.activemq.command.ConsumerId;
21
22 import javax.jms.Destination JavaDoc;
23
24 import java.util.EventObject JavaDoc;
25
26 /**
27  * An event when the number of consumers on a given destination changes.
28  *
29  * @version $Revision: 426366 $
30  */

31 public abstract class ConsumerEvent extends EventObject JavaDoc {
32     private static final long serialVersionUID = 2442156576867593780L;
33     private final Destination JavaDoc destination;
34     private final ConsumerId consumerId;
35     private final int consumerCount;
36
37     public ConsumerEvent(ConsumerEventSource source, Destination JavaDoc destination, ConsumerId consumerId, int consumerCount) {
38         super(source);
39         this.destination = destination;
40         this.consumerId = consumerId;
41         this.consumerCount = consumerCount;
42     }
43
44     public ConsumerEventSource getAdvisor() {
45         return (ConsumerEventSource) getSource();
46     }
47
48     public Destination JavaDoc getDestination() {
49         return destination;
50     }
51
52     /**
53      * Returns the current number of consumers active at the time this advisory was sent.
54      *
55      * Note that this is not the number of consumers active when the consumer started consuming.
56      * It is usually more vital to know how many consumers there are now - rather than historically
57      * how many there were when a consumer started. So if you create a {@link ConsumerListener}
58      * after many consumers have started, you will receive a ConsumerEvent for each consumer. However the
59      * {@link #getConsumerCount()} method will always return the current active consumer count on each event.
60      */

61     public int getConsumerCount() {
62         return consumerCount;
63     }
64
65     public ConsumerId getConsumerId() {
66         return consumerId;
67     }
68
69     public abstract boolean isStarted();
70 }
71
Popular Tags