Examples of EmsOperation


Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

        Class<?>[] emptyParams = new Class<?>[0];

        if (log.isDebugEnabled()) {
            log.debug("Disabling native transport...");
        }
        EmsOperation operation = storageService.getOperation("stopNativeTransport", emptyParams);
        operation.invoke((Object[]) emptyParams);

        if (log.isDebugEnabled()) {
            log.debug("Disabling gossip...");
        }
        operation = storageService.getOperation("stopGossiping", emptyParams);
        operation.invoke((Object[]) emptyParams);

        if (log.isDebugEnabled()) {
            log.debug("Taking the snapshot...");
        }
        operation = storageService.getOperation("takeSnapshot", String.class, String[].class);
        String snapshotName = parameters.getSimpleValue("snapshotName");
        if (snapshotName == null || snapshotName.trim().isEmpty()) {
            snapshotName = System.currentTimeMillis() + "";
        }
        operation.invoke(snapshotName, new String[] {});

        // max 2 sec
        waitForTaskToComplete(500, 10, 150);

        if (log.isDebugEnabled()) {
            log.debug("Initiating drain...");
        }
        operation = storageService.getOperation("drain", emptyParams);
        operation.invoke((Object[]) emptyParams);

        return new OperationResult();
    }
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

    private static final String JBOSS_WEB_MBEAN_NAME_TEMPLATE =
            "jboss.web:J2EEApplication=none,J2EEServer=none,j2eeType=WebModule,name=%s";

    protected static EmsOperation getListDeployedOperation(EmsConnection connection) {
        EmsOperation retOperation;
        EmsBean bean = connection.getBean(MAIN_DEPLOYER);

        // first try the new operation name, used by JBossAS 3.2.8 and 4.x.
        retOperation = bean.getOperation(LIST_DEPLOYED_MODULES_OP_NAME);
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

     * @return Collection of DeploymentInfo
     * @throws Exception If the listDeployed() or listDeployedModuls() ops can not be found.
     */
    private static Collection getDeploymentInformations(EmsConnection connection) throws Exception {
        Collection deploymentInfos = null;
        EmsOperation operation = null;
        try {
            operation = getListDeployedOperation(connection);
            if (operation == null) {
                throw new UnsupportedOperationException(
                    "This JBossAS instance is unsupported; its MainDeployer MBean doesn't have a listDeployedModules or listDeployed operation.");
            }
            deploymentInfos = (Collection) operation.invoke(new Object[0]);
        } catch (RuntimeException re) {
            // Make a last ditch effort in case the call to listDeployedModules() failed due to
            // https://jira.jboss.org/jira/browse/JBAS-5983.
            if (operation != null && operation.getName().equals(LIST_DEPLOYED_MODULES_OP_NAME)) {
                EmsBean mainDeployerMBean = connection.getBean(MAIN_DEPLOYER);
                operation = mainDeployerMBean.getOperation(LIST_DEPLOYED_OP_NAME);
                try {
                    deploymentInfos = (Collection) operation.invoke(new Object[0]);
                }
                catch (RuntimeException re2) {
                    deploymentInfos = null;
                }
            }
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

        if (emsConnection == null) {
            throw new RuntimeException("Can not connect to the server");
        }
        EmsBean bean = emsConnection.getBean("jboss.messaging:service=ServerPeer");

        EmsOperation operation = bean.getOperation("enableMessageCounters");
        List<EmsParameter> params = operation.getParameters();
        int count = params.size();
        if (count == 0)
            operation.invoke(new Object[0]);
        else { // overloaded operation
            operation.invoke(new Object[] { 0 }); // return code of 0
        }

        //reset counters
        operation = bean.getOperation("resetAllMessageCounters");
        params = operation.getParameters();
        count = params.size();
        if (count == 0)
            operation.invoke(new Object[0]);
        else { // overloaded operation
            operation.invoke(new Object[] { 0 }); // return code of 0
        }

        operation = bean.getOperation("resetAllMessageCounterHistories");
        params = operation.getParameters();
        count = params.size();
        if (count == 0)
            operation.invoke(new Object[0]);
        else { // overloaded operation
            operation.invoke(new Object[] { 0 }); // return code of 0
        }
        Thread.sleep(5000);
        ///////

        //remove messages from the destination
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

                + "], as we can't connect to the MBean - is it down?");
        }

        Map<String, PropertySimple> paramProps = parameters.getSimpleProperties();
        SortedSet<EmsOperation> emsOperations = emsBean.getOperations();
        EmsOperation operation = null;
        // There could be multiple operations with the same name but different parameters. Try to find one that has
        // the same # of parameters as the RHQ operation def.
        for (EmsOperation emsOperation : emsOperations) {
            if (emsOperation.getName().equals(name) && (emsOperation.getParameters().size() == paramProps.size())) {
                operation = emsOperation;
                break;
            }
        }
        if (operation == null) {
            // We couldn't find an operation with the expected name and # of parameters, so as as a last ditch effort,
            // see if there's an operation that at least has the expected name.
            operation = emsBean.getOperation(name);
        }
        if (operation == null) {
            throw new Exception("Operation [" + name + "] not found on MBean [" + emsBean.getBeanName() + "].");
        }

        List<EmsParameter> emsParams = operation.getParameters();
        Map<String, Integer> emsParamIndexesByName = new HashMap<String, Integer>();
        for (int i = 0, emsParamsSize = emsParams.size(); i < emsParamsSize; i++) {
            EmsParameter emsParam = emsParams.get(i);
            if (emsParam.getName() != null) {
                emsParamIndexesByName.put(emsParam.getName(), i);
            }
        }

        Object[] paramValues = new Object[operation.getParameters().size()];

        for (String propName : paramProps.keySet()) {
            Integer paramIndex;
            if (propName.matches("\\[\\d+\\]")) {
                paramIndex = Integer.valueOf(propName.substring(propName.indexOf('[') + 1, propName.indexOf(']')));
                if (paramIndex < 0 || paramIndex >= emsParams.size()) {
                    throw new IllegalStateException("Index [" + paramIndex + "] specified for parameter of operation ["
                        + name + "] on MBean [" + emsBean.getBeanName() + "] is invalid. The MBean operation takes "
                        + emsParams.size() + " parameters.");
                }
            } else {
                paramIndex = emsParamIndexesByName.get(propName);
                if (paramIndex == null) {
                    throw new IllegalStateException("Name [" + propName + "] specified for parameter of operation ["
                        + name + "] on MBean [" + emsBean.getBeanName()
                        + "] is invalid. The MBean operation does not take a parameter by that name.");
                }
            }
            EmsParameter emsParam = emsParams.get(paramIndex);

            PropertySimple paramProp = paramProps.get(propName);
            String emsParamType = emsParam.getType();
            Object paramValue = getPropertyValueAsType(paramProp, emsParamType);
            paramValues[paramIndex] = paramValue;
        }

        Object resultObject = operation.invoke(paramValues);

        boolean hasVoidReturnType = (operation.getReturnType() == null
            || Void.class.getName().equals(operation.getReturnType()) || void.class.getName().equals(
            operation.getReturnType()));

        OperationResult resultToReturn;
        if (resultObject == null && hasVoidReturnType) {
            resultToReturn = null;
        } else {
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

        EmsConnection connection = this.serverComponent.getEmsConnection();
        if (connection == null) {
            throw new RuntimeException("Can not connect to the server");
        }
        EmsBean bean = connection.getBean(mbeanName);
        EmsOperation operation = bean.getOperation(operationName);
        /*
         *  Now see if we got the 'real' method (the one with no param) or the overloaded one.
         *  This is a workaround for a bug in EMS that prevents finding operations with same name
         *  and different signature.
         *  http://sourceforge.net/tracker/index.php?func=detail&aid=2007692&group_id=60228&atid=493495
         *
         *   In addition, as we offer the user to specify any MBean and any method, we'd need a
         *   clever way for the user to specify parameters anyway.
         */
        List<EmsParameter> params = operation.getParameters();
        int count = params.size();
        if (count == 0)
            operation.invoke(new Object[0]);
        else { // overloaded operation
            operation.invoke(new Object[] { 0 }); // return code of 0
        }

        return "Server has been shut down.";
    }
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

    }
  }

  protected Object getEmsOperationResult(String beanName, String operationName) {
    EmsBean bean = connection.getBean(beanName);
    EmsOperation operation = bean.getOperation(operationName);

    Object obj = operation.invoke(new Object[] {});
    return obj;
  }
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

  }

  protected String getOperationResultType(String beanName,
      String operationName) {
    EmsBean bean = connection.getBean(beanName);
    EmsOperation operation = bean.getOperation(operationName);
    return operation.getReturnType();
  }
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

            // TODO check whether this should be getName,getCanonicalName,
            // getSimpleName
            // just needs to match what EMS returns
            parameterTypeNames[i] = parameterTypes[i].getName();
        }
        EmsOperation selectedOperation = null;
        for (EmsOperation operation : allOperations) {
            if (!operation.getName().equals(operationName)) {
                continue;
            }
View Full Code Here

Examples of org.mc4j.ems.connection.bean.operation.EmsOperation

      boolean trace = log.isTraceEnabled();
      int paramSep = fullName.indexOf('|');
      String fullOpName = paramSep < 0 ? fullName : fullName.substring(0, paramSep);
      EmsBean bean = queryComponentBean(getConnection(), fullOpName);
      String opName = fullOpName.substring(fullOpName.indexOf(".") + 1);
      EmsOperation ops = bean.getOperation(opName);
      Collection<PropertySimple> simples = parameters.getSimpleProperties().values();
      if (trace) log.trace("Parameters, as simple properties, are " + simples);
      Object[] realParams = new Object[simples.size()];
      int i = 0;
      for (PropertySimple property : simples) {
         // Since parameters are typed in UI, passing them as Strings is the only reasonable way of dealing with this
         realParams[i++] = property.getStringValue();
      }

      if (ops == null)
         throw new Exception("Operation " + fullOpName + " can't be found");

      Object result = ops.invoke(realParams);
      String sResult = result != null ? result.toString() : "";
      if (trace)
         log.trace("Returning operation result containing " + sResult);
      return new OperationResult(sResult);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.