Java API

From jManage

You can access jManage via a set of Java APIs, which allows jManage to be used as a backend system and also allows applications to register themselves as they come online. This interface is new in the 1.0 release and still experimental.

 Note: To enable remote access, add JMANAGE_HOME/lib/client/jmanage-client.jar to your application classpath.

Here are some examples:

Invoking an operation:

 RemoteServiceContextFactory.setJManageURL("http://localhost:9090");
 ServiceContext context = RemoteServiceContextFactory.getServiceContext(
               "admin", "123456",
               "testApp1",
               "jmanage:name=DataFormat,type=test");
 MBeanService mbeanService = ServiceFactory.getMBeanService();
 OperationResultData[] result = mbeanService.invoke(context,
                                "retrieveXMLData", new String[]{});
 /* this is not a cluster, so the number of results must be 1 */
 assert result.length == 1;
    
 System.out.println(result[0].isError()?"Error": "OK");
 System.out.println(result[0].getDisplayOutput());


Adding an application:

 RemoteServiceContextFactory.setJManageURL("http://localhost:9090");
 ServiceContext context = RemoteServiceContextFactory.getServiceContext(
               "admin", "123456",
               null, null);
 ConfigurationService configService = ServiceFactory.getConfigurationService();
 /* Build ApplicationConfigData object */
 ApplicationConfigData configData = new ApplicationConfigData();
 configData.setHost("localhost");
 configData.setPort(new Integer(7001));
 configData.setName("testApp");
 configData.setType("weblogic");
 configData.setUsername("system");
 configData.setPassword("12345678");
 /* add application */
 configData = configService.addApplication(context, configData);
 
 System.out.println("ApplicationId:"   configData.getApplicationId());