JMX(Java Management Extensions) 원격 API를 사용하여 JMX(Java Management Extension) 클라이언트 프로그램 개발

JMX(Java™ Management Extensions) 커넥터 스펙과 JMX 원격 API(Application Programming Interface)(JSR 160)를 개발할 수 있습니다. 프로그램은 RMI-IIOP(Remote Method Invocation over Internet Inter-ORB Protocol)를 통해 통신할 수 있습니다.

시작하기 전에

JSR 160, JMX API, 관리 Beans(MBeans)에 대해 학습하십시오. JSR 160에 대한 자세한 정보는 웹(http://www.jcp.org/en/jsr/detail?id=160)에서 JSR 160: JMX(Java Management Extensions) 원격 API를 참조하십시오. JMX API 및 MBean에 대한 자세한 정보는 API(Application Programming Interface) 문서를 참조하십시오.

이 태스크 정보

관리 콘솔, wsadmin 유틸리티 또는 JMX(Java Management Extension) 프로그래밍을 통해 WebSphere® Application Server 환경을 관리할 수 있습니다. JMX 프로그래밍을 통해 환경을 관리할 수 있도록 JMX 원격 API를 사용하여 JMX 원격 클라이언트 프로그램을 개발하려면 이 태스크를 완료하십시오.

프로시저

  1. JMXServiceURL 클래스를 통해 서버의 JMX 커넥터 주소를 지정하십시오.
    JMX 서비스 URL의 값은 다음과 같습니다.
    service:jmx:rmi://" + host + ":" + port + "/jndi/JMXConnector"
    예를 들어, 대상 서버 호스트가 sales.xyz.com이고 청취 포트가 1234인 경우 JMX 서비스 URL은 다음과 같습니다.
    service:jmx:rmi://sales.xyz.com:1234/jndi/JMXConnector

    대상 서버가 포함되어 있는 serverindex.xml 파일이나 콘솔 서버 설정 페이지의 포트 테이블에서 port의 값을 찾을 수 있습니다. URL이 host의 값을 지정하지 않은 경우, 제품이 localhost의 기본값을 사용합니다. URL이 port의 값을 지정하지 않은 경우, 제품이 2809의 기본값을 사용합니다.

    관리 에이전트에 연결할 경우 관리 에이전트 JMX 커넥터 포트 번호를 URL의 끝에 추가하십시오. 예를 들어, 관리 에이전트 JMX 커넥터 호스트가 sales.xyz.com이고 포트가 6789인 경우 다음 URL을 사용하십시오.
    service:jmx:rmi://sales.xyz.com:6789/jndi/JMXConnector6789
  2. 제품의 관리 이름 서비스를 사용하려면 JNDI(Java Naming and Directory Interface) 제공자 URL 특성을 설정하십시오.

    JNDI 프로바이더 URL 특성은 javax.naming.Context.PROVIDER_URL입니다. 관리 네임 서비스는 WsnAdminNameService입니다.

  3. 클라이언트가 보안을 사용하는 경우 클라이언트 JVM(Java Virtual Machine)에서 -Dcom.ibm.CORBA.ConfigURL 및 -Dcom.ibm.SSL.ConfigURL 시스템 특성을 설정하십시오.

    -Dcom.ibm.CORBA.ConfigURL 및 -Dcom.ibm.SSL.ConfigURL 시스템 특성이 유효한 시스템 특성 파일로 설정되지 않은 경우 보안을 사용할 때 클라이언트가 올바르게 작동하지 않습니다. JMX 커넥터 클라이언트를 관리 씬 클라이언트로 실행하는 방법을 권장합니다.

    일반적으로 설치 프로파일 디렉토리(가급적 대상 서버 프로파일 디렉토리)에서 특성 파일을 복사할 수 있습니다.

  4. 보안이 사용 가능한 경우 서버의 사용자 ID 및 비밀번호를 지정하십시오.
  5. JMX 연결을 설정하십시오.
  6. MBean 서버 연결 인스턴스를 가져오십시오.

결과

RMI 연결을 통해 배치 관리자에 대한 연결을 설정하고 노드 에이전트 MBean을 통해 애플리케이션 서버를 시작했습니다.

다음 씬 클라이언트 코드 예제를 사용하여 JMX 클라이언트를 작성하고 사용하십시오.

일부 구문은 인쇄를 위해 여러 줄로 표시됩니다.

import java.io.File;
import java.util.Date;
import java.util.Set;
import java.util.Hashtable;

import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class JMXRemoteClientApp implements NotificationListener {

   private MBeanServerConnection mbsc = null;
   private ObjectName nodeAgent;
   private ObjectName jvm;
   private long ntfyCount = 0;
   private static String userid = null;
   private static String pwd = null;

   public static void main(String[] args)
   {
      try {

         JMXRemoteClientApp client = new JMXRemoteClientApp();

         String host=args[0];
         String port=args[1];
         String nodeName =args[2];
         userid =args[3];
         pwd = args[4];

         client.connect(host,port);

         // Find a node agent MBean
         client.getNodeAgentMBean(nodeName);

         // Invoke the launch process.
         client.invokeLaunchProcess("server1");

         // Register for node agent events
         client.registerNotificationListener();

         // Run until interrupted.
         client.countNotifications();
         
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   private void connect(String host,String port) throws Exception
   {
      String jndiPath="/WsnAdminNameService#JMXConnector";

      JMXServiceURL url =
        new JMXServiceURL("service:jmx:iiop://"+host+"/jndi/corbaname:iiop:"+host+":"+port+jndiPath);

      Hashtable h  = new Hashtable();

      //Specify the user ID and password for the server if security is enabled on server.

      System.out.println("Userid is " + userid);
      System.out.println("Password is " + pwd);
      if ((userid.length() != 0) && (pwd.length() != 0)) {
             System.out.println("adding userid and password to credentials...");
             String[] credentials = new String[] {userid , pwd }; 
             h.put("jmx.remote.credentials", credentials);
              } else {
             System.out.println("No credentials provided.");
      }


      //Establish the JMX connection.

      JMXConnector jmxc = JMXConnectorFactory.connect(url, h);

      //Get the MBean server connection instance.

      mbsc = jmxc.getMBeanServerConnection();

      System.out.println("Connected to DeploymentManager");
   }


   private void getNodeAgentMBean(String nodeName)
   {
      // Query for the object name of the node agent MBean on the given node
      try {
         String query = "WebSphere:type=NodeAgent,node=" + nodeName + ",*";
         ObjectName queryName = new ObjectName(query);
         Set s = mbsc.queryNames(queryName, null);
         if (!s.isEmpty()) {
            nodeAgent = (ObjectName)s.iterator().next();
                System.out.println("NodeAgent mbean found "+ nodeAgent.toString());
                 } else {
            System.out.println("노드 에이전트 MBean was not found");
            System.exit(-1);
         }
      } catch (Exception e) {
         System.out.println(e);
         System.exit(-1);
      }
   }
   
  
   private void invokeLaunchProcess(String serverName)
   {
      // Use the launch process on the node agent MBean to start
      // the given server.
      String opName = "launchProcess";
      String signature[] = { "java.lang.String" };
      String params[] = { serverName };
      boolean launched = false;
      try {
         Boolean b = (Boolean)mbsc.invoke(nodeAgent, opName, params, signature);
         launched = b.booleanValue();
         if (launched)
            System.out.println(serverName + " was launched");
         else
            System.out.println(serverName + " was not launched");

      } catch (Exception e) {
         System.out.println("Exception invoking launchProcess: " + e);
      }
   }
   
  
   private void registerNotificationListener()
   {
      // Register this object as a listener for notifications from the
      // node agent MBean.  Do not use a filter and do not use a handback
      // object.
      try {
         mbsc.addNotificationListener(nodeAgent, this, null, null);
         System.out.println("Registered for event notifications");
      } catch (Exception e) {
         System.out.println(e);
      }
   }

   public void handleNotification(Notification ntfyObj, Object handback)
   {
      // Each notification that the node agent MBean generates results in
      // a call to this method.
      ntfyCount++;
      System.out.println("***************************************************");
      System.out.println("* Notification received at " + new Date().toString());
      System.out.println("* type      = " + ntfyObj.getType());
      System.out.println("* message   = " + ntfyObj.getMessage());
      System.out.println("* source    = " + ntfyObj.getSource());
      System.out.println(
                        "* seqNum    = " + Long.toString(ntfyObj.getSequenceNumber()));
      System.out.println("* timeStamp = " + new Date(ntfyObj.getTimeStamp()));
      System.out.println("* userData  = " + ntfyObj.getUserData());
      System.out.println("***************************************************");

   }

   private void countNotifications()
   {
      // Run until stopped.
      try {
         while (true) {
            Thread.currentThread().sleep(60000);
            System.out.println(ntfyCount + " notification have been received");
         }
      } catch (InterruptedException e) {
      }
   }

}

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjmx_develop_jsr160
파일 이름:tjmx_develop_jsr160.html