Posts filed under 'cluster'

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…

Post to Twitter Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Post to Ping.fm Ping This Post

Add comment 13 September 2007 at 6:17 PM

A singleton MDB in a JBoss cluster AS 4.x

Sorry, but this post is not available in English

Post to Twitter Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Post to Ping.fm Ping This Post

18 comments 20 October 2006 at 7:45 PM