1 22 package org.jboss.jms.asf; 23 24 import javax.management.ObjectName ; 25 import javax.naming.InitialContext ; 26 import javax.naming.NamingException ; 27 28 import org.jboss.util.naming.NonSerializableFactory; 29 import org.jboss.system.ServiceMBeanSupport; 30 import org.jboss.tm.XidFactoryMBean; 31 32 40 public class ServerSessionPoolLoader extends ServiceMBeanSupport implements ServerSessionPoolLoaderMBean 41 { 42 43 private ServerSessionPoolFactory poolFactory; 44 45 46 private String name; 47 48 49 private String poolFactoryClass; 50 51 private ObjectName xidFactory; 52 53 public void setPoolName(final String name) 54 { 55 this.name = name; 56 } 57 58 public String getPoolName() 59 { 60 return name; 61 } 62 63 public void setPoolFactoryClass(final String classname) 64 { 65 this.poolFactoryClass = classname; 66 } 67 68 public String getPoolFactoryClass() 69 { 70 return poolFactoryClass; 71 } 72 73 public ObjectName getXidFactory() 74 { 75 return xidFactory; 76 } 77 78 public void setXidFactory(final ObjectName xidFactory) 79 { 80 this.xidFactory = xidFactory; 81 } 82 83 protected void startService() throws Exception 84 { 85 XidFactoryMBean xidFactoryObj = (XidFactoryMBean) getServer().getAttribute(xidFactory, "Instance"); 86 87 Class 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 ctx = new InitialContext (); 94 String name = poolFactory.getName(); 95 String 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 InitialContext ctx = null; 111 try 112 { 113 ctx = new InitialContext (); 114 String name = poolFactory.getName(); 115 String 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 ignore) 122 { 123 } 124 finally 125 { 126 if (ctx != null) 127 { 128 try 129 { 130 ctx.close(); 131 } 132 catch (NamingException ignore) 133 { 134 } 135 } 136 } 137 } 138 } 139 | Popular Tags |