KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > asf > ServerSessionPoolLoader


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.jms.asf;
23
24 import javax.management.ObjectName JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26 import javax.naming.NamingException JavaDoc;
27
28 import org.jboss.util.naming.NonSerializableFactory;
29 import org.jboss.system.ServiceMBeanSupport;
30 import org.jboss.tm.XidFactoryMBean;
31
32 /**
33  * A loader for <tt>ServerSessionPools</tt>.
34  *
35  * @author <a HREF="mailto:peter.antman@tim.se">Peter Antman</a>.
36  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
37  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
38  * @version $Revision: 38364 $
39  */

40 public class ServerSessionPoolLoader extends ServiceMBeanSupport implements ServerSessionPoolLoaderMBean
41 {
42    /** The factory used to create server session pools. */
43    private ServerSessionPoolFactory poolFactory;
44
45    /** The name of the pool. */
46    private String JavaDoc name;
47
48    /** The type of pool factory to use. */
49    private String JavaDoc poolFactoryClass;
50
51    private ObjectName JavaDoc xidFactory;
52
53    public void setPoolName(final String JavaDoc name)
54    {
55       this.name = name;
56    }
57
58    public String JavaDoc getPoolName()
59    {
60       return name;
61    }
62
63    public void setPoolFactoryClass(final String JavaDoc classname)
64    {
65       this.poolFactoryClass = classname;
66    }
67
68    public String JavaDoc getPoolFactoryClass()
69    {
70       return poolFactoryClass;
71    }
72
73    public ObjectName JavaDoc getXidFactory()
74    {
75       return xidFactory;
76    }
77
78    public void setXidFactory(final ObjectName JavaDoc xidFactory)
79    {
80       this.xidFactory = xidFactory;
81    }
82
83    protected void startService() throws Exception JavaDoc
84    {
85       XidFactoryMBean xidFactoryObj = (XidFactoryMBean) getServer().getAttribute(xidFactory, "Instance");
86
87       Class JavaDoc cls = Class.forName(poolFactoryClass);
88       poolFactory = (ServerSessionPoolFactory) cls.newInstance();
89       poolFactory.setName(name);
90       poolFactory.setXidFactory(xidFactoryObj);
91       log.debug("initialized with pool factory: " + poolFactory);
92
93       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
94       String JavaDoc name = poolFactory.getName();
95       String JavaDoc jndiname = "java:/" + name;
96       try
97       {
98          NonSerializableFactory.rebind(ctx, jndiname, poolFactory);
99          log.debug("pool factory " + name + " bound to " + jndiname);
100       }
101       finally
102       {
103          ctx.close();
104       }
105    }
106
107    protected void stopService()
108    {
109       // Unbind from JNDI
110
InitialContext JavaDoc ctx = null;
111       try
112       {
113          ctx = new InitialContext JavaDoc();
114          String JavaDoc name = poolFactory.getName();
115          String JavaDoc jndiname = "java:/" + name;
116
117          ctx.unbind(jndiname);
118          NonSerializableFactory.unbind(jndiname);
119          log.debug("pool factory " + name + " unbound from " + jndiname);
120       }
121       catch (NamingException JavaDoc ignore)
122       {
123       }
124       finally
125       {
126          if (ctx != null)
127          {
128             try
129             {
130                ctx.close();
131             }
132             catch (NamingException JavaDoc ignore)
133             {
134             }
135          }
136       }
137    }
138 }
139
Popular Tags