Calling JMX MBeans from Flash (JRun only)

You can call Macromedia JRun application functionality through JMX using Flash Remoting MX. You connect to a JMX MBean object using the MBean object name in the ActionScript getService function. Service functions are methods defined in the MBean's manageable interface. The following sections describe how to get a reference to a JMX MBean object and call its methods.

To grant clients access to JMX MBeans, you must provide permissions that specify the exposed MBean object names in the jrun_root/lib/jrun.policy file. For example, the following line of text, which is currently uncommented in the jrun.policy file, exposes the DeployerService for the JRun Flash samples:

permission jrun.security.JMXPermission "accessMBean.DefaultDomain:service=DeployerService"; 

You can also use wildcards to grant access to JMX MBeans. For example, to grant access to all MBeans under the DefaultDomain using a wildcard, you would uncomment the following line in the jrun.policy file:

// permission jrun.security.JMXPermission "accessMBean.DefaultDomain:*";

Getting a reference to an MBean in ActionScript

Before calling the methods of an MBean from ActionScript, you must get a reference to to an MBean.

To get a reference to an MBean:

  1. Include the NetServices.as file:
    #include "NetServices.as"
    
  2. Specify the default Flash Remoting gateway URL:
    NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway"); 
    

    Note:   There are several other ways to specify the gateway URL. For more information, see, "Using Flash Remoting Components in ActionScript," on page 13.

  3. Connect to the Flash Remoting gateway:
    gatewayConnection = NetServices.createGatewayConnection();
    
  4. Get a reference to the MBean object; you must provide the name of the JMX object under which the MBean is registered in the getService function, as shown in the following example:
    jrunDeployerMBean = gatewayConnection.getService ("DefaultDomain:service = DeployerService", this);
    

Invoking MBean methods in ActionScript

Once you have a reference to an MBean, you can use ActionScript functions to invoke its public methods. For example, you could use the following ActionScript code to invoke the getEARs method of the jrunDeployerMBean MBean to get a list of JMX object names for deployed enterprise applications:

function getEARs()
{
  jrunDeployerMBean.getEARs();
}

To handle the function results, you use a result handler function like the following:

function getEARs_Result(result)
{
  numDeployed.text = result.length;
}

For more information about handling results in ActionScript, see "Handling function results in ActionScript".