KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > ConnectionContext


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.broker;
19
20 import java.util.concurrent.ConcurrentHashMap JavaDoc;
21 import java.util.concurrent.atomic.AtomicBoolean JavaDoc;
22 import java.util.concurrent.atomic.AtomicInteger JavaDoc;
23
24 import org.apache.activemq.broker.region.MessageReference;
25 import org.apache.activemq.command.ConnectionId;
26 import org.apache.activemq.command.ConnectionInfo;
27 import org.apache.activemq.command.WireFormatInfo;
28 import org.apache.activemq.filter.MessageEvaluationContext;
29 import org.apache.activemq.security.MessageAuthorizationPolicy;
30 import org.apache.activemq.security.SecurityContext;
31 import org.apache.activemq.transaction.Transaction;
32
33 import java.io.IOException JavaDoc;
34
35 /**
36  * Used to hold context information needed to process requests sent to a broker.
37  *
38  * @version $Revision: 1.5 $
39  */

40 public class ConnectionContext {
41     
42     private Connection connection;
43     private Connector connector;
44     private Broker broker;
45     private boolean inRecoveryMode;
46     private Transaction transaction;
47     private ConcurrentHashMap JavaDoc transactions;
48     private SecurityContext securityContext;
49     private ConnectionId connectionId;
50     private String JavaDoc clientId;
51     private String JavaDoc userName;
52     private boolean haAware;
53     private WireFormatInfo wireFormatInfo;
54     private Object JavaDoc longTermStoreContext;
55     private boolean producerFlowControl=true;
56     private MessageAuthorizationPolicy messageAuthorizationPolicy;
57     private AtomicInteger JavaDoc referenceCounter = new AtomicInteger JavaDoc();
58     private boolean networkConnection;
59     private final AtomicBoolean JavaDoc stopping = new AtomicBoolean JavaDoc();
60     private final MessageEvaluationContext messageEvaluationContext = new MessageEvaluationContext();
61     private boolean dontSendReponse;
62     
63     public ConnectionContext() {
64     }
65     
66     public ConnectionContext(ConnectionInfo info) {
67         setClientId(info.getClientId());
68         setUserName(info.getUserName());
69         setConnectionId(info.getConnectionId());
70     }
71
72     public SecurityContext getSecurityContext() {
73         return securityContext;
74     }
75
76     public void setSecurityContext(SecurityContext subject) {
77         this.securityContext = subject;
78         if (subject != null) {
79             setUserName(subject.getUserName());
80         } else {
81             setUserName(null);
82         }
83     }
84
85     /**
86      * @return the broker being used.
87      */

88     public Broker getBroker() {
89         return broker;
90     }
91
92     /**
93      * @param broker being used
94      */

95     public void setBroker(Broker broker) {
96         this.broker = broker;
97     }
98
99     /**
100      * @return the connection being used
101      */

102     public Connection getConnection() {
103         return connection;
104     }
105     
106     /**
107      * @param connection being used
108      */

109     public void setConnection(Connection connection) {
110         this.connection = connection;
111     }
112     
113     /**
114      * @return the transaction being used.
115      */

116     public Transaction getTransaction() {
117         return transaction;
118     }
119     
120     /**
121      * @param transaction being used.
122      */

123     public void setTransaction(Transaction transaction) {
124         this.transaction = transaction;
125     }
126
127     /**
128      * @return the connector being used.
129      */

130     public Connector getConnector() {
131         return connector;
132     }
133
134     /**
135      * @param connector being used.
136      */

137     public void setConnector(Connector connector) {
138         this.connector = connector;
139     }
140
141     
142     public MessageAuthorizationPolicy getMessageAuthorizationPolicy() {
143         return messageAuthorizationPolicy;
144     }
145
146     /**
147      * Sets the policy used to decide if the current connection is authorized to consume
148      * a given message
149      */

150     public void setMessageAuthorizationPolicy(MessageAuthorizationPolicy messageAuthorizationPolicy) {
151         this.messageAuthorizationPolicy = messageAuthorizationPolicy;
152     }
153
154     /**
155      * @return
156      */

157     public boolean isInRecoveryMode() {
158         return inRecoveryMode;
159     }
160
161     public void setInRecoveryMode(boolean inRecoveryMode) {
162         this.inRecoveryMode = inRecoveryMode;
163     }
164
165     public ConcurrentHashMap JavaDoc getTransactions() {
166         return transactions;
167     }
168     
169     public void setTransactions(ConcurrentHashMap JavaDoc transactions) {
170         this.transactions = transactions;
171     }
172
173     public boolean isInTransaction() {
174         return transaction!=null;
175     }
176
177     public String JavaDoc getClientId() {
178         return clientId;
179     }
180
181     public void setClientId(String JavaDoc clientId) {
182         this.clientId = clientId;
183     }
184
185     public boolean isHaAware() {
186         return haAware;
187     }
188
189     public void setHaAware(boolean haAware) {
190         this.haAware = haAware;
191     }
192
193     public WireFormatInfo getWireFormatInfo() {
194         return wireFormatInfo;
195     }
196
197     public void setWireFormatInfo(WireFormatInfo wireFormatInfo) {
198         this.wireFormatInfo = wireFormatInfo;
199     }
200
201     public ConnectionId getConnectionId() {
202         return connectionId;
203     }
204
205     public void setConnectionId(ConnectionId connectionId) {
206         this.connectionId = connectionId;
207     }
208
209     public String JavaDoc getUserName() {
210         return userName;
211     }
212
213     protected void setUserName(String JavaDoc userName) {
214         this.userName = userName;
215     }
216
217     public MessageEvaluationContext getMessageEvaluationContext() {
218         return messageEvaluationContext;
219     }
220
221     public Object JavaDoc getLongTermStoreContext() {
222         return longTermStoreContext;
223     }
224
225     public void setLongTermStoreContext(Object JavaDoc longTermStoreContext) {
226         this.longTermStoreContext = longTermStoreContext;
227     }
228
229     public boolean isProducerFlowControl() {
230         return producerFlowControl;
231     }
232
233     public void setProducerFlowControl(boolean disableProducerFlowControl) {
234         this.producerFlowControl = disableProducerFlowControl;
235     }
236
237     public boolean isAllowedToConsume(MessageReference n) throws IOException JavaDoc {
238         if (messageAuthorizationPolicy != null) {
239             return messageAuthorizationPolicy.isAllowedToConsume(this, n.getMessage());
240         }
241         return true;
242     }
243
244     public int incrementReference() {
245         return referenceCounter.incrementAndGet();
246     }
247     
248     public int decrementReference() {
249         return referenceCounter.decrementAndGet();
250     }
251
252     public synchronized boolean isNetworkConnection() {
253         return networkConnection;
254     }
255
256     public synchronized void setNetworkConnection(boolean networkConnection) {
257         this.networkConnection = networkConnection;
258     }
259     
260     public AtomicBoolean JavaDoc getStopping() {
261         return stopping;
262     }
263
264     public void setDontSendReponse(boolean b) {
265         this.dontSendReponse=b;
266     }
267
268     public boolean isDontSendReponse() {
269         return dontSendReponse;
270     }
271     
272 }
273
Popular Tags