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:
026: import javax.jms.JMSException;
027: import javax.management.InstanceNotFoundException;
028: import javax.management.MBeanException;
029: import javax.management.ReflectionException;
030: import javax.naming.InitialContext;
031: import javax.naming.NamingException;
032:
033: import org.jboss.mq.SpyTopic;
034: import org.jboss.mq.server.JMSDestinationManager;
035: import org.jboss.mq.server.JMSTopic;
036: import org.jboss.util.naming.Util;
037:
038: /**
039: * Comment
040: *
041: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
042: * @version $Revision: 60195 $
043: */
044: public class Topic extends org.jboss.mq.server.jmx.Topic {
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: protected InitialContext getInitialContext() throws NamingException {
069: InitialContext ctx1 = null;
070: if (initialContextProperties != null) {
071: ctx1 = new InitialContext(initialContextProperties);
072: } else
073: ctx1 = new InitialContext();
074: InitialContext ctx = ctx1;
075: return ctx;
076: }
077:
078: public void create() throws Exception {
079: // Copy default values from the server when null or zero
080: if (parameters.receiversImpl == null)
081: parameters.receiversImpl = destinationManagerPojo
082: .getParameters().receiversImpl;
083: if (parameters.recoveryRetries == 0)
084: parameters.recoveryRetries = destinationManagerPojo
085: .getParameters().recoveryRetries;
086: }
087:
088: public void start() throws Exception {
089: if (destinationName == null || destinationName.length() == 0) {
090: throw new javax.jms.IllegalStateException(
091: "TopicName was not set");
092: }
093:
094: spyDest = new SpyTopic(destinationName);
095: destination = new JMSTopic(spyDest, null,
096: destinationManagerPojo, parameters);
097:
098: destinationManagerPojo.addDestination(destination);
099:
100: if (jndiName == null) {
101: setJNDIName("topic/" + destinationName);
102: } else {
103: // in config phase, we only stored the name, and didn't actually bind it
104: setJNDIName(jndiName);
105: }
106: }
107:
108: public void stop() {
109: try {
110: // unbind from JNDI
111: if (jndiBound) {
112: InitialContext ctx = getInitialContext();
113: try {
114: log.info("Unbinding JNDI name: " + jndiName);
115: Util.unbind(ctx, jndiName);
116: } finally {
117: ctx.close();
118: }
119: jndiName = null;
120: jndiBound = false;
121: }
122:
123: if (destinationManagerPojo != null)
124: destinationManagerPojo.closeDestination(spyDest);
125:
126: // TODO: need to remove from JMSServer
127: /*
128: if (securityManager != null)
129: {
130: // Set securityConf at manager
131: getServer().invoke(securityManager, "removeDestination", new Object[]{spyDest.getName()}, new String[]{"java.lang.String"});
132: }
133: */} catch (NamingException e) {
134: throw new RuntimeException(e);
135: } catch (JMSException e) {
136: throw new RuntimeException(e);
137: }
138: }
139:
140: public void destroy() {
141: }
142:
143: public Hashtable getInitialContextProperties() {
144: return initialContextProperties;
145: }
146:
147: public void setInitialContextProperties(
148: Hashtable initialContextProperties) {
149: this .initialContextProperties = initialContextProperties;
150: }
151:
152: public JMSDestinationManager getDestinationManagerPojo() {
153: return destinationManagerPojo;
154: }
155:
156: public void setDestinationManagerPojo(
157: JMSDestinationManager destinationManagerPojo) {
158: this.destinationManagerPojo = destinationManagerPojo;
159: }
160: }
|