KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > kernel > Topic


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq.kernel;
23
24 import java.util.Hashtable JavaDoc;
25 import javax.management.InstanceNotFoundException JavaDoc;
26 import javax.management.MBeanException JavaDoc;
27 import javax.management.ReflectionException JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30 import javax.jms.*;
31 import org.jboss.mq.server.JMSDestinationManager;
32 import org.jboss.mq.server.JMSTopic;
33 import org.jboss.mq.SpyTopic;
34 import org.jboss.naming.Util;
35
36 /**
37  * Comment
38  *
39  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
40  * @version $Revision: 37459 $
41  */

42 public class Topic extends org.jboss.mq.server.jmx.Topic
43 {
44    protected JMSDestinationManager destinationManagerPojo;
45    protected Hashtable JavaDoc initialContextProperties;
46
47
48    public void setDestinationName(String JavaDoc name)
49    {
50       this.destinationName = name;
51    }
52
53    public String JavaDoc getDestinationName()
54    {
55       return destinationName;
56    }
57
58    protected void setupSecurityManager() throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
59    {
60       // todo
61
}
62
63    protected void teardownSecurityManager() throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
64    {
65       // todo
66
}
67
68    protected InitialContext JavaDoc getInitialContext()
69            throws NamingException JavaDoc
70    {
71       InitialContext JavaDoc ctx1 = null;
72       if (initialContextProperties != null)
73       {
74          ctx1 = new InitialContext JavaDoc(initialContextProperties);
75       }
76       else ctx1 = new InitialContext JavaDoc();
77       InitialContext JavaDoc ctx = ctx1;
78       return ctx;
79    }
80
81    public void create() throws Exception JavaDoc
82    {
83       // Copy default values from the server when null or zero
84
if (parameters.receiversImpl == null)
85          parameters.receiversImpl = destinationManagerPojo.getParameters().receiversImpl;
86       if (parameters.recoveryRetries == 0)
87          parameters.recoveryRetries = destinationManagerPojo.getParameters().recoveryRetries;
88    }
89
90    public void start() throws Exception JavaDoc
91    {
92       if (destinationName == null || destinationName.length() == 0)
93       {
94          throw new javax.jms.IllegalStateException JavaDoc("TopicName was not set");
95       }
96
97       spyDest = new SpyTopic(destinationName);
98       destination = new JMSTopic(spyDest, null, destinationManagerPojo, parameters);
99
100       destinationManagerPojo.addDestination(destination);
101
102       if (jndiName == null) {
103             setJNDIName("topic/" + destinationName);
104       }
105       else {
106          // in config phase, we only stored the name, and didn't actually bind it
107
setJNDIName(jndiName);
108       }
109    }
110
111    public void stop()
112    {
113       try
114       {
115          // unbind from JNDI
116
if (jndiBound)
117          {
118             InitialContext JavaDoc ctx = getInitialContext();
119             try
120             {
121                log.info("Unbinding JNDI name: " + jndiName);
122                Util.unbind(ctx, jndiName);
123             }
124             finally
125             {
126                ctx.close();
127             }
128             jndiName = null;
129             jndiBound = false;
130          }
131
132          if (destinationManagerPojo != null)
133             destinationManagerPojo.closeDestination(spyDest);
134
135          // TODO: need to remove from JMSServer
136
/*
137          if (securityManager != null)
138          {
139             // Set securityConf at manager
140             getServer().invoke(securityManager, "removeDestination", new Object[]{spyDest.getName()}, new String[]{"java.lang.String"});
141          }
142          */
}
143       catch (NamingException JavaDoc e)
144       {
145          throw new RuntimeException JavaDoc(e);
146       }
147       catch (JMSException e)
148       {
149          throw new RuntimeException JavaDoc(e);
150       }
151    }
152
153    public void destroy()
154    {
155    }
156
157    public Hashtable JavaDoc getInitialContextProperties()
158    {
159       return initialContextProperties;
160    }
161
162    public void setInitialContextProperties(Hashtable JavaDoc initialContextProperties)
163    {
164       this.initialContextProperties = initialContextProperties;
165    }
166
167    public JMSDestinationManager getDestinationManagerPojo()
168    {
169       return destinationManagerPojo;
170    }
171
172    public void setDestinationManagerPojo(JMSDestinationManager destinationManagerPojo)
173    {
174       this.destinationManagerPojo = destinationManagerPojo;
175    }
176 }
177
Popular Tags