api监控java代码,通过 API 连接到服务器

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:46   1797   0

通过 API 连接到服务器

目前,Java CAPS 提供了 7 个便于您使用 API 连接到 Sun Java System Application Server 的选项。

CAPSManagementClientFactory 客户机用法

选项 1:host, port, userName, password

/** Only relevant piece of code is shown */

ManagementClient client = CAPSManagementClientFactory.getInstance("127.0.0.1",

4848,

"admin",

"adminadmin");

// ... Invoke operations on the returned CAPSManagementClient object ...

选项 2:host, port, userName, password, connectionType

/** Only relevant piece of code is shown */

ManagementClient client = CAPSManagementClientFactory.getInstance("127.0.0.1",

4848,

"admin",

"adminadmin",

ConnectionType.HTTP);

// ... Invoke operations on the returned CAPSManagementClient object ...

选项 3:url, userName, password, isRemoteConnection

/** Only relevant piece of code is shown */

ManagementClient client = CAPSManagementClientFactory.getInstance(

"service:jmx:rmi:///jndi/rmi://localhost:22287/management/rmi-jmx- connector",

"admin", "adminadmin", false);

// ... Invoke operations on the returned CAPSManagementClient object ...

选项 4:MBeanServerConnection

/** Only relevant piece of code is shown */

MBeanServerConnection connection = ... // Get the MBeanServerConnection

ManagementClient client = CAPSManagementClientFactory.getInstance(connection);

// ... Invoke operations on the returned CAPSManagementClient object ...

选项 5:MBeanServerConnection, isRemoteConnection (true/false)

/** Only relevant piece of code is shown */

MBeanServerConnection connection = ... // Get the MBeanServerConnection

ManagementClient client = CAPSManagementClientFactory.getInstance(connection, true);

// ... Invoke operations on the returned CAPSManagementClient object ...

选项 6:host, port, userName, password, connectionType, promtUserForMasterPassword(true/false)

/** Only relevant piece of code is shown */

ManagementClient client =

CAPSManagementClientFactory.getInstance("127.0.0.1",

8686,

"admin",

"adminadmin",

ConnectionType.JRMP,

false);

// ... Invoke operations on the returned CAPSManagementClient object ...

选项 7:hostName, portNumber, userName, password, connectionType, keyStoreFileLocation, masterPassword, promptForMasterPassword (true/false)

/** Only relevant piece of code is shown */

ManagementClient client =

CAPSManagementClientFactory.getInstance

("127.0.0.1",

8686,

"admin",

"adminadmin",

ConnectionType.JRMP,

"C:/CAPS6/Glassfish/

domains/domain1/

config/keystore.jks",

"changeit",

true);

// ... Invoke operations on the returned CAPSManagementClient object ...

连接类型定义

public enum ConnectionType {

HTTP("s1ashttp"),

HTTPS("s1ashttps"),

JRMP("jmxrmi"),

IIOP("iiop");

// ... Implementation ...

/** @return the protocol */

public String getProtocol();

/** @return the protocol description */

public String getDescription();

}

CAPSManagementClientFactory 定义

/** Only relevant piece of code is shown */

public class CAPSManagementClientFactory {

// Option 1 - host, port, userName, password

public static CAPSManagementClient getInstance(String hostName, int portNumber,

String userName, String password) throws ManagementRemoteException {

// ... Implementation ...

}

// Option 2 - host, port, userName, password, connectionType

public static CAPSManagementClient getInstance(String hostName, int portNumber,

String userName, String password, ConnectionType connectionType)

throws ManagementRemoteException {

// ... Implementation ...

}

// Option 3 - url, userName, password, isRemoteConnection

public static CAPSManagementClient getInstance(String url, String userName,

String password, boolean isRemoteConnection) throws

ManagementRemoteException {

// ... Implementation ...

}

// Option 4 - MBeanServerConnection

public static CAPSManagementClient getInstance(MBeanServerConnection connection)

throws ManagementRemoteException {

// ... Implementation ...

}

// Option 5 - MBeanServerConnection, isRemoteConnection

public static CAPSManagementClient getInstance(MBeanServerConnection connection,

boolean isRemoteConnection) throws ManagementRemoteException {

// ... Implementation ...

}

// Option 6 - host, port, userName, password, connectionType,

promtUserForMasterPassword(true/false)

public static CAPSManagementClient getInstance(String hostName, int portNumber,

String userName, String password, ConnectionType connectionType,

boolean promptForPasswordFlag) throws ManagementRemoteException {

// ... Implementation ...

}

// Option 7 - hostName, portNumber, userName, password, connectionType,

keyStoreFileLocation,

// masterPassword, promptForMasterPassword (true/false)

public static CAPSManagementClient getInstance(String hostName, int portNumber,

String userName, String password, ConnectionType connectionType,

String trustStoreFilePath, String trustStorePassword,

boolean promptForPasswordFlag) throws ManagementRemoteException {

// ... Implementation ...

}

}注 –

此软件包以压缩文件形式附带提供了与该主题有关的 Java CAPS 管理 API 样例,例如,AdministrationServiceSample.groovy。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP