Invoke a singleton MBean inside a cluster node
It needs to deploy RMI Adaptor service in singleton. I can do it creating file above in deploy-hasingleton (singleton-jmx-adapter-service.xml will be ok, it’s necessary it ends with -service.xml):
<server>
<mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory" name="jboss.jmx:type=singletonadaptor,name=Invoker,protocol=jrmp,service=proxyFactory">
<!-- Use the standard JRMPInvoker from conf/jboss-service.xxml -->
<depends optional-attribute-name="InvokerName">jboss:service=invoker,type=jrmp
<attribute name="ClientInterceptors">
<interceptors>
<interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
<interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
<interceptor>org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor</interceptor>
<interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
</interceptors>
</attribute>
</mbean>
</server>
Then inside any session of any cluster node I can invoke a method of MBean Service in this way:
final String RMI_ADAPTOR_JNDI_NAME = "jmx/invoker/SingletonRMIAdaptor";
final String IDTAG_SERVICE_JNDI_NAME = "MyService:service=MyManagerService";
try {
final Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "10.x.x.1:1100,10.x.x.2:1100"); // HA
InitialContext initialContext = new InitialContext(properties);
RMIAdaptor adaptor = (RMIAdaptor) initialContext.lookup(RMI_ADAPTOR_JNDI_NAME);
ObjectName objectName = new ObjectName(IDTAG_SERVICE_JNDI_NAME);
if (adaptor != null && adaptor.isRegistered(objectName)) {
obj = adaptor.invoke(objectName, methodName, params, signature);
} else {
logWriter.debug("---- Error invoking MyManager service: " + adaptor + " ----");
throw new Exception("Error invoking MyManager service");
}
} catch (NamingException ex) {
logWriter.error(ex);
throw ex;
} catch (MalformedObjectNameException ex) {
logWriter.error(ex);
throw ex;
} catch (IOException ex) {
logWriter.error(ex);
throw ex;
} catch (InstanceNotFoundException ex) {
logWriter.error(ex);
throw ex;
} catch (MBeanException ex) {
logWriter.error(ex);
throw ex;
} catch (ReflectionException ex) {
logWriter.error(ex);
throw ex;
}
That’s all…
Buzz This Post
Delicious
Digg This Post
Ping This Post
Add comment 13 September 2007 at 6:17 PM