1 18 package org.apache.activemq.broker.region; 19 20 import javax.jms.InvalidSelectorException ; 21 import javax.jms.JMSException ; 22 import org.apache.activemq.broker.Broker; 23 import org.apache.activemq.broker.ConnectionContext; 24 import org.apache.activemq.command.ActiveMQDestination; 25 import org.apache.activemq.command.ActiveMQTempDestination; 26 import org.apache.activemq.command.ConsumerInfo; 27 import org.apache.activemq.memory.UsageManager; 28 import org.apache.activemq.thread.TaskRunnerFactory; 29 30 34 public class TempQueueRegion extends AbstractRegion { 35 36 public TempQueueRegion(RegionBroker broker,DestinationStatistics destinationStatistics, UsageManager memoryManager, TaskRunnerFactory taskRunnerFactory, DestinationFactory destinationFactory) { 37 super(broker,destinationStatistics, memoryManager, taskRunnerFactory, destinationFactory); 38 } 41 42 protected Destination createDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception { 43 final ActiveMQTempDestination tempDest = (ActiveMQTempDestination) destination; 44 return new Queue(destination, memoryManager, null, destinationStatistics, taskRunnerFactory, null) { 45 46 public void addSubscription(ConnectionContext context,Subscription sub) throws Exception { 47 48 if( !context.isNetworkConnection() && !tempDest.getConnectionId().equals( sub.getConsumerInfo().getConsumerId().getConnectionId() ) ) { 51 throw new JMSException ("Cannot subscribe to remote temporary destination: "+tempDest); 52 } 53 super.addSubscription(context, sub); 54 }; 55 56 }; 57 } 58 59 protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws InvalidSelectorException { 60 if( info.isBrowser() ) { 61 return new QueueBrowserSubscription(broker,context, info); 62 } else { 63 return new QueueSubscription(broker,context, info); 64 } 65 } 66 67 public String toString() { 68 return "TempQueueRegion: destinations="+destinations.size()+", subscriptions="+subscriptions.size()+", memory="+memoryManager.getPercentUsage()+"%"; 69 } 70 71 public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception { 72 73 if( timeout == 0 ) 77 timeout = 1; 78 79 super.removeDestination(context, destination, timeout); 80 } 81 82 } 83 | Popular Tags |