Example usage for javax.management MBeanOperationInfo getName

List of usage examples for javax.management MBeanOperationInfo getName

Introduction

In this page you can find the example usage for javax.management MBeanOperationInfo getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the feature.

Usage

From source file:org.fishwife.jrugged.spring.jmx.TestWebMBeanAdapter.java

@Test
public void testInvokeOperation() throws Exception {
    String operationName = "operation_name";
    expect(mockSanitizer.urlDecode(operationName, ENCODING)).andReturn(operationName);

    MBeanOperationInfo mockOperation = createMock(MBeanOperationInfo.class);
    MBeanOperationInfo[] operationList = new MBeanOperationInfo[1];
    operationList[0] = mockOperation;/*ww  w  . j  a v a  2s .c om*/
    expect(mockMBeanInfo.getOperations()).andReturn(operationList);
    expect(mockOperation.getName()).andReturn(operationName);

    Map<String, String[]> parameterMap = new HashMap<String, String[]>();
    Object value = new Object();
    expect(mockMBeanOperationInvoker.invokeOperation(parameterMap)).andReturn(value);

    String valueString = "some_value";
    expect(mockSanitizer.escapeValue(value)).andReturn(valueString);

    replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation,
            mockMBeanOperationInvoker);

    String invokeResult = webMBeanAdapter.invokeOperation(operationName, parameterMap);

    assertEquals(valueString, invokeResult);
    verify(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation,
            mockMBeanOperationInvoker);
}

From source file:fullThreadDump.java

private void parseMBeanInfo() throws IOException {
    try {/*from  w ww  .j  a  va2  s . c  o  m*/
        MBeanOperationInfo[] mopis = server.getMBeanInfo(objname).getOperations();
        // look for findDeadlockedThreads operations;
        boolean found = false;
        for (MBeanOperationInfo op : mopis) {
            if (op.getName().equals(findDeadlocksMethodName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            // if findDeadlockedThreads operation doesn't exist,
            // the target VM is running on JDK 5 and details about
            // synchronizers and locks cannot be dumped.
            findDeadlocksMethodName = "findMonitorDeadlockedThreads";
            canDumpLocks = false;
        }
    } catch (IntrospectionException e) {
        InternalError ie = new InternalError(e.getMessage());
        ie.initCause(e);
        throw ie;
    } catch (InstanceNotFoundException e) {
        InternalError ie = new InternalError(e.getMessage());
        ie.initCause(e);
        throw ie;
    } catch (ReflectionException e) {
        InternalError ie = new InternalError(e.getMessage());
        ie.initCause(e);
        throw ie;
    }
}

From source file:net.sbbi.upnp.jmx.UPNPMBeanService.java

private String getDeviceSSDP(MBeanInfo info) throws IllegalArgumentException {

    MBeanOperationInfo[] ops = info.getOperations();
    MBeanAttributeInfo[] atts = info.getAttributes();

    if ((ops == null || ops.length == 0) && (atts == null || atts.length == 0)) {
        throw new IllegalArgumentException(
                "MBean has no operation and no attribute and cannot be exposed as an UPNP device, provide at least one attribute");
    }/*w  ww. ja  v  a2 s .c om*/
    Set deployedActionNames = new HashSet();
    operationsStateVariables = new HashMap();
    StringBuffer rtrVal = new StringBuffer();
    rtrVal.append("<?xml version=\"1.0\" ?>\r\n");
    rtrVal.append("<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">\r\n");
    rtrVal.append("<specVersion><major>1</major><minor>0</minor></specVersion>\r\n");

    if (ops != null && ops.length > 0) {
        rtrVal.append("<actionList>\r\n");
        for (int i = 0; i < ops.length; i++) {
            MBeanOperationInfo op = ops[i];
            StringBuffer action = new StringBuffer();
            if (deployedActionNames.contains(op.getName())) {
                log.debug("The " + op.getName()
                        + " is allready deplyoed and cannot be reused, skipping operation deployment");
                continue;
            }
            action.append("<action>\r\n");
            action.append("<name>");
            action.append(op.getName());
            action.append("</name>\r\n");
            action.append("<argumentList>\r\n");
            // output argument
            action.append("<argument>\r\n");
            action.append("<name>");
            // TODO handle specific output vars
            String outVarName = op.getName() + "_out";
            String actionOutDataType = ServiceStateVariable.getUPNPDataTypeMapping(op.getReturnType());
            if (actionOutDataType == null)
                actionOutDataType = ServiceStateVariableTypes.STRING;
            action.append(outVarName);
            action.append("</name>\r\n");
            action.append("<direction>out</direction>\r\n");
            action.append("<relatedStateVariable>");
            action.append(outVarName);
            action.append("</relatedStateVariable>\r\n");
            action.append("</argument>\r\n");

            // handle now for all input argument
            boolean nonPrimitiveInputType = false;
            boolean duplicatedInputVarname = false;
            Map operationsInputStateVariables = new HashMap();
            if (op.getSignature() != null) {
                for (int z = 0; z < op.getSignature().length; z++) {
                    MBeanParameterInfo param = op.getSignature()[z];
                    // do some sanity checks
                    String actionInDataType = ServiceStateVariable.getUPNPDataTypeMapping(param.getType());
                    if (actionInDataType == null) {
                        nonPrimitiveInputType = true;
                        log.debug("The " + param.getType()
                                + " type is not an UPNP compatible data type, use only primitives");
                        break;
                    }
                    String inVarName = param.getName();
                    // check that if the name does allready exists it
                    // has the same type
                    String existing = (String) operationsStateVariables.get(inVarName);
                    if (existing != null && !existing.equals(actionInDataType)) {
                        String msg = "The operation " + op.getName() + " " + inVarName
                                + " parameter already exists for another method with another data type ("
                                + existing + ") either match the data type or change the parameter name"
                                + " in you MBeanParameterInfo object for this operation";
                        duplicatedInputVarname = true;
                        log.debug(msg);
                        break;
                    }
                    action.append("<argument>\r\n");
                    action.append("<name>");
                    operationsInputStateVariables.put(inVarName, actionInDataType);
                    action.append(inVarName);
                    action.append("</name>\r\n");
                    action.append("<direction>in</direction>\r\n");
                    action.append("<relatedStateVariable>");
                    action.append(inVarName);
                    action.append("</relatedStateVariable>\r\n");
                    action.append("</argument>\r\n");
                }
            }

            action.append("</argumentList>\r\n");
            action.append("</action>\r\n");
            // finally the action is only added to the UPNP SSDP if no problems have been detected
            // with the input parameters type and names.
            if (!nonPrimitiveInputType && !duplicatedInputVarname) {
                operationsStateVariables.putAll(operationsInputStateVariables);
                operationsStateVariables.put(outVarName, actionOutDataType);
                rtrVal.append(action.toString());
                deployedActionNames.add(op.getName());
            }
        }
        rtrVal.append("</actionList>\r\n");
    } else {
        rtrVal.append("<actionList/>\r\n");
    }

    // now append the operation created state vars
    rtrVal.append("<serviceStateTable>\r\n");

    for (Iterator i = operationsStateVariables.keySet().iterator(); i.hasNext();) {
        String name = (String) i.next();
        String type = (String) operationsStateVariables.get(name);
        // TODO handle sendevents with mbean notifications ???
        // TODO handle defaultValue and allowedValueList values
        rtrVal.append("<stateVariable sendEvents=\"no\">\r\n");
        rtrVal.append("<name>");
        rtrVal.append(name);
        rtrVal.append("</name>\r\n");
        rtrVal.append("<dataType>");
        rtrVal.append(type);
        rtrVal.append("</dataType>\r\n");
        rtrVal.append("</stateVariable>\r\n");
    }

    if (atts != null && atts.length > 0) {
        for (int i = 0; i < atts.length; i++) {
            MBeanAttributeInfo att = atts[i];
            if (att.isReadable()) {
                rtrVal.append("<stateVariable sendEvents=\"no\">\r\n");
                rtrVal.append("<name>");
                rtrVal.append(att.getName());
                rtrVal.append("</name>\r\n");
                rtrVal.append("<dataType>");
                // TODO check if this works
                String stateVarType = ServiceStateVariable.getUPNPDataTypeMapping(att.getType());
                if (stateVarType == null)
                    stateVarType = ServiceStateVariableTypes.STRING;
                rtrVal.append(stateVarType);
                rtrVal.append("</dataType>\r\n");
                rtrVal.append("</stateVariable>\r\n");
            }
        }
    }
    rtrVal.append("</serviceStateTable>\r\n");
    rtrVal.append("</scpd>");
    return rtrVal.toString();
}

From source file:org.mc4j.ems.impl.jmx.connection.bean.DMBean.java

public synchronized void loadSynchronous() {
    if (!loaded) {
        try {//  w w w  .ja va 2 s  .c om
            info = connectionProvider.getMBeanServer().getMBeanInfo(this.objectName);

            if (info.getAttributes().length > 0) {

                this.attributes = new TreeMap<String, EmsAttribute>(String.CASE_INSENSITIVE_ORDER);
                for (MBeanAttributeInfo attributeInfo : info.getAttributes()) {
                    DAttribute attribute = new DAttribute(attributeInfo, this);
                    this.attributes.put(attributeInfo.getName(), attribute);
                }
            }

            if (info.getOperations().length > 0) {
                this.operations = new TreeMap<String, EmsOperation>(String.CASE_INSENSITIVE_ORDER);
                for (MBeanOperationInfo operationInfo : info.getOperations()) {
                    DOperation operation = new DOperation(operationInfo, this);
                    this.operations.put(operationInfo.getName(), operation);
                }
            }

            if (info.getNotifications().length > 0) {
                this.notifications = new TreeMap<String, EmsNotification>(String.CASE_INSENSITIVE_ORDER);
                for (MBeanNotificationInfo notificationInfo : info.getNotifications()) {
                    DNotification notification = new DNotification(notificationInfo, this);
                    this.notifications.put(notificationInfo.getName(), notification);
                }
            }

        } catch (InstanceNotFoundException infe) {
            this.deleted = true;
            this.attributes = null;
            this.operations = null;
            this.notifications = null;

        } catch (Exception e) {
            unsupportedType = true;
            RuntimeException f = new EmsUnsupportedTypeException(
                    "Could not load MBean info, unsupported type on bean " + objectName, e);
            // TODO: Memory Leak below... don't do that
            //registerFailure(f);
            // TODO should we throw this here?
            //throw f;
        } finally {
            loaded = true;
        }
    }
}

From source file:com.clustercontrol.HinemosManagerCli.java

private void printMBeanInfo(MBeanInfo mbeanInfo) {
    MBeanAttributeInfo[] attributeInfos = mbeanInfo.getAttributes();
    System.out.println("Attributes:");
    for (MBeanAttributeInfo attributeInfo : attributeInfos) {
        System.out.println(String.format("\t%s: %s", attributeInfo.getName(), attributeInfo.getType()));
    }/* w  w  w.  j ava 2s  .c  o  m*/

    MBeanOperationInfo[] operationInfos = mbeanInfo.getOperations();
    System.out.println("Operations:");
    for (MBeanOperationInfo operationInfo : operationInfos) {
        MBeanParameterInfo[] paramInfos = operationInfo.getSignature();

        StringBuffer paramStr = new StringBuffer();
        for (MBeanParameterInfo paramInfo : paramInfos) {
            paramStr.append(paramInfo.getType() + ",");
        }
        if (paramStr.length() != 0) {
            paramStr.append(paramStr.substring(0, paramStr.length() - 1));
        }

        System.out.println(
                String.format("\t%s %s(%s)", operationInfo.getReturnType(), operationInfo.getName(), paramStr));
    }
}

From source file:org.fluentd.jvmwatcher.proxy.JvmClientProxy.java

/**
 * @return//from   w  w w  .  j a  v a2s . c om
 */
public boolean connect() {
    if (this.localJvmInfo_ == null) {
        return false;
    }

    // connect the JVM server
    if (this.localJvmInfo_.isManageable() != true) {
        try {
            // get JVM Agent address
            this.localJvmInfo_.startManagementAgent();
        } catch (IOException ex) {
            log.error("startManagementAgent error.", ex);
            return false;
        } catch (Exception ex) {
            log.error("startManagementAgent error.", ex);
            return false;
        }
    }

    // connect JVM MBean Server 
    try {
        if (this.jmxUrl_ == null) {
            this.jmxUrl_ = new JMXServiceURL(this.localJvmInfo_.getAddress());
            this.jmxc_ = JMXConnectorFactory.connect(jmxUrl_, null);
            this.server_ = this.jmxc_.getMBeanServerConnection();
        }
    } catch (MalformedURLException ex) {
        log.error(" connect JVM MBean Server error.", ex);
        return false;
    } catch (IOException ex) {
        log.error(" connect JVM MBean Server error.", ex);
        return false;
    } catch (Exception ex) {
        log.error(" connect JVM MBean Server error.", ex);
        return false;
    }

    // this client have successfully connected to the JVM server.
    this.isDeadServer_ = false;

    try {
        ObjectName objName = new ObjectName(THREAD_MXBEAN_NAME);
        this.hasPlatformMXBeans_ = this.server_.isRegistered(objName);
        this.hasHotSpotDiagnosticMXBean_ = this.server_
                .isRegistered(new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME));
        // check if it has 6.0 new APIs
        if (this.hasPlatformMXBeans_ = true) {
            MBeanOperationInfo[] mopis = this.server_.getMBeanInfo(objName).getOperations();
            // look for findDeadlockedThreads operations;
            for (MBeanOperationInfo op : mopis) {
                if (op.getName().equals("findDeadlockedThreads")) {
                    this.supportsLockUsage_ = true;
                    break;
                }
            }

            objName = new ObjectName(COMPILATION_MXBEAN_NAME);
            this.hasCompilationMXBean_ = this.server_.isRegistered(objName);
        }

        if (this.hasPlatformMXBeans_ == true) {
            // WORKAROUND for bug 5056632
            // Check if the access role is correct by getting a RuntimeMXBean
            getRuntimeMXBean();
        }
    } catch (MalformedObjectNameException ex) {
        log.error("connect error.", ex);
        return false;
    } catch (IntrospectionException ex) {
        log.error("connect error.", ex);
        return false;
    } catch (InstanceNotFoundException ex) {
        log.error("connect error.", ex);
        return false;
    } catch (ReflectionException ex) {
        log.error("connect error.", ex);
        return false;
    } catch (IOException ex) {
        log.error("connect error.", ex);
        return false;
    } catch (Exception ex) {
        log.error("connect error.", ex);
        return false;
    }

    // connect success.
    this.isConnect_ = true;

    return true;
}

From source file:com.springsource.hq.plugin.tcserver.plugin.appmgmt.TomcatJmxScriptingApplicationManager.java

private boolean isTcRuntime250OrLater(String objectName, String operationName,
        int expected25OrLaterArgumentCount, ConfigResponse config) throws JMException, IOException {
    MBeanServerConnection mBeanServer = mxUtil.getMBeanServer(config.toProperties());
    MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(new ObjectName(objectName));
    for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) {
        if (operationInfo.getName().equals(operationName)
                && (expected25OrLaterArgumentCount == operationInfo.getSignature().length)) {
            return true;
        }// w ww .  jav a2s  .c o  m
    }
    return false;
}

From source file:org.fishwife.jrugged.spring.jmx.TestWebMBeanAdapter.java

@Test
public void testGetOperationMetadata() throws Exception {
    String operationName1 = "operation_name_1";
    MBeanOperationInfo mockOperation1 = createMock(MBeanOperationInfo.class);

    String operationName2 = "operation_name_2";
    MBeanOperationInfo mockOperation2 = createMock(MBeanOperationInfo.class);

    MBeanOperationInfo[] operationList = new MBeanOperationInfo[2];
    operationList[0] = mockOperation1;//from w w  w .j av a  2 s. c om
    operationList[1] = mockOperation2;
    expect(mockMBeanInfo.getOperations()).andReturn(operationList);
    expect(mockOperation1.getName()).andReturn(operationName1);
    expect(mockOperation2.getName()).andReturn(operationName2);

    replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation1, mockOperation2);

    Map<String, MBeanOperationInfo> operationMap = webMBeanAdapter.getOperationMetadata();

    assertEquals(2, operationMap.size());
    assertEquals(mockOperation1, operationMap.get(operationName1));
    assertEquals(mockOperation2, operationMap.get(operationName2));

    verify(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation1, mockOperation2);
}

From source file:org.sakaiproject.status.StatusServlet.java

protected void reportDetailedWebappStatus(HttpServletResponse response) throws Exception {
    PrintWriter pw = response.getWriter();

    for (ObjectName appName : findMBeans("*:j2eeType=WebModule,*")) {
        for (MBeanAttributeInfo mbai : mbs.getMBeanInfo(appName).getAttributes()) {
            pw.print(mbai.getName() + ",");
            pw.print(mbai.getType() + ",");
            pw.print(mbai.getDescription() + ",");
            pw.print(mbs.getAttribute(appName, mbai.getName()) + "\n");
        }/*from   w  w w .j a  v a 2  s.  co  m*/
        pw.print("\n");
        for (MBeanOperationInfo mboi : mbs.getMBeanInfo(appName).getOperations()) {
            pw.print(mboi.getName() + ",");
            pw.print(mboi.getReturnType() + ",");
            pw.print(mboi.getDescription() + "\n");
        }
        pw.print("\n\n");
    }
}

From source file:org.fishwife.jrugged.spring.jmx.TestWebMBeanAdapter.java

@Test
public void testGetOperationInfoWhenItExists() throws Exception {
    String operationName1 = "operation_name_1";
    MBeanOperationInfo mockOperation1 = createMock(MBeanOperationInfo.class);

    String operationName2 = "operation_name_2";
    MBeanOperationInfo mockOperation2 = createMock(MBeanOperationInfo.class);

    expect(mockSanitizer.urlDecode(operationName2, ENCODING)).andReturn(operationName2);
    MBeanOperationInfo[] operationList = new MBeanOperationInfo[2];
    operationList[0] = mockOperation1;/*from w w w .jav  a 2 s.c o  m*/
    operationList[1] = mockOperation2;
    expect(mockMBeanInfo.getOperations()).andReturn(operationList);
    expect(mockOperation1.getName()).andReturn(operationName1);
    expect(mockOperation2.getName()).andReturn(operationName2);

    replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation1, mockOperation2);

    MBeanOperationInfo operationInfo = webMBeanAdapter.getOperationInfo(operationName2);

    assertEquals(mockOperation2, operationInfo);

    verify(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation1, mockOperation2);
}