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.jms.asf;
023:
024: import javax.management.ObjectName;
025: import javax.naming.InitialContext;
026: import javax.naming.NamingException;
027:
028: import org.jboss.util.naming.NonSerializableFactory;
029: import org.jboss.system.ServiceMBeanSupport;
030: import org.jboss.tm.XidFactoryMBean;
031:
032: /**
033: * A loader for <tt>ServerSessionPools</tt>.
034: *
035: * @author <a href="mailto:peter.antman@tim.se">Peter Antman</a>.
036: * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
037: * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
038: * @version $Revision: 57209 $
039: */
040: public class ServerSessionPoolLoader extends ServiceMBeanSupport
041: implements ServerSessionPoolLoaderMBean {
042: /** The factory used to create server session pools. */
043: private ServerSessionPoolFactory poolFactory;
044:
045: /** The name of the pool. */
046: private String name;
047:
048: /** The type of pool factory to use. */
049: private String poolFactoryClass;
050:
051: private ObjectName xidFactory;
052:
053: public void setPoolName(final String name) {
054: this .name = name;
055: }
056:
057: public String getPoolName() {
058: return name;
059: }
060:
061: public void setPoolFactoryClass(final String classname) {
062: this .poolFactoryClass = classname;
063: }
064:
065: public String getPoolFactoryClass() {
066: return poolFactoryClass;
067: }
068:
069: public ObjectName getXidFactory() {
070: return xidFactory;
071: }
072:
073: public void setXidFactory(final ObjectName xidFactory) {
074: this .xidFactory = xidFactory;
075: }
076:
077: protected void startService() throws Exception {
078: XidFactoryMBean xidFactoryObj = (XidFactoryMBean) getServer()
079: .getAttribute(xidFactory, "Instance");
080:
081: Class cls = Class.forName(poolFactoryClass);
082: poolFactory = (ServerSessionPoolFactory) cls.newInstance();
083: poolFactory.setName(name);
084: poolFactory.setXidFactory(xidFactoryObj);
085: log.debug("initialized with pool factory: " + poolFactory);
086:
087: InitialContext ctx = new InitialContext();
088: String name = poolFactory.getName();
089: String jndiname = "java:/" + name;
090: try {
091: NonSerializableFactory.rebind(ctx, jndiname, poolFactory);
092: log.debug("pool factory " + name + " bound to " + jndiname);
093: } finally {
094: ctx.close();
095: }
096: }
097:
098: protected void stopService() {
099: // Unbind from JNDI
100: InitialContext ctx = null;
101: try {
102: ctx = new InitialContext();
103: String name = poolFactory.getName();
104: String jndiname = "java:/" + name;
105:
106: ctx.unbind(jndiname);
107: NonSerializableFactory.unbind(jndiname);
108: log.debug("pool factory " + name + " unbound from "
109: + jndiname);
110: } catch (NamingException ignore) {
111: } finally {
112: if (ctx != null) {
113: try {
114: ctx.close();
115: } catch (NamingException ignore) {
116: }
117: }
118: }
119: }
120: }
|