1 18 package org.apache.activemq.broker; 19 20 import java.util.concurrent.ConcurrentHashMap ; 21 import java.util.concurrent.atomic.AtomicBoolean ; 22 import java.util.concurrent.atomic.AtomicInteger ; 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 ; 34 35 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 transactions; 48 private SecurityContext securityContext; 49 private ConnectionId connectionId; 50 private String clientId; 51 private String userName; 52 private boolean haAware; 53 private WireFormatInfo wireFormatInfo; 54 private Object longTermStoreContext; 55 private boolean producerFlowControl=true; 56 private MessageAuthorizationPolicy messageAuthorizationPolicy; 57 private AtomicInteger referenceCounter = new AtomicInteger (); 58 private boolean networkConnection; 59 private final AtomicBoolean stopping = new AtomicBoolean (); 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 88 public Broker getBroker() { 89 return broker; 90 } 91 92 95 public void setBroker(Broker broker) { 96 this.broker = broker; 97 } 98 99 102 public Connection getConnection() { 103 return connection; 104 } 105 106 109 public void setConnection(Connection connection) { 110 this.connection = connection; 111 } 112 113 116 public Transaction getTransaction() { 117 return transaction; 118 } 119 120 123 public void setTransaction(Transaction transaction) { 124 this.transaction = transaction; 125 } 126 127 130 public Connector getConnector() { 131 return connector; 132 } 133 134 137 public void setConnector(Connector connector) { 138 this.connector = connector; 139 } 140 141 142 public MessageAuthorizationPolicy getMessageAuthorizationPolicy() { 143 return messageAuthorizationPolicy; 144 } 145 146 150 public void setMessageAuthorizationPolicy(MessageAuthorizationPolicy messageAuthorizationPolicy) { 151 this.messageAuthorizationPolicy = messageAuthorizationPolicy; 152 } 153 154 157 public boolean isInRecoveryMode() { 158 return inRecoveryMode; 159 } 160 161 public void setInRecoveryMode(boolean inRecoveryMode) { 162 this.inRecoveryMode = inRecoveryMode; 163 } 164 165 public ConcurrentHashMap getTransactions() { 166 return transactions; 167 } 168 169 public void setTransactions(ConcurrentHashMap transactions) { 170 this.transactions = transactions; 171 } 172 173 public boolean isInTransaction() { 174 return transaction!=null; 175 } 176 177 public String getClientId() { 178 return clientId; 179 } 180 181 public void setClientId(String 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 getUserName() { 210 return userName; 211 } 212 213 protected void setUserName(String userName) { 214 this.userName = userName; 215 } 216 217 public MessageEvaluationContext getMessageEvaluationContext() { 218 return messageEvaluationContext; 219 } 220 221 public Object getLongTermStoreContext() { 222 return longTermStoreContext; 223 } 224 225 public void setLongTermStoreContext(Object 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 { 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 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 |