1 16 package org.quartz.ee.jmx.jboss; 17 18 import org.quartz.SchedulerException; 19 import org.quartz.impl.RemoteMBeanScheduler; 20 21 import javax.management.AttributeList ; 22 import javax.management.MBeanServerConnection ; 23 import javax.naming.Context ; 24 import javax.naming.InitialContext ; 25 import javax.naming.NamingException ; 26 import java.util.Arrays ; 27 import java.util.Properties ; 28 29 45 public class JBoss4RMIRemoteMBeanScheduler extends RemoteMBeanScheduler { 46 47 private static final String DEFAULT_PROVIDER_URL = "jnp://localhost:1099"; 48 private static final String RMI_ADAPTOR_JNDI_NAME = "jmx/rmi/RMIAdaptor"; 49 50 private MBeanServerConnection server = null; 51 private String providerURL = DEFAULT_PROVIDER_URL; 52 53 public JBoss4RMIRemoteMBeanScheduler() throws SchedulerException { 54 } 55 56 57 62 public void setProviderURL(String providerURL) { 63 this.providerURL = providerURL; 64 } 65 66 70 public void initialize() throws SchedulerException { 71 InitialContext ctx = null; 72 try { 73 ctx = new InitialContext (getContextProperties()); 74 server = (MBeanServerConnection )ctx.lookup(RMI_ADAPTOR_JNDI_NAME); 75 } catch (Exception e) { 76 throw new SchedulerException("Failed to lookup JBoss JMX RMI Adaptor.", e); 77 } finally { 78 if (ctx != null) { 79 try { 80 ctx.close(); 81 } catch (NamingException ignore) { 82 } 83 } 84 } 85 } 86 87 95 protected Properties getContextProperties() { 96 Properties props = new Properties (); 97 props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 98 props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); 99 props.put(Context.PROVIDER_URL, providerURL); 100 101 return props; 102 } 103 104 protected Object getAttribute(String attribute) throws SchedulerException { 105 try { 106 return server.getAttribute(getSchedulerObjectName(), attribute); 107 } catch (Exception e) { 108 throw new SchedulerException("Failed to get Scheduler MBean attribute: " + attribute, e); 109 } 110 } 111 112 protected AttributeList getAttributes(String [] attributes) throws SchedulerException { 113 try { 114 return server.getAttributes(getSchedulerObjectName(), attributes); 115 } catch (Exception e) { 116 throw new SchedulerException("Failed to get Scheduler MBean attributes: " + Arrays.asList(attributes), e); 117 } 118 } 119 120 protected Object invoke(String operationName, Object [] params, 121 String [] signature) throws SchedulerException { 122 try { 123 return server.invoke(getSchedulerObjectName(), operationName, params, signature); 124 } catch (Exception e) { 125 throw new SchedulerException( 126 "Failed to invoke Scheduler MBean operation: " + operationName, e); 127 } 128 } 129 } 130 | Popular Tags |