KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > region > TempTopicRegion


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
4  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
5  * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12  * specific language governing permissions and limitations under the License.
13  */

14
15 package org.apache.activemq.broker.region;
16
17 import javax.jms.JMSException JavaDoc;
18 import org.apache.activemq.broker.ConnectionContext;
19 import org.apache.activemq.command.ActiveMQDestination;
20 import org.apache.activemq.broker.region.cursors.VMPendingMessageCursor;
21 import org.apache.activemq.broker.region.policy.PolicyEntry;
22 import org.apache.activemq.command.ActiveMQDestination;
23 import org.apache.activemq.command.ConsumerInfo;
24 import org.apache.activemq.memory.UsageManager;
25 import org.apache.activemq.thread.TaskRunnerFactory;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  *
31  * @version $Revision: 1.7 $
32  */

33 public class TempTopicRegion extends AbstractRegion{
34
35     private static final Log log=LogFactory.getLog(TempTopicRegion.class);
36
37     public TempTopicRegion(RegionBroker broker,DestinationStatistics destinationStatistics,UsageManager memoryManager,
38             TaskRunnerFactory taskRunnerFactory,DestinationFactory destinationFactory){
39         super(broker,destinationStatistics,memoryManager,taskRunnerFactory,destinationFactory);
40         // We should allow the following to be configurable via a Destination Policy
41
// setAutoCreateDestinations(false);
42
}
43
44     protected Subscription createSubscription(ConnectionContext context,ConsumerInfo info) throws JMSException JavaDoc{
45         if(info.isDurable()){
46             throw new JMSException JavaDoc("A durable subscription cannot be created for a temporary topic.");
47         }
48         try{
49             TopicSubscription answer=new TopicSubscription(broker,context,info,memoryManager);
50             // lets configure the subscription depending on the destination
51
ActiveMQDestination destination=info.getDestination();
52             if(destination!=null&&broker.getDestinationPolicy()!=null){
53                 PolicyEntry entry=broker.getDestinationPolicy().getEntryFor(destination);
54                 if(entry!=null){
55                     entry.configure(broker,memoryManager,answer);
56                 }
57             }
58             answer.init();
59             return answer;
60         }catch(Exception JavaDoc e){
61             log.error("Failed to create TopicSubscription ",e);
62             JMSException JavaDoc jmsEx=new JMSException JavaDoc("Couldn't create TopicSubscription");
63             jmsEx.setLinkedException(e);
64             throw jmsEx;
65         }
66     }
67
68     public String JavaDoc toString(){
69         return "TempTopicRegion: destinations="+destinations.size()+", subscriptions="+subscriptions.size()+", memory="
70                 +memoryManager.getPercentUsage()+"%";
71     }
72     
73     public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception JavaDoc {
74         
75         // Force a timeout value so that we don't get an error that
76
// there is still an active sub. Temp destination may be removed
77
// while a network sub is still active which is valid.
78
if( timeout == 0 )
79             timeout = 1;
80         
81         super.removeDestination(context, destination, timeout);
82     }
83 }
84
Popular Tags