1 18 19 package org.apache.activemq.state; 20 21 import java.util.Collection ; 22 import java.util.Set ; 23 24 import org.apache.activemq.command.ConsumerId; 25 import org.apache.activemq.command.ConsumerInfo; 26 import org.apache.activemq.command.ProducerId; 27 import org.apache.activemq.command.ProducerInfo; 28 import org.apache.activemq.command.SessionInfo; 29 30 import java.util.concurrent.ConcurrentHashMap ; 31 import java.util.concurrent.atomic.AtomicBoolean ; 32 33 public class SessionState { 34 final SessionInfo info; 35 36 public final ConcurrentHashMap producers = new ConcurrentHashMap (); 37 public final ConcurrentHashMap consumers = new ConcurrentHashMap (); 38 private final AtomicBoolean shutdown = new AtomicBoolean (false); 39 40 public SessionState(SessionInfo info) { 41 this.info = info; 42 } 43 public String toString() { 44 return info.toString(); 45 } 46 47 public void addProducer(ProducerInfo info) { 48 checkShutdown(); 49 producers.put(info.getProducerId(), new ProducerState(info)); 50 } 51 public ProducerState removeProducer(ProducerId id) { 52 return (ProducerState) producers.remove(id); 53 } 54 55 public void addConsumer(ConsumerInfo info) { 56 checkShutdown(); 57 consumers.put(info.getConsumerId(), new ConsumerState(info)); 58 } 59 public ConsumerState removeConsumer(ConsumerId id) { 60 return (ConsumerState) consumers.remove(id); 61 } 62 63 public SessionInfo getInfo() { 64 return info; 65 } 66 67 public Set getConsumerIds() { 68 return consumers.keySet(); 69 } 70 public Set getProducerIds() { 71 return producers.keySet(); 72 } 73 public Collection getProducerStates() { 74 return producers.values(); 75 } 76 public ProducerState getProducerState(ProducerId producerId) { 77 return (ProducerState) producers.get(producerId); 78 } 79 80 public Collection getConsumerStates() { 81 return consumers.values(); 82 } 83 84 public ConsumerState getConsumerState(ConsumerId consumerId) { 85 return (ConsumerState)consumers.get(consumerId); 86 } 87 88 private void checkShutdown() { 89 if( shutdown.get() ) 90 throw new IllegalStateException ("Disposed"); 91 } 92 93 public void shutdown() { 94 shutdown.set(false); 95 } 96 97 } 98 | Popular Tags |