KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > network > DemandSubscription


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.network;
19
20 import java.util.concurrent.CopyOnWriteArraySet JavaDoc;
21 import java.util.concurrent.atomic.AtomicInteger JavaDoc;
22
23 import org.apache.activemq.command.ConsumerId;
24 import org.apache.activemq.command.ConsumerInfo;
25
26 import java.util.Set JavaDoc;
27
28 /**
29  * Represents a network bridge interface
30  *
31  * @version $Revision: 1.1 $
32  */

33 public class DemandSubscription{
34     private ConsumerInfo remoteInfo;
35     private ConsumerInfo localInfo;
36     private Set JavaDoc remoteSubsIds = new CopyOnWriteArraySet JavaDoc();
37     private AtomicInteger JavaDoc dispatched = new AtomicInteger JavaDoc(0);
38
39     DemandSubscription(ConsumerInfo info){
40         remoteInfo=info;
41         localInfo=info.copy();
42         localInfo.setBrokerPath(info.getBrokerPath());
43         remoteSubsIds.add(info.getConsumerId());
44     }
45
46     /**
47      * Increment the consumers associated with this subscription
48      * @param id
49      * @return true if added
50      */

51     public boolean add(ConsumerId id){
52         return remoteSubsIds.add(id);
53     }
54     
55     /**
56      * Increment the consumers associated with this subscription
57      * @param id
58      * @return true if added
59      */

60     public boolean remove(ConsumerId id){
61         return remoteSubsIds.remove(id);
62     }
63     
64     /**
65      * @return true if there are no interested consumers
66      */

67     public boolean isEmpty(){
68         return remoteSubsIds.isEmpty();
69     }
70     
71     
72     /**
73      * @return Returns the dispatched.
74      */

75     public int getDispatched(){
76         return dispatched.get();
77     }
78
79     /**
80      * @param dispatched The dispatched to set.
81      */

82     public void setDispatched(int dispatched){
83         this.dispatched.set(dispatched);
84     }
85     
86     /**
87      * @return dispatched count after incremented
88      */

89     public int incrementDispatched(){
90         return dispatched.incrementAndGet();
91     }
92
93     /**
94      * @return Returns the localInfo.
95      */

96     public ConsumerInfo getLocalInfo(){
97         return localInfo;
98     }
99
100     /**
101      * @param localInfo The localInfo to set.
102      */

103     public void setLocalInfo(ConsumerInfo localInfo){
104         this.localInfo=localInfo;
105     }
106
107     /**
108      * @return Returns the remoteInfo.
109      */

110     public ConsumerInfo getRemoteInfo(){
111         return remoteInfo;
112     }
113
114     /**
115      * @param remoteInfo The remoteInfo to set.
116      */

117     public void setRemoteInfo(ConsumerInfo remoteInfo){
118         this.remoteInfo=remoteInfo;
119     }
120     
121 }
122
Popular Tags