001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mq.kernel;
023:
024: import java.util.Hashtable;
025: import javax.jms.JMSException;
026: import javax.naming.InitialContext;
027: import javax.naming.NamingException;
028: import javax.management.InstanceNotFoundException;
029: import javax.management.MBeanException;
030: import javax.management.ReflectionException;
031:
032: import org.jboss.mq.SpyQueue;
033: import org.jboss.mq.server.JMSDestinationManager;
034: import org.jboss.mq.server.JMSQueue;
035: import org.jboss.mq.SpyDestination;
036: import org.jboss.util.naming.Util;
037:
038: /**
039: * lite wrapper so that this can work in a dependency injection framework.
040: *
041: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
042: * @version $Revision: 60195 $
043: */
044: public class Queue extends org.jboss.mq.server.jmx.Queue {
045: protected JMSDestinationManager destinationManagerPojo;
046: protected Hashtable initialContextProperties;
047:
048: public void setDestinationName(String name) {
049: this .destinationName = name;
050: }
051:
052: public String getDestinationName() {
053: return destinationName;
054: }
055:
056: protected void setupSecurityManager()
057: throws InstanceNotFoundException, MBeanException,
058: ReflectionException {
059: // todo
060: }
061:
062: protected void teardownSecurityManager()
063: throws InstanceNotFoundException, MBeanException,
064: ReflectionException {
065: // todo
066: }
067:
068: public void create() throws Exception {
069: // Copy default values from the server when null or zero
070: if (parameters.receiversImpl == null)
071: parameters.receiversImpl = destinationManagerPojo
072: .getParameters().receiversImpl;
073: if (parameters.recoveryRetries == 0)
074: parameters.recoveryRetries = destinationManagerPojo
075: .getParameters().recoveryRetries;
076: }
077:
078: public void start() throws Exception {
079: // todo set up security manager.
080: /*
081: if (securityManager != null)
082: {
083: // Set securityConf at manager
084: getServer().invoke(securityManager, "addDestination", new Object[]{spyDest.getName(), securityConf}, new String[]{"java.lang.String", "org.w3c.dom.Element"});
085: }
086: */
087: if (destinationName == null || destinationName.length() == 0) {
088: throw new javax.jms.IllegalStateException(
089: "QueueName was not set");
090: }
091:
092: spyDest = new SpyQueue(destinationName);
093: destination = new JMSQueue(spyDest, null,
094: destinationManagerPojo, parameters);
095:
096: destinationManagerPojo.addDestination(destination);
097:
098: if (jndiName == null) {
099: setJNDIName("queue/" + destinationName);
100: } else {
101: // in config phase, all we did was store the name, and not actually bind
102: setJNDIName(jndiName);
103: }
104: }
105:
106: public void setExpiryDestinationJndi(String jndi) throws Exception {
107: InitialContext ctx = new InitialContext();
108: parameters.expiryDestination = (SpyDestination) ctx
109: .lookup(jndi);
110: }
111:
112: public void stop() {
113: try {
114: // unbind from JNDI
115: if (jndiBound) {
116: InitialContext ctx = getInitialContext();
117: try {
118: log.info("Unbinding JNDI name: " + jndiName);
119: Util.unbind(ctx, jndiName);
120: } finally {
121: ctx.close();
122: }
123: jndiName = null;
124: jndiBound = false;
125: }
126:
127: if (destinationManagerPojo != null)
128: destinationManagerPojo.closeDestination(spyDest);
129:
130: // TODO: need to remove from JMSServer
131: /*
132: if (securityManager != null)
133: {
134: // Set securityConf at manager
135: getServer().invoke(securityManager, "removeDestination", new Object[]{spyDest.getName()}, new String[]{"java.lang.String"});
136: }
137: */} catch (NamingException e) {
138: throw new RuntimeException(e);
139: } catch (JMSException e) {
140: throw new RuntimeException(e);
141: }
142: }
143:
144: protected InitialContext getInitialContext() throws NamingException {
145: InitialContext ctx1 = null;
146: if (initialContextProperties != null) {
147: ctx1 = new InitialContext(initialContextProperties);
148: } else
149: ctx1 = new InitialContext();
150: InitialContext ctx = ctx1;
151: return ctx;
152: }
153:
154: public void destroy() {
155: }
156:
157: public Hashtable getInitialContextProperties() {
158: return initialContextProperties;
159: }
160:
161: public void setInitialContextProperties(
162: Hashtable initialContextProperties) {
163: this .initialContextProperties = initialContextProperties;
164: }
165:
166: public JMSDestinationManager getDestinationManagerPojo() {
167: return destinationManagerPojo;
168: }
169:
170: public void setDestinationManagerPojo(
171: JMSDestinationManager destinationManagerPojo) {
172: this.destinationManagerPojo = destinationManagerPojo;
173: }
174: }
|