Package com.adahas.tools.jmxeval.exception

Examples of com.adahas.tools.jmxeval.exception.EvalException


   * @param value Value of the variable
   * @throws EvalException When the variable is already defined or is having a reserved name as its variable name
   */
  public void setVar(final String name, final Object value) throws EvalException {
    if (variables.containsKey(name)) {
      throw new EvalException(Status.UNKNOWN, "Variable already set: " + name);
    } else {
      variables.put(name, value);
    }
  }
View Full Code Here


    if (variables.containsKey(key)) {
      return variables.get(key);
    } else if (defaultValue != null) {
      return defaultValue;
    } else {
      throw new EvalException(Status.UNKNOWN, "Variable not set: " + name);
    }
  }
View Full Code Here

  protected void setDefine(String name_value) throws EvalException
  {
    String[] s = name_value.split("=", 2);
    if (s.length != 2)
    {
      throw new EvalException(Status.UNKNOWN, "arg to --set ("+name_value+") must be in \"name=value\" format!");
    }
    setVar(s[0], s[1]);
  }
View Full Code Here

   */
  @Override
  public void process(final Context context) throws EvalException {
    try {
      if (context.getConnection() == null) {
        throw new EvalException(Status.UNKNOWN, "Can not connect to server");
      }
     
      final ObjectName mbeanName = new ObjectName(objectName);
      Object returnValue = null;
     
      final MBeanInfo mbeanInfo = context.getConnection().getMBeanInfo(mbeanName);
      final MBeanOperationInfo[] operationInfo = mbeanInfo.getOperations();
     
      String operationName = null;
      String[] argNames = null;
      Object[] argValues = null;
     
      // find the operation to execute
      for (final MBeanOperationInfo op : operationInfo) {
        final StringBuilder opSignature = new StringBuilder();
        opSignature.append(op.getName());
        opSignature.append("(");
        for (int i = 0; i < op.getSignature().length; i++) {
          if (i > 0) {
            opSignature.append(",");
          }
          opSignature.append(String.valueOf(op.getSignature()[i].getType()));
        }
        opSignature.append(")");
       
        if (operation.equals(opSignature.toString())) {
          operationName = op.getName();
          argNames = new String[op.getSignature().length];
          argValues = new Object[op.getSignature().length];
         
          for (int i = 0; i < op.getSignature().length; i++) {
            argNames[i] = op.getSignature()[i].getType();
           
            if (argNames[i].equals(String.class.getName())) {
              argValues[i] = arguments.get(i);
            } else if (argNames[i].equals("boolean")) {
              argValues[i] = Boolean.valueOf(arguments.get(i));
            } else if (argNames[i].equals("byte")) {
              argValues[i] = Byte.valueOf(arguments.get(i));
            } else if (argNames[i].equals("short")) {
              argValues[i] = Short.valueOf(arguments.get(i));
            } else if (argNames[i].equals("int")) {
              argValues[i] = Integer.valueOf(arguments.get(i));
            } else if (argNames[i].equals("long")) {
              argValues[i] = Long.valueOf(arguments.get(i));
            }
          }
         
          break;
        }
      }
     
      if (operationName != null) {
        returnValue = context.getConnection().invoke(mbeanName, operationName, argValues, argNames);
      } else {
        throw new EvalException(Status.UNKNOWN, "Could not locate the operation: [" + operation + "]");
      }
      // set query result as variable
      context.setVar(var, returnValue);
     
      // process child elements
      super.process(context);
     
    } catch (IOException e) {
      throw new EvalException(Status.UNKNOWN, "Executing operation failed [" + operation + "] on object [" +
          objectName + "]", e);
    } catch (JMException e) {
      throw new EvalException(Status.UNKNOWN, "Executing operation failed [" + operation + "] on object [" +
          objectName + "]", e);
    }
  }
View Full Code Here

   */
  @Override
  public void process(final Context context) throws EvalException {
    try {
      if (context.getConnection() == null) {
        throw new EvalException(Status.UNKNOWN, "Can not connect to server");
      }
     
      final ObjectName mbeanName = new ObjectName(objectName);
      Object attributeValue;
     
      // retrieve attribute value
      if (compositeAttribute == null) {
        final Object attributeVal = context.getConnection().getAttribute(mbeanName, attribute);
        if (attributeVal instanceof String[]) {
          attributeValue = Arrays.asList((String[]) attributeVal);
        } else {
          attributeValue = attributeVal;
        }
      } else {
        final CompositeDataSupport compositeAttributeValue =
            (CompositeDataSupport) context.getConnection().getAttribute(mbeanName, compositeAttribute);
        attributeValue = compositeAttributeValue.get(attribute);
      }
   
      // set query result as variable
      context.setVar(var, attributeValue);
     
      // process child elements
      super.process(context);
     
    } catch (IOException e) {
      throw new EvalException(Status.UNKNOWN, "Reading attribute failed [" + attribute + "] from object [" +
          objectName + "]" + (compositeAttribute == null ? "" : " composite result [" + compositeAttribute + "]"), e);
    } catch (JMException e) {
      throw new EvalException(Status.UNKNOWN, "Can not read attribute [" + attribute + "] from object [" +
          objectName + "]" + (compositeAttribute == null ? "" : " composite result [" + compositeAttribute + "]"), e);
    }
  }
View Full Code Here

TOP

Related Classes of com.adahas.tools.jmxeval.exception.EvalException

Copyright © 2018 www.massapicom. 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.