BLOG ARTICLE JBoss MBean | 1 ARTICLE FOUND

  1. 2009/02/11 JBoss MBean Access

JBoss에서 원하는 MBean 에 접근하는 코드는 다음과 같습니다. 간단하게 JSP 파일을 만들어 실행해 보면 됩니다.

<%@ page language="java" contentType="text/html; charset=UTF-8"   pageEncoding="UTF-8" import="javax.naming.*, java.util.*,javax.management.*,org.jboss.jms.server.destination.*,org.jboss.jmx.adaptor.rmi.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--meta http-equiv="refresh" content="5"-->
<link href="style.css" rel=stylesheet type="text/css">
<title>Insert title here</title>
</head>
 
<body leftmargin=15 topmargin=10>
<center><p>
<br>
 
<%
            Hashtable<String,String> env = new Hashtable<String,String>();
        String factory = "org.jboss.security.jndi.JndiLoginInitialContextFactory";
        env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
        String url = "jnp://127.0.0.1:1099";
        env.put(Context.PROVIDER_URL, url);
        env.put(Context.SECURITY_CREDENTIALS, "admin");
        env.put(Context.SECURITY_PRINCIPAL, "admin");
        Context ctx = new InitialContext(env);
        RMIAdaptor server = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");

        System.out.println(server);
        String targetName = "jboss.deployment:id=\"HRService\",type=Component";
        //String targetName = "jboss.messaging.destination:name=A,service=Queue";
        //String targetName = "jboss.jca:name='jboss-local-jdbc.rar',service=RARDeployment";
        ObjectName objName = ObjectName.getInstance(targetName);
        out.println(objName.getClass().getName());

    MBeanInfo  info = server.getMBeanInfo(objName);
        System.out.println("JNDIView Class: " + info.getClassName());

    MBeanOperationInfo[] opInfo = info.getOperations();
System.out.println("JNDIView Operations: ");
for(int o = 0; o < opInfo.length; o ++) {
    MBeanOperationInfo op = opInfo[o];

    String returnType = op.getReturnType();
    String opName     = op.getName();
    System.out.print(" + " + returnType + " " + opName + "(");

    MBeanParameterInfo[] params = op.getSignature();
    for(int p = 0; p < params.length; p++)  {
        MBeanParameterInfo paramInfo = params[p];

        String pname = paramInfo.getName();
        String type  = paramInfo.getType();

        if (pname.equals(type)) {
            System.out.print(type);
        } else {
            System.out.print(type + " " + objName);
        }

        if (p < params.length-1) {
            System.out.print(',');
        }
    }
    System.out.println(")");
}

// Invoke the list(boolean) op
//  String[] sig    = {"boolean"};
//   Object[] opArgs = {Boolean.TRUE};
 //   Object   result = server.invoke(objName, "list", opArgs, sig);

  //   System.out.println("JNDIView.list(true) output:\n"+result);

%>


크리에이티브 커먼즈 라이센스
Creative Commons License
2009/02/11 20:11 2009/02/11 20:11