abstractmbeanserver.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,037 行 · 第 1/2 页

JAVA
1,037
字号
      log.log(Level.WARNING, e.toString(), e);      return null;    }  }  /**   * Returns a set of names for MBeans matching the query.   *   * @param name the name of the mbean to match.   * @param query the query to match.   *   * @return the set of matching mbean names.   */  public Set<ObjectName> queryNames(ObjectName name, QueryExp query)  {    try {      if (query != null) {        query.setMBeanServer(this);      }      return getView().queryNames(name, query);    } catch (Exception e) {      log.log(Level.WARNING, e.toString(), e);      return null;    }  }  /**   * Returns true if the given object is registered with the server.   *   * @param name the name of the mbean to test.   *   * @return true if the object is registered.   */  public boolean isRegistered(ObjectName name)  {    return getView().getMBean(name) != null;  }  /**   * Returns the number of MBeans registered.   *   * @return the number of registered mbeans.   */  public Integer getMBeanCount()  {    return new Integer(getView().getMBeanCount());  }  /**   * Returns a specific attribute of a named MBean.   *   * @param name the name of the mbean to test   * @param attribute the name of the attribute to retrieve   *   * @return the attribute value   */  public Object getAttribute(ObjectName name, String attribute)    throws MBeanException, AttributeNotFoundException,           InstanceNotFoundException, ReflectionException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null) {      throw new InstanceNotFoundException(String.valueOf(name));    }    return mbean.getAttribute(attribute);  }  /**   * Returns a list of several MBean attributes.   *   * @param name the name of the mbean   * @param attributes the name of the attributes to retrieve   *   * @return the attribute value   */  public AttributeList getAttributes(ObjectName name, String []attributes)    throws InstanceNotFoundException, ReflectionException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    return mbean.getAttributes(attributes);  }  /**   * Sets an attribute in the MBean.   *   * @param name the name of the mbean   * @param attribute the name/value of the attribute to set.   */  public void setAttribute(ObjectName name, Attribute attribute)    throws InstanceNotFoundException, AttributeNotFoundException,           InvalidAttributeValueException, MBeanException, ReflectionException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    mbean.setAttribute(attribute);  }  /**   * Set an attributes in the MBean.   *   * @param name the name of the mbean   * @param attributes the name/value list of the attribute to set.   */  public AttributeList setAttributes(ObjectName name, AttributeList attributes)    throws InstanceNotFoundException, ReflectionException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    return mbean.setAttributes(attributes);  }  /**   * Invokers an operation on an MBean.   *   * @param name the name of the mbean   * @param operationName the name of the method to invoke   * @param params the parameters for the invocation   * @param signature the signature of the operation   */  public Object invoke(ObjectName name,                       String operationName,                       Object []params,                       String []signature)    throws InstanceNotFoundException, MBeanException, ReflectionException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    return mbean.invoke(operationName, params, signature);  }  /**   * Returns the default domain for naming the MBean   */  public String getDefaultDomain()  {    return _defaultDomain;  }  /**   * Adds a listener to a registered MBean   *   * @param name the name of the mbean   * @param listener the listener object   * @param filter filters events the listener is interested in   * @param handback context to be returned to the listener   */  public void addNotificationListener(ObjectName name,                                      NotificationListener listener,                                      NotificationFilter filter,                                      Object handback)    throws InstanceNotFoundException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    mbean.addNotificationListener(listener, filter, handback);    createContext().addNotificationListener(name, listener, filter, handback);  }  /**   * Adds a listener to a registered MBean   *   * @param name the name of the mbean   * @param listenerName the name of the listener   * @param filter filters events the listener is interested in   * @param handback context to be returned to the listener   */  public void addNotificationListener(ObjectName name,                                      ObjectName listenerName,                                      NotificationFilter filter,                                      Object handback)    throws InstanceNotFoundException  {    MBeanWrapper listenerMBean = getMBean(listenerName);    if (listenerMBean == null)      throw new InstanceNotFoundException(String.valueOf(listenerName));    NotificationListener listener = listenerMBean.getListener();    if (listener == null) {      IllegalArgumentException exn = new IllegalArgumentException(L.l("{0} does not implement NotificationListener.", listenerName));      throw new RuntimeOperationsException(exn);    }    addNotificationListener(name, listener, filter, handback);  }  /**   * Removes a listener from a registered MBean   *   * @param name the name of the mbean   * @param listener the listener object   */  public void removeNotificationListener(ObjectName name,                                         NotificationListener listener)    throws InstanceNotFoundException, ListenerNotFoundException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    mbean.removeNotificationListener(listener);    createContext().removeNotificationListener(name, listener);  }  /**   * Removes a listener from a registered MBean   *   * @param name the name of the mbean   * @param listenerName the name of the listener   */  public void removeNotificationListener(ObjectName name,                                         ObjectName listenerName)    throws InstanceNotFoundException, ListenerNotFoundException  {    MBeanWrapper listenerMBean = getMBean(listenerName);    if (listenerMBean == null)      throw new InstanceNotFoundException(String.valueOf(listenerName));    NotificationListener listener = listenerMBean.getListener();    if (listener == null) {      IllegalArgumentException exn = new IllegalArgumentException(L.l("{0} does not implement NotificationListener."));      throw new RuntimeOperationsException(exn);    }    removeNotificationListener(name, listener);  }  /**   * Removes a listener from a registered MBean   *   * @param name the name of the mbean   * @param listenerName the name of the listener   * @param filter the notification filter   * @param handback context to the listener   *   * @since JMX 1.2   */  public void removeNotificationListener(ObjectName name,                                         ObjectName listenerName,                                         NotificationFilter filter,                                         Object handback)    throws InstanceNotFoundException, ListenerNotFoundException  {    MBeanWrapper listenerMBean = getMBean(listenerName);    if (listenerMBean == null)      throw new InstanceNotFoundException(String.valueOf(listenerName));    NotificationListener listener = listenerMBean.getListener();    if (listener == null) {      IllegalArgumentException exn = new IllegalArgumentException(L.l("{0} does not implement NotificationListener."));      throw new RuntimeOperationsException(exn);    }    removeNotificationListener(name, listener, filter, handback);  }  /**   * Removes a listener from a registered MBean   *   * @param name the name of the mbean   * @param listenerName the name of the listener   * @param filter the notification filter   * @param handback context to the listener   *   * @since JMX 1.2   */  public void removeNotificationListener(ObjectName name,                                         NotificationListener listener,                                         NotificationFilter filter,                                         Object handback)    throws InstanceNotFoundException, ListenerNotFoundException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    createContext().removeNotificationListener(name, listener, filter, handback);    mbean.removeNotificationListener(listener, filter, handback);  }  /**   * Returns the analyzed information for an MBean   *   * @param name the name of the mbean   *   * @return the introspected information   */  public MBeanInfo getMBeanInfo(ObjectName name)    throws InstanceNotFoundException, IntrospectionException,           ReflectionException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    MBeanInfo info = mbean.getMBeanInfo();    return info;  }  /**   * Returns true if the MBean is an instance of the specified class.   *   * @param name the name of the mbean   * @param className the className to test.   *   * @return true if the bean is an instance   */  public boolean isInstanceOf(ObjectName name, String className)    throws InstanceNotFoundException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    Object obj = mbean.getObject();    Class cl = obj.getClass();    return isInstanceOf(cl, className);  }  private boolean isInstanceOf(Class cl, String className)  {    if (cl == null)      return false;    if (cl.getName().equals(className))      return true;    if (isInstanceOf(cl.getSuperclass(), className))      return true;    Class []ifs = cl.getInterfaces();    for (int i = 0; i < ifs.length; i++) {      if (isInstanceOf(ifs[i], className))        return true;    }    return false;  }  /**   * Returns the ClassLoader that was used for loading the MBean.   *   * @param mbeanName the name of the mbean   *   * @return the class loader   *   * @since JMX 1.2   */  public ClassLoader getClassLoaderFor(ObjectName name)    throws InstanceNotFoundException  {    MBeanWrapper mbean = getMBean(name);    if (mbean == null)      throw new InstanceNotFoundException(String.valueOf(name));    return mbean.getContext().getClassLoader();  }  /**   * Returns the named ClassLoader.   *   * @param loaderName the name of the class loader   *   * @return the class loader   *   * @since JMX 1.2   */  public ClassLoader getClassLoader(ObjectName loaderName)    throws InstanceNotFoundException  {    return null;  }  /**   * Returns the ClassLoaderRepository for this MBeanServer   *   * @since JMX 1.2   */  public ClassLoaderRepository getClassLoaderRepository()  {    return createContext().getClassLoaderRepository();  }  /**   * Deserializes a byte array in the class loader of the mbean.   *   * @param name the name of the mbean   * @param data the data to deserialize   *   * @return the deserialization stream   */  public ObjectInputStream deserialize(ObjectName name, byte []data)    throws InstanceNotFoundException, OperationsException  {    throw new UnsupportedOperationException();  }  /**   * Deserializes a byte array in the class loader of the mbean.   *   * @param className the className matches to the loader   * @param data the data to deserialize   *   * @return the deserialization stream   */  public ObjectInputStream deserialize(String className, byte []data)    throws OperationsException, ReflectionException  {    throw new UnsupportedOperationException();  }  /**   * Deserializes a byte array in the class loader of the mbean.   *   * @param className the className matches to the loader   * @param loaderName the loader to use for deserialization   * @param data the data to deserialize   *   * @return the deserialization stream   */  public ObjectInputStream deserialize(String className,                                       ObjectName loaderName,                                       byte []data)    throws OperationsException, ReflectionException,           InstanceNotFoundException  {    throw new UnsupportedOperationException();  }  /**   * Returns the domains for all registered MBeans   *   * @since JMX 1.2   */  public String []getDomains()  {    return getView().getDomains();  }  /**   * Finds the MBean implementation.   */  MBeanWrapper getMBean(ObjectName name)  {    return getView().getMBean(name);  }  /**   * Handles the case where a class loader is dropped.   */  public void destroy()  {    try {      MBeanServerFactory.releaseMBeanServer(this);    } catch (IllegalArgumentException e) {      log.log(Level.FINEST, e.toString(), e);    } catch (Throwable e) {      log.log(Level.FINER, e.toString(), e);    }  }  /**   * Returns the string form.   */  @Override  public String toString()  {    if (_defaultDomain != null)      return "MBeanServerImpl[domain=" + _defaultDomain + "]";    else      return "MBeanServerImpl[]";  }  static {    try {      SERVER_DELEGATE_NAME = new ObjectName("JMImplementation:type=MBeanServerDelegate");    } catch (Throwable e) {      e.printStackTrace();    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?