1 22 package org.jboss.mq.il; 23 24 import java.util.Properties ; 25 26 import javax.jms.IllegalStateException ; 27 import javax.management.ObjectName ; 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 32 import org.jboss.mq.GenericConnectionFactory; 33 import org.jboss.mq.SpyConnectionFactory; 34 import org.jboss.mq.SpyXAConnectionFactory; 35 import org.jboss.system.ServiceMBeanSupport; 36 37 48 public abstract class ServerILJMXService extends ServiceMBeanSupport implements ServerILJMXServiceMBean 49 { 50 51 private ObjectName jbossMQService; 52 53 protected Invoker jmsServer; 54 55 protected String connectionFactoryJNDIRef; 56 57 protected String xaConnectionFactoryJNDIRef; 58 59 protected long pingPeriod = 60000L; 60 61 62 protected String clientID; 63 64 71 public ObjectName getJBossMQService() 72 { 73 return jbossMQService; 74 } 75 76 83 public void setInvoker(ObjectName jbossMQService) 84 { 85 this.jbossMQService = jbossMQService; 86 } 87 88 public void startService() throws Exception 89 { 90 jmsServer = (Invoker) getServer().getAttribute(jbossMQService, "Invoker"); 91 if (jmsServer == null) 92 { 93 throw new IllegalStateException ("Cannot find JBossMQService!"); 94 } } 96 97 public void stopService() throws Exception 98 { 99 jmsServer = null; 100 } 101 102 108 public void setConnectionFactoryJNDIRef(java.lang.String newConnectionFactoryJNDIRef) 109 { 110 connectionFactoryJNDIRef = newConnectionFactoryJNDIRef; 111 } 112 113 119 public void setXAConnectionFactoryJNDIRef(java.lang.String newXaConnectionFactoryJNDIRef) 120 { 121 xaConnectionFactoryJNDIRef = newXaConnectionFactoryJNDIRef; 122 } 123 124 129 public java.util.Properties getClientConnectionProperties() 130 { 131 Properties rc = new Properties (); 132 rc.setProperty(ServerILFactory.PING_PERIOD_KEY, "" + pingPeriod); 133 if (clientID != null) 134 rc.setProperty(ServerILFactory.CLIENTID, clientID); 135 return rc; 136 } 137 138 142 public abstract ServerIL getServerIL(); 143 144 150 public java.lang.String getConnectionFactoryJNDIRef() 151 { 152 return connectionFactoryJNDIRef; 153 } 154 155 161 public java.lang.String getXAConnectionFactoryJNDIRef() 162 { 163 return xaConnectionFactoryJNDIRef; 164 } 165 166 171 public void bindJNDIReferences() throws javax.naming.NamingException 172 { 173 GenericConnectionFactory gcf = new GenericConnectionFactory(getServerIL(), getClientConnectionProperties()); 174 SpyConnectionFactory scf = new SpyConnectionFactory(gcf); 175 SpyXAConnectionFactory sxacf = new SpyXAConnectionFactory(gcf); 176 177 InitialContext ctx = getInitialContext(); 179 rebind(ctx, connectionFactoryJNDIRef, scf); 180 rebind(ctx, xaConnectionFactoryJNDIRef, sxacf); 181 182 } 183 184 protected InitialContext getInitialContext() 185 throws NamingException 186 { 187 InitialContext ctx = new InitialContext (); 188 return ctx; 189 } 190 191 protected void rebind(Context ctx, String name, Object val) throws NamingException 192 { 193 javax.naming.Name n = ctx.getNameParser("").parse(name); 196 while (n.size() > 1) 197 { 198 String ctxName = n.get(0); 199 try 200 { 201 ctx = (Context ) ctx.lookup(ctxName); 202 } 203 catch (javax.naming.NameNotFoundException e) 204 { 205 ctx = ctx.createSubcontext(ctxName); 206 } 207 n = n.getSuffix(1); 208 } 209 210 ctx.rebind(n.get(0), val); 211 } 212 213 218 public void unbindJNDIReferences() throws javax.naming.NamingException 219 { 220 InitialContext ctx = getInitialContext(); 222 ctx.unbind(connectionFactoryJNDIRef); 223 ctx.unbind(xaConnectionFactoryJNDIRef); 224 } 225 226 231 public Invoker getJMSServer() 232 { 233 return jmsServer; 234 } 235 236 241 public Invoker lookupJMSServer() 242 { 243 return getJMSServer(); 244 } 245 246 252 public long getPingPeriod() 253 { 254 return pingPeriod; 255 } 256 257 263 public void setPingPeriod(long period) 264 { 265 pingPeriod = period; 266 } 267 268 274 public String getClientID() 275 { 276 return clientID; 277 } 278 279 285 public void setClientID(String clientID) 286 { 287 this.clientID = clientID; 288 } 289 290 } 291 | Popular Tags |