Repositorypublic class Repository extends Object The RepositorySupport implements the Repository interface.
This repository does not support persistency. |
Fields Summary |
---|
private final Map | domainTbThe structure for storing the objects is very basic.
A Hashtable is used for storing the different domains
For each domain, a hashtable contains the instances with
canonical key property list string as key and named object
aggregated from given object name and mbean instance as value. | private int | nbElementsNumber of elements contained in the Repository | private final String | domainDomain name of the server the repository is attached to.
It is quicker to store the information in the repository rather
than querying the framework each time the info is required. | private static final String | dbgTagThe name of this class to be used for tracing |
Constructors Summary |
---|
public Repository(String domain)Construct a new repository with the given default domain.
domainTb = new HashMap<String,Map<String,NamedObject>>(5);
if (domain != null && domain.length() != 0)
this.domain = domain;
else
this.domain = ServiceName.DOMAIN;
// Creates an new hastable for the default domain
domainTb.put(this.domain.intern(), new HashMap<String,NamedObject>());
|
Methods Summary |
---|
private void | addAllMatching(java.util.Map moiTb, java.util.Set result, com.sun.jmx.mbeanserver.Repository$ObjectNamePattern pattern)Add all the matching objects from the given hashtable in the
result set for the given ObjectNamePattern
Do not check whether the domains match (only check for matching
key property lists - see matchKeys())
synchronized (moiTb) {
for (NamedObject no : moiTb.values()) {
final ObjectName on = no.getName();
// if all couples (property, value) are contained
if (pattern.matchKeys(on)) result.add(no);
}
}
| public void | addMBean(javax.management.DynamicMBean object, javax.management.ObjectName name)Stores an MBean associated with its object name in the repository.
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()) {
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 Map<String,NamedObject> moiTb = domainTb.get(dom);
if (moiTb == null) {
addNewDomMoi(object, dom, name);
return;
} else {
// Add instance if not already present
String cstr = name.getCanonicalKeyPropertyListString();
NamedObject elmt= moiTb.get(cstr);
if (elmt != null) {
throw new InstanceAlreadyExistsException(name.toString());
} else {
nbElements++;
moiTb.put(cstr, new NamedObject(name, object));
}
}
| private void | addNewDomMoi(javax.management.DynamicMBean object, java.lang.String dom, javax.management.ObjectName name)
final Map<String,NamedObject> moiTb =
new HashMap<String,NamedObject>();
moiTb.put(name.getCanonicalKeyPropertyListString(),
new NamedObject(name, object));
domainTb.put(dom, moiTb);
nbElements++;
| public boolean | contains(javax.management.ObjectName name)Checks whether an MBean of the name specified is already stored in
the repository.
if (isTraceOn()) {
trace("contains", "name=" + name);
}
return (retrieveNamedObject(name) != null);
| private static final void | debug(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER, clz, func,
info);
| private static final void | debug(java.lang.String func, java.lang.String info)
debug(dbgTag, func, info);
| public java.lang.Integer | getCount()Gets the number of MBeans stored in the repository.
return new Integer(nbElements);
| public java.lang.String | getDefaultDomain()Gets the name of the domain currently used by default in the
repository.
return domain;
| public java.lang.String[] | getDomains()Returns the list of domains in which any MBean is currently
registered.
final List<String> result;
synchronized(domainTb) {
// Temporary list
result = new ArrayList<String>(domainTb.size());
for (Map.Entry<String,Map<String,NamedObject>> entry :
domainTb.entrySet()) {
// Skip domains that are in the table but have no
// MBean registered in them
// in particular the default domain may be like this
Map<String,NamedObject> t = entry.getValue();
if (t != null && t.size() != 0)
result.add(entry.getKey());
}
}
// Make an array from result.
return result.toArray(new String[result.size()]);
| private static final boolean | isDebugOn()
return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER);
| private static final boolean | isTraceOn()
// Private fields <=============================================
// Private methods --------------------------------------------->
// TRACES & DEBUG
//---------------
return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER);
| public java.util.Set | query(javax.management.ObjectName pattern, javax.management.QueryExp query)Selects and retrieves the list of MBeans whose names match the specified
object name pattern and which match the specified query expression
(optionally).
final Set<NamedObject> result = new HashSet<NamedObject>();
// The following filter cases are considered:
// null, "", "*:*" : names in all domains
// ":*", ":[key=value],*" : names in defaultDomain
// "domain:*", "domain:[key=value],*" : names in the specified domain
// Surely one of the most frequent case ... query on the whole world
ObjectName name = null;
if (pattern == null ||
pattern.getCanonicalName().length() == 0 ||
pattern.equals(ObjectName.WILDCARD))
name = ObjectName.WILDCARD;
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 == ObjectName.WILDCARD) {
synchronized(domainTb) {
for (Map<String,NamedObject> moiTb : domainTb.values()) {
result.addAll(moiTb.values());
}
}
return result;
}
String canonical_key_property_list_string =
name.getCanonicalKeyPropertyListString();
// All names in default domain
if (name.getDomain().length() == 0) {
final Map<String,NamedObject> moiTb = domainTb.get(domain);
if (canonical_key_property_list_string.length() == 0)
result.addAll(moiTb.values());
else
addAllMatching(moiTb, result, new ObjectNamePattern(name));
return result;
}
// Pattern matching in the domain name (*, ?)
synchronized (domainTb) {
char[] dom2Match = name.getDomain().toCharArray();
for (String domain : domainTb.keySet()) {
char[] theDom = domain.toCharArray();
if (wildmatch(theDom, dom2Match)) {
final Map<String,NamedObject> moiTb = domainTb.get(domain);
if (canonical_key_property_list_string.length() == 0)
result.addAll(moiTb.values());
else
addAllMatching(moiTb, result,
new ObjectNamePattern(name));
}
}
}
return result;
| public void | remove(javax.management.ObjectName name)Removes an MBean from the repository.
// 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
Map<String,NamedObject> moiTb = domainTb.get(dom);
if (moiTb == null) {
throw new InstanceNotFoundException(name.toString());
}
// Remove the corresponding element
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 HashMap<String,NamedObject>());
}
| public javax.management.DynamicMBean | retrieve(javax.management.ObjectName name)Retrieves the MBean of the name specified from the repository. The
object name must match exactly.
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();
| private com.sun.jmx.mbeanserver.NamedObject | retrieveNamedObject(javax.management.ObjectName name)Retrieves the named object contained in repository
from the given objectname.
// No patterns inside reposit
if (name.isPattern()) return null;
// Extract the domain name.
String dom= name.getDomain().intern();
// Default domain case
if (dom.length() == 0) {
dom = domain;
}
Map<String,NamedObject> moiTb = domainTb.get(dom);
if (moiTb == null) {
return null; // No domain containing registered object names
}
return moiTb.get(name.getCanonicalKeyPropertyListString());
| private static final void | trace(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER, clz, func,
info);
| private static final void | trace(java.lang.String func, java.lang.String info)
trace(dbgTag, func, info);
| public static boolean | wildmatch(char[] str, char[] pat)Match a string against a shell-style pattern. The only pattern
characters recognised are ? , standing for any one
character, and * , standing for any string of
characters, including the empty string.
int stri; // index in str
int pati; // index in pat
int starstri; // index for backtrack if "*" attempt fails
int starpati; // index for backtrack if "*" attempt fails, +1
final int strlen = str.length;
final int patlen = pat.length;
stri = pati = 0;
starstri = starpati = -1;
/* On each pass through this loop, we either advance pati,
or we backtrack pati and advance starstri. Since starstri
is only ever assigned from pati, the loop must terminate. */
while (true) {
if (pati < patlen) {
final char patc = pat[pati];
switch (patc) {
case '?":
if (stri == strlen)
break;
stri++;
pati++;
continue;
case '*":
pati++;
starpati = pati;
starstri = stri;
continue;
default:
if (stri < strlen && str[stri] == patc) {
stri++;
pati++;
continue;
}
break;
}
} else if (stri == strlen)
return true;
// Mismatched, can we backtrack to a "*"?
if (starpati < 0 || starstri == strlen)
return false;
// Retry the match one position later in str
pati = starpati;
starstri++;
stri = starstri;
}
|
|