KickJava   Java API By Example, From Geeks To Geeks.

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


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.jms.JMSException JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28 import javax.management.InstanceNotFoundException JavaDoc;
29 import javax.management.MBeanException JavaDoc;
30 import javax.management.ReflectionException JavaDoc;
31 import org.jboss.mq.SpyQueue;
32 import org.jboss.mq.server.JMSDestinationManager;
33 import org.jboss.mq.server.JMSQueue;
34 import org.jboss.mq.SpyDestination;
35 import org.jboss.naming.Util;
36
37 /**
38  * lite wrapper so that this can work in a dependency injection framework.
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  * @version $Revision: 57013 $
42  */

43 public class Queue extends org.jboss.mq.server.jmx.Queue
44 {
45    protected JMSDestinationManager destinationManagerPojo;
46    protected Hashtable JavaDoc initialContextProperties;
47
48
49    public void setDestinationName(String JavaDoc name)
50    {
51       this.destinationName = name;
52    }
53
54    public String JavaDoc getDestinationName()
55    {
56       return destinationName;
57    }
58
59    protected void setupSecurityManager() throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
60    {
61       // todo
62
}
63
64    protected void teardownSecurityManager() throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc
65    {
66       // todo
67
}
68
69    public void create() throws Exception JavaDoc
70    {
71       // Copy default values from the server when null or zero
72
if (parameters.receiversImpl == null)
73          parameters.receiversImpl = destinationManagerPojo.getParameters().receiversImpl;
74       if (parameters.recoveryRetries == 0)
75          parameters.recoveryRetries = destinationManagerPojo.getParameters().recoveryRetries;
76    }
77
78    public void start() throws Exception JavaDoc
79    {
80       // todo set up security manager.
81
/*
82       if (securityManager != null)
83       {
84          // Set securityConf at manager
85          getServer().invoke(securityManager, "addDestination", new Object[]{spyDest.getName(), securityConf}, new String[]{"java.lang.String", "org.w3c.dom.Element"});
86       }
87       */

88       if (destinationName == null || destinationName.length() == 0)
89       {
90          throw new javax.jms.IllegalStateException JavaDoc("QueueName was not set");
91       }
92
93       spyDest = new SpyQueue(destinationName);
94       destination = new JMSQueue(spyDest, null, destinationManagerPojo, parameters);
95
96       destinationManagerPojo.addDestination(destination);
97
98       if (jndiName == null) {
99          setJNDIName("queue/" + destinationName);
100       }
101       else {
102          // in config phase, all we did was store the name, and not actually bind
103
setJNDIName(jndiName);
104       }
105    }
106    
107    public void setExpiryDestinationJndi(String JavaDoc jndi) throws Exception JavaDoc
108    {
109       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
110       parameters.expiryDestination = (SpyDestination)ctx.lookup(jndi);
111    }
112    
113    public void stop()
114    {
115       try
116       {
117          // unbind from JNDI
118
if (jndiBound)
119          {
120             InitialContext JavaDoc ctx = getInitialContext();
121             try
122             {
123                log.info("Unbinding JNDI name: " + jndiName);
124                Util.unbind(ctx, jndiName);
125             }
126             finally
127             {
128                ctx.close();
129             }
130             jndiName = null;
131             jndiBound = false;
132          }
133
134          if (destinationManagerPojo != null)
135             destinationManagerPojo.closeDestination(spyDest);
136
137          // TODO: need to remove from JMSServer
138
/*
139          if (securityManager != null)
140          {
141             // Set securityConf at manager
142             getServer().invoke(securityManager, "removeDestination", new Object[]{spyDest.getName()}, new String[]{"java.lang.String"});
143          }
144          */
}
145       catch (NamingException JavaDoc e)
146       {
147          throw new RuntimeException JavaDoc(e);
148       }
149       catch (JMSException JavaDoc e)
150       {
151          throw new RuntimeException JavaDoc(e);
152       }
153    }
154
155    protected InitialContext JavaDoc getInitialContext()
156            throws NamingException JavaDoc
157    {
158       InitialContext JavaDoc ctx1 = null;
159       if (initialContextProperties != null)
160       {
161          ctx1 = new InitialContext JavaDoc(initialContextProperties);
162       }
163       else ctx1 = new InitialContext JavaDoc();
164       InitialContext JavaDoc ctx = ctx1;
165       return ctx;
166    }
167
168    public void destroy()
169    {
170    }
171
172    public Hashtable JavaDoc getInitialContextProperties()
173    {
174       return initialContextProperties;
175    }
176
177    public void setInitialContextProperties(Hashtable JavaDoc initialContextProperties)
178    {
179       this.initialContextProperties = initialContextProperties;
180    }
181
182    public JMSDestinationManager getDestinationManagerPojo()
183    {
184       return destinationManagerPojo;
185    }
186
187    public void setDestinationManagerPojo(JMSDestinationManager destinationManagerPojo)
188    {
189       this.destinationManagerPojo = destinationManagerPojo;
190    }
191 }
192
Popular Tags