public List getEntries(int startIndex, int endIndex) {
    // User code starts here
    if (agentName.initTopo()) {
      ArrayList arrayList = new ArrayList();
      int noOfObj = getCount();
      String[] name = {""}; // No I18N

      for (int i = 0; i < noOfObj; i++) {
        if (name[0].trim().equals("")) // No I18N
        {
          getFirstMo(name);
        } else {
          getNextMo(name);
        }

        if ((i + 1 >= startIndex) && (i + 1 <= endIndex)) {
          Object[] indx = new Object[] {name[0]};
          arrayList.add(indx);
          if (i + 1 == endIndex) break;
        }
      }
      return arrayList;
    }

    // User code ends here
    return null;
  }
  /* Check that all descriptors have been returned */
  private static void checkDescriptors(
      ModelMBeanInfo modelMBeanInfo, Descriptor[] descriptors, String string) {
    int errCount = 0;
    final ArrayList<Descriptor> list = new ArrayList<Descriptor>(descriptors.length);
    list.addAll(Arrays.asList(descriptors));
    System.out.println("Got " + list.size() + " descriptors for " + string);

    // checks that MBean's descriptor is returned.
    //
    final Descriptor mbd = ((MBeanInfo) modelMBeanInfo).getDescriptor();
    if (!mbd.equals(remove(list, mbd))) {
      System.err.println("modelMBeanInfo.getDescriptor(): not found");
      errCount++;
    }

    // checks that MBean's attributes descriptors are returned.
    //
    final MBeanAttributeInfo[] attrs = modelMBeanInfo.getAttributes();
    for (MBeanAttributeInfo att : attrs) {
      final Descriptor ad = att.getDescriptor();
      final String name = att.getName();
      if (!ad.equals(remove(list, ad))) {
        System.err.println("attInfo.getDescriptor(): not found for " + name);
        errCount++;
      }
    }

    // checks that MBean's operations descriptors are returned.
    //
    final MBeanOperationInfo[] ops = modelMBeanInfo.getOperations();
    for (MBeanOperationInfo op : ops) {
      final Descriptor od = op.getDescriptor();
      final String name = op.getName();
      if (!od.equals(remove(list, od))) {
        System.err.println("opInfo.getDescriptor(): not found for " + name);
        errCount++;
      }
    }

    // checks that MBean's notifications descriptors are returned.
    //
    final MBeanNotificationInfo[] ntfs = modelMBeanInfo.getNotifications();
    for (MBeanNotificationInfo ntf : ntfs) {
      final Descriptor nd = ntf.getDescriptor();
      final String name = ntf.getName();
      if (!nd.equals(remove(list, nd))) {
        System.err.println("notifInfo.getDescriptor(): not found for " + name);
        errCount++;
      }
    }
    if (errCount > 0) {
      throw new RuntimeException(string + ": failed with " + errCount + " errors");
    } else if (list.size() != 0) {
      // Check that there are no additional descriptors
      //
      throw new RuntimeException(string + ": Unexpected remaining descriptors: " + list);
    } else System.out.println(string + ": PASSED");
  }
  /**
   * Define an operation. Explicit definition of an operation. Reflection is used to locate method
   * called.
   *
   * @param opInfo
   */
  public synchronized void defineOperation(ModelMBeanOperationInfo opInfo) {
    _dirty = true;
    Class oClass = _object.getClass();

    try {
      MBeanParameterInfo[] pInfo = opInfo.getSignature();

      Class[] types = new Class[pInfo.length];
      String method = opInfo.getName() + "(";
      for (int i = 0; i < pInfo.length; i++) {
        Class type = TypeUtil.fromName(pInfo[i].getType());
        if (type == null)
          type = Thread.currentThread().getContextClassLoader().loadClass(pInfo[i].getType());
        types[i] = type;
        method += (i > 0 ? "," : "") + pInfo[i].getType();
      }
      method += ")";

      _method.put(method, oClass.getMethod(opInfo.getName(), types));
      _operations.add(opInfo);
    } catch (Exception e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new IllegalArgumentException(e.toString());
    }
  }
  /**
   * Define an attribute. Explicit definition of an attribute. Reflection is used to locate the
   * actual getter and setter methods.
   *
   * @param attrInfo ModelMBeanAttributeInfo.
   */
  public synchronized void defineAttribute(ModelMBeanAttributeInfo attrInfo) {
    if (_object == null) throw new IllegalStateException("No Object");

    _dirty = true;

    String name = attrInfo.getName();
    String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
    Class oClass = _object.getClass();

    try {
      Class type = TypeUtil.fromName(attrInfo.getType());
      if (type == null)
        type = Thread.currentThread().getContextClassLoader().loadClass(attrInfo.getType());

      Method getter = null;
      Method setter = null;

      if (attrInfo.isReadable())
        getter =
            oClass.getMethod((attrInfo.isIs() ? "is" : "get") + uName, (java.lang.Class[]) null);

      if (attrInfo.isWritable()) setter = oClass.getMethod("set" + uName, new Class[] {type});

      _getter.put(name, getter);
      _setter.put(name, setter);
      _attributes.add(attrInfo);
    } catch (Exception e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new IllegalArgumentException(e.toString());
    }
  }
  /**
   * Define an attribute on the managed object. The meta data is defined by looking for standard
   * getter and setter methods. Descriptions are obtained with a call to findDescription with the
   * attribute name.
   *
   * @param name The name of the attribute. Normal java bean capitlization is enforced on this name.
   * @param writable If false, do not look for a setter.
   * @param onMBean .
   */
  public synchronized void defineAttribute(String name, boolean writable, boolean onMBean) {
    _dirty = true;

    String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
    name = java.beans.Introspector.decapitalize(name);
    Class oClass = onMBean ? this.getClass() : _object.getClass();

    Class type = null;
    Method getter = null;
    Method setter = null;
    Method[] methods = oClass.getMethods();
    for (int m = 0; m < methods.length; m++) {
      if ((methods[m].getModifiers() & Modifier.PUBLIC) == 0) continue;

      // Look for a getter
      if (methods[m].getName().equals("get" + uName)
          && methods[m].getParameterTypes().length == 0) {
        if (getter != null) throw new IllegalArgumentException("Multiple getters for attr " + name);
        getter = methods[m];
        if (type != null && !type.equals(methods[m].getReturnType()))
          throw new IllegalArgumentException("Type conflict for attr " + name);
        type = methods[m].getReturnType();
      }

      // Look for an is getter
      if (methods[m].getName().equals("is" + uName) && methods[m].getParameterTypes().length == 0) {
        if (getter != null) throw new IllegalArgumentException("Multiple getters for attr " + name);
        getter = methods[m];
        if (type != null && !type.equals(methods[m].getReturnType()))
          throw new IllegalArgumentException("Type conflict for attr " + name);
        type = methods[m].getReturnType();
      }

      // look for a setter
      if (writable
          && methods[m].getName().equals("set" + uName)
          && methods[m].getParameterTypes().length == 1) {
        if (setter != null) throw new IllegalArgumentException("Multiple setters for attr " + name);
        setter = methods[m];
        if (type != null && !type.equals(methods[m].getParameterTypes()[0]))
          throw new IllegalArgumentException("Type conflict for attr " + name);
        type = methods[m].getParameterTypes()[0];
      }
    }

    if (getter == null && setter == null)
      throw new IllegalArgumentException("No getter or setters found for " + name);

    try {
      // Remember the methods
      _getter.put(name, getter);
      _setter.put(name, setter);
      // create and add the info
      _attributes.add(new ModelMBeanAttributeInfo(name, findDescription(name), getter, setter));
    } catch (Exception e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new IllegalArgumentException(e.toString());
    }
  }
 /** Post Deregister. This implementation destroys this MBean and it cannot be used again. */
 public void postDeregister() {
   _beanInfo = null;
   _mBeanServer = null;
   _object = null;
   _objectName = null;
   if (_getter != null) _getter.clear();
   _getter = null;
   if (_setter != null) _setter.clear();
   _setter = null;
   if (_method != null) _method.clear();
   _method = null;
   if (_attributes != null) _attributes.clear();
   _attributes = null;
   if (_operations != null) _operations.clear();
   _operations = null;
   if (_notifications != null) _notifications.clear();
   _notifications = null;
 }
  /**
   * Define an operation on the managed object. Defines an operation with parameters. Refection is
   * used to determine find the method and it's return type. The description of the method is found
   * with a call to findDescription on "name(signature)". The name and description of each parameter
   * is found with a call to findDescription with "name(partialSignature", the returned description
   * is for the last parameter of the partial signature and is assumed to start with the parameter
   * name, followed by a colon.
   *
   * @param name The name of the method call.
   * @param signature The types of the operation parameters.
   * @param impact Impact as defined in MBeanOperationInfo
   * @param onMBean true if the operation is defined on the mbean
   */
  public synchronized void defineOperation(
      String name, String[] signature, int impact, boolean onMBean) {
    _dirty = true;
    Class oClass = onMBean ? this.getClass() : _object.getClass();
    if (signature == null) signature = new String[0];

    try {
      Class[] types = new Class[signature.length];
      MBeanParameterInfo[] pInfo = new MBeanParameterInfo[signature.length];

      // Check types and build methodKey
      String methodKey = name + "(";
      for (int i = 0; i < signature.length; i++) {
        Class type = TypeUtil.fromName(signature[i]);
        if (type == null)
          type = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
        types[i] = type;
        signature[i] = type.isPrimitive() ? TypeUtil.toName(type) : signature[i];
        methodKey += (i > 0 ? "," : "") + signature[i];
      }
      methodKey += ")";

      // Build param infos
      for (int i = 0; i < signature.length; i++) {
        String description = findDescription(methodKey + "[" + i + "]");
        int colon = description.indexOf(":");
        if (colon < 0) {
          description = "param" + i + ":" + description;
          colon = description.indexOf(":");
        }
        pInfo[i] =
            new MBeanParameterInfo(
                description.substring(0, colon).trim(),
                signature[i],
                description.substring(colon + 1).trim());
      }

      // build the operation info
      Method method = oClass.getMethod(name, types);
      Class returnClass = method.getReturnType();
      _method.put(methodKey, method);
      _operations.add(
          new ModelMBeanOperationInfo(
              name,
              findDescription(methodKey),
              pInfo,
              returnClass.isPrimitive() ? TypeUtil.toName(returnClass) : (returnClass.getName()),
              impact));
    } catch (Exception e) {
      log.warn("operation " + name, e);
      throw new IllegalArgumentException(e.toString());
    }
  }
  /* ------------------------------------------------------------ */
  public synchronized MBeanInfo getMBeanInfo() {
    log.debug("getMBeanInfo");

    if (_dirty) {
      _dirty = false;
      ModelMBeanAttributeInfo[] attributes =
          (ModelMBeanAttributeInfo[])
              _attributes.toArray(new ModelMBeanAttributeInfo[_attributes.size()]);
      ModelMBeanOperationInfo[] operations =
          (ModelMBeanOperationInfo[])
              _operations.toArray(new ModelMBeanOperationInfo[_operations.size()]);
      ModelMBeanNotificationInfo[] notifications =
          (ModelMBeanNotificationInfo[])
              _notifications.toArray(new ModelMBeanNotificationInfo[_notifications.size()]);

      _beanInfo =
          new ModelMBeanInfoSupport(
              _object.getClass().getName(),
              findDescription(null),
              attributes,
              null,
              operations,
              notifications);
    }

    return _beanInfo;
  }
Beispiel #9
0
  public List getEntries(int startIndex, int endIndex) {

    // User code starts here
    /*
    return null;
    */
    if (!agentName.initAlert()) return null;

    ArrayList arrayList = new ArrayList();

    boolean firstAlert = true;

    String[] keys = null;

    int totalAlerts = totalRows();

    for (int i = 0; i < totalAlerts; i++) {
      if (firstAlert) {
        firstAlert = false;

        keys = getFirstAlert();
      } else keys = getNextAlert(keys);

      // Checking the range
      if ((i + 1 >= startIndex) && (i + 1 <= endIndex)) {
        Object[] index = new Object[] {keys[0], keys[1]};

        arrayList.add(index);
      }

      // checking if the upper limit is exceeded, if so break
      if (i + 1 == endIndex) break;
    }

    return arrayList;
    // User code ends here
    //	return null;
  }
 /* Removes descriptor from the list and returns it. Returns {@code null}
 if descriptor is not found */
 private static Descriptor remove(ArrayList<Descriptor> list, Descriptor item) {
   if (list.remove(item)) return item;
   else return null;
 }