/* ------------------------------------------------------------ */
  public synchronized ObjectName uniqueObjectName(
      MBeanServer server, Object object, String objectName) {
    if (!objectName.endsWith("=")) {
      String className = object.getClass().getName();
      if (className.indexOf(".") > 0)
        className = className.substring(className.lastIndexOf(".") + 1);
      if (className.endsWith("MBean")) className = className.substring(0, className.length() - 5);
      if (!objectName.endsWith(":")) objectName += ",";
      objectName += className + "=";
    }

    ObjectName oName = null;
    try {
      while (true) {
        Integer id = (Integer) __objectId.get(objectName);
        if (id == null) id = new Integer(0);
        oName = new ObjectName(objectName + id);
        id = new Integer(id.intValue() + 1);
        __objectId.put(objectName, id);

        // If no server, this must be unique
        if (server == null) break;

        // Otherwise let's check it is unique
        // if not found then it is unique
        if (!server.isRegistered(oName)) break;
      }
    } catch (Exception e) {
      log.warn(LogSupport.EXCEPTION, e);
    }

    return oName;
  }
  /* ------------------------------------------------------------ */
  public Object invoke(String name, Object[] params, String[] signature)
      throws MBeanException, ReflectionException {
    if (log.isDebugEnabled()) log.debug("invoke " + name);

    String methodKey = name + "(";
    if (signature != null)
      for (int i = 0; i < signature.length; i++) methodKey += (i > 0 ? "," : "") + signature[i];
    methodKey += ")";

    try {
      Method method = (Method) _method.get(methodKey);
      if (method == null) throw new NoSuchMethodException(methodKey);

      Object o = _object;
      if (method.getDeclaringClass().isInstance(this)) o = this;
      return method.invoke(o, params);
    } catch (NoSuchMethodException e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new ReflectionException(e);
    } catch (IllegalAccessException e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new MBeanException(e);
    } catch (InvocationTargetException e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new ReflectionException((Exception) e.getTargetException());
    }
  }
 /* ------------------------------------------------------------ */
 public Object getAttribute(String name)
     throws AttributeNotFoundException, MBeanException, ReflectionException {
   if (log.isDebugEnabled()) log.debug("getAttribute " + name);
   Method getter = (Method) _getter.get(name);
   if (getter == null) throw new AttributeNotFoundException(name);
   try {
     Object o = _object;
     if (getter.getDeclaringClass().isInstance(this)) o = this;
     return getter.invoke(o, (java.lang.Object[]) null);
   } catch (IllegalAccessException e) {
     log.warn(LogSupport.EXCEPTION, e);
     throw new AttributeNotFoundException(e.toString());
   } catch (InvocationTargetException e) {
     log.warn(LogSupport.EXCEPTION, e);
     throw new ReflectionException((Exception) e.getTargetException());
   }
 }
 public void handleNotification(Notification notif, Object handback) {
   String type = notif.getType();
   if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
     GarbageCollectionNotificationInfo gcNotif =
         GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
     String source = ((ObjectName) notif.getSource()).getCanonicalName();
     synchronized (synchronizer) {
       if (listenerInvoked.get(source) == null) {
         listenerInvoked.put(((ObjectName) notif.getSource()).getCanonicalName(), gcNotif);
         count++;
         if (count >= number) {
           synchronizer.notify();
         }
       }
     }
   }
 }
  /* ------------------------------------------------------------ */
  public void setAttribute(Attribute attr)
      throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException,
          ReflectionException {
    if (attr == null) return;

    if (log.isDebugEnabled()) log.debug("setAttribute " + attr.getName() + "=" + attr.getValue());
    Method setter = (Method) _setter.get(attr.getName());
    if (setter == null) throw new AttributeNotFoundException(attr.getName());
    try {
      Object o = _object;
      if (setter.getDeclaringClass().isInstance(this)) o = this;
      setter.invoke(o, new Object[] {attr.getValue()});
    } catch (IllegalAccessException e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new AttributeNotFoundException(e.toString());
    } catch (InvocationTargetException e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new ReflectionException((Exception) e.getTargetException());
    }
  }