⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repositorysupport.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public String[] getDomains() {	final ArrayList result;	synchronized(domainTb) {	    // Temporary list	    result = new ArrayList(domainTb.size());	    // Loop over all domains	    for (Enumeration e = domainTb.keys();e.hasMoreElements();) {		// key = domain name		final String key = (String)e.nextElement();		if (key == null) continue;		// If no MBean in domain continue		final Hashtable t = (Hashtable)domainTb.get(key);		if (t == null || t.size()==0) continue;		// Some MBean are registered => add to result.		result.add(key);	    }	}	// Make an array from result.	return (String[]) result.toArray(new String[result.size()]); 	    }      /**     * Indicates whether or not the Repository Service supports filtering. If     * the Repository Service does not support filtering, the MBean Server     * will perform filtering.     *     * @return  true if filtering is supported, false otherwise.     */    public boolean isFiltering() {	// Let the MBeanServer perform the filtering !     	return false;    }        /**     * Stores an MBean associated with its object name in the repository.     *     *@param object MBean to be stored in the repository.     *@param name MBean object name.     *     */    public void addMBean(final Object object, ObjectName name) 	throws InstanceAlreadyExistsException {		if (isTraceOn()) {	    trace("addMBean", "name=" + name);	}  	// Extract the domain name. 	String dom = name.getDomain().intern();     	boolean to_default_domain = false;        // Set domain to default if domain is empty and not already set	if (dom.length() == 0) {	     try {                name = new ObjectName(domain + name.toString());            } catch (MalformedObjectNameException e) {                if (isDebugOn()) {                    debug("addMBean",			  "Unexpected MalformedObjectNameException");                }            }	}		// Do we have default domain ?	if (dom == domain) {	    to_default_domain = true;	    dom = domain;	} else {	    to_default_domain = false;	}	// ------------------------------ 	// ------------------------------	// Validate name for an object     	if (name.isPattern() == true) {	    throw new RuntimeOperationsException(	     new IllegalArgumentException("Repository: cannot add mbean for pattern name " + name.toString()));	}        // Domain cannot be JMImplementation if entry does not exists        if ( !to_default_domain &&             dom.equals("JMImplementation") &&             domainTb.containsKey("JMImplementation")) {		throw new RuntimeOperationsException(		  new IllegalArgumentException(                      "Repository: domain name cannot be JMImplementation"));	    }	         	// If domain not already exists, add it to the hash table	final Hashtable moiTb= (Hashtable) domainTb.get(dom);	if (moiTb == null) {	    addNewDomMoi(object, dom, name);	    return;	}        else {            // Add instance if not already present            String cstr = name.getCanonicalKeyPropertyListString();            Object elmt= moiTb.get(cstr);            if (elmt != null) {                throw new InstanceAlreadyExistsException(name.toString());            } else {                nbElements++;                moiTb.put(cstr, new NamedObject(name, object));            }        }    }         /**     * Checks whether an MBean of the name specified is already stored in     * the repository.     *     * @param name name of the MBean to find.     *     * @return  true if the MBean is stored in the repository,      *          false otherwise.     *     */    public boolean contains(ObjectName name) {		if (isTraceOn()) {	    trace("contains", "name=" + name);	}  	return (retrieveNamedObject(name) != null);    }        /**     * Retrieves the MBean of the name specified from the repository. The     * object name must match exactly.     *     * @param name name of the MBean to retrieve.     *     * @return  The retrieved MBean if it is contained in the repository,      *          null otherwise.     *     */    public Object retrieve(ObjectName name) {		// ------------------------------ 	// ------------------------------	if (isTraceOn()) {	    trace("retrieve", "name=" + name);	}        // Calls internal retrieve method to get the named object        NamedObject no = retrieveNamedObject(name);        if (no == null) return null;        else return no.getObject();    }         /**     * Selects and retrieves the list of MBeans whose names match the specified     * object name pattern and which match the specified query expression      * (optionally).     *     * @param pattern The name of the MBean(s) to retrieve - may be a specific      * object or a name pattern allowing multiple MBeans to be selected.     * @param query query expression to apply when selecting objects - this      * parameter will be ignored when the Repository Service does not      * support filtering.     *     * @return  The list of MBeans selected. There may be zero, one or many      *          MBeans returned in the set.     *     */    public Set query(ObjectName pattern, QueryExp query) {		// ------------------------------ 	// ------------------------------        ObjectNamePattern on_pattern = null; // intermediate Object name pattern for performance	final HashSet result = new HashSet();		// The following filter cases are considered :	// null, "", "*:*"" :  names in all domains	// ":*" : names in defaultDomain	// "domain:*" : names in the specified domain	// "domain:[key=value], *"	        // Surely one of the most frequent case ... query on the whole world        ObjectName name = null;        if (pattern == null ||            pattern.getCanonicalName().length() == 0 ||            pattern.equals(_WholeWordQueryObjectName))           name = _WholeWordQueryObjectName;        else name = pattern;		// If pattern is not a pattern, retrieve this mbean !	if (!name.isPattern()) {       		final NamedObject no = retrieveNamedObject(name);		if (no != null) result.add(no);	    return result;	}		// all  names in all domains	if  (name == _WholeWordQueryObjectName) {   	    synchronized(domainTb) {		for(final Enumeration e = domainTb.elements(); 		    e.hasMoreElements();) {			    final Hashtable moiTb = (Hashtable) e.nextElement();                    result.addAll(moiTb.values());		}	    }	    return result;	}        String canonical_key_property_list_string = name.getCanonicalKeyPropertyListString();	// all names in default domain	//	// DF: fix 4618986 - take into account the case where the 	//     property list is not empty.	//	if (name.getDomain().length() == 0) {	    final Hashtable moiTb = (Hashtable) domainTb.get(domain);	    if  (canonical_key_property_list_string.length() == 0) {                result.addAll(moiTb.values());	    } else {                if (on_pattern == null) 		    on_pattern = new ObjectNamePattern(name);		addAllMatching(moiTb,result,on_pattern);	    }	    return result;	}		// Pattern matching in the domain name (*, ?)        synchronized (domainTb) {            char[] dom2Match = name.getDomain().toCharArray();            String nextDomain;            char [] theDom;            for (final Enumeration enumi = domainTb.keys(); enumi.hasMoreElements();) {                nextDomain = (String) enumi.nextElement();                theDom = nextDomain.toCharArray();                if (wildmatch(theDom, dom2Match, 0, 0)) {                    final Hashtable moiTb = 			(Hashtable) domainTb.get(nextDomain);                    if (canonical_key_property_list_string.length() == 0)                        result.addAll(moiTb.values());                    else {                        if (on_pattern == null) 			    on_pattern = new ObjectNamePattern(name);                        addAllMatching(moiTb,result,on_pattern);                    }                }            }        }	return result;    }        /**     * Removes an MBean from the repository.     *     * @param name name of the MBean to remove.     *     * @exception InstanceNotFoundException The MBean does not exist in      *            the repository.     */    public void remove(final ObjectName name) 	throws InstanceNotFoundException {        // Debugging stuff	if (isTraceOn()) {	    trace("remove", "name=" + name);	}  	// Extract domain name.       	String dom= name.getDomain().intern();        // Default domain case	if (dom.length() == 0) dom = domain;        // Find the domain subtable        Object tmp_object =  domainTb.get(dom);	if (tmp_object == null) {	    throw new InstanceNotFoundException(name.toString());	}        // Remove the corresponding element	Hashtable moiTb= (Hashtable) tmp_object;	if (moiTb.remove(name.getCanonicalKeyPropertyListString()) == null) {	    throw new InstanceNotFoundException(name.toString());	}        // We removed it !	nbElements--;                // No more object for this domain, we remove this domain hashtable        if (moiTb.isEmpty()) {            domainTb.remove(dom);            // set a new default domain table (always present)            // need to reinstantiate a hashtable because of possible            // big buckets array size inside table, never cleared, 	    // thus the new !            if (dom == domain) 		domainTb.put(domain, new Hashtable());        }    }         /**     * Gets the number of MBeans stored in the repository.     *     * @return  Number of MBeans.     */        public Integer getCount() {	return new Integer(nbElements);    }        /**     * Gets the name of the domain currently used by default in the      * repository.     *     * @return  A string giving the name of the default domain name.     */    public  String getDefaultDomain() {	return domain;    }}

⌨️ 快捷键说明

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