Methods Summary |
---|
private void | addAttributeToList(javax.management.AttributeList attrList, javax.management.ObjectName objName, java.lang.String attrPattern)
// only single "*"/"property.*" masks available now and they are implemented
// in ConfigMBeanBase.getAttributes() with "empty" values
AttributeList list = null;
if(attrPattern.equals(""+Tokens.kWildCardChar))
{
list = mServer.getAttributes(objName, new String[]{""});
if(list!=null)
attrList.addAll(list);
}
else
if(attrPattern.equals(ConfigAttributeName.PROPERTY_NAME_PREFIX+Tokens.kWildCardChar))
{
list = mServer.getAttributes(objName, new String[]{ConfigAttributeName.PROPERTY_NAME_PREFIX});
if(list!=null)
attrList.addAll(list);
}
else
{
Object attValue = mServer.getAttribute(objName, attrPattern);
attrList.add(new Attribute(attrPattern, attValue));
}
/* //the following code maybe will be used for non-config mbeans
ArrayList attrNames = getAttrNames(objName, attrPattern);
if(attrNames.size()==0)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.no_attributes_matched_to_pattern", attrPattern );
throw new AttributeNotFoundException( msg );
}
for(int i=0; i<attrNames.size(); i++)
{
String name = (String)attrNames.get(i);
Object attValue;
if(attrNames.size()==1)
attValue = mServer.getAttribute(objName, name);
else
{
try
{
attValue = mServer.getAttribute(objName, name);
}
catch (Exception e)
{
attValue = null;
}
}
attrList.add(new Attribute(name, attValue));
}
return attrNames.size(); //number of added elements
*/
|
private java.lang.Object | convertValueToAttributeType(javax.management.ObjectName objName, java.lang.String attrName, java.lang.Object value)
try
{
if(value instanceof String) //only for string now
{
String type = getAttrType(objName, attrName);
return MBeanEasyConfig.convertStringValueToProperType((String)value, type);
}
}
catch (Throwable t)
{
}
return value; //no conversion if error
|
java.lang.String | extractAttrNameFromDotted(java.lang.String dottedStringName)
int idx = dottedStringName.lastIndexOf(Tokens.kDelimiterChar);
if(idx<=0 || idx==(dottedStringName.length()-1))
{
String msg = localStrings.getString( "admin.server.core.mbean.config.cannot_extract_attribute_name_from_dotted_notation", dottedStringName );
throw new MalformedNameException( msg );
}
//property?
if(dottedStringName.substring(0, idx+1).endsWith(ConfigAttributeName.PROPERTY_NAME_PREFIX))
{
int idx2 = idx-ConfigAttributeName.PROPERTY_NAME_PREFIX.length();
if(dottedStringName.charAt(idx2)==Tokens.kDelimiterChar)
{
idx = idx2;
if(idx<1) {
String msg = localStrings.getString( "admin.server.core.mbean.config.cannot_extract_attribute_name_from_dotted_notation", dottedStringName );
throw new MalformedNameException( msg );
}
}
}
return dottedStringName.substring(idx+1);
|
java.lang.String | extractInstanceNameFromDotted(java.lang.String dottedName)
Name name = new Name(dottedName);
return name.getNamePart(0).toString();
|
private java.util.ArrayList | getAttrNames(javax.management.ObjectName objName, java.lang.String attrPattern)
ArrayList list = new ArrayList();
if(attrPattern==null)
return list;
if(attrPattern.indexOf(Tokens.kWildCardChar)>=0 || attrPattern.indexOf(ObjectNames.kSingleMatchChar)>=0)
{
MBeanInfo mi = mServer.getMBeanInfo(objName);
if(mi!=null)
{
MBeanAttributeInfo[] ai = mi.getAttributes();
if(ai!=null)
for(int i=0; i<ai.length; i++)
{
String name = ai[i].getName();
try
{
if((new CombinedPatternMatcher(attrPattern, name)).matches())
list.add(ai[i].getName());
} catch (Throwable e)
{
}
}
}
}
else
list.add(attrPattern); //for now
return list;
|
private java.lang.String | getAttrType(javax.management.ObjectName objName, java.lang.String attrName)
return getAttrType(attrName, mServer.getMBeanInfo(objName));
|
private java.lang.String | getAttrType(java.lang.String attrName, javax.management.MBeanInfo mi)
if(attrName==null && mi==null)
return null;
MBeanAttributeInfo[] ai = mi.getAttributes();
if(ai!=null)
for(int i=0; i<ai.length; i++)
{
String name = ai[i].getName();
if(attrName.equals(ai[i].getName()))
return ai[i].getType();
}
return null;
|
public javax.management.AttributeList | getGenericAttribute(java.lang.String dottedName)Obtains the Dynamic MBean Attribute object(s) for given attribute pattern (in dotted notation).
sLogger.log(Level.FINEST, MSG_GET_ATTRIBUTE, dottedName);
if(mServer==null)
mServer=MBeanServerFactory.getMBeanServer();
dottedName = dottedName.trim();
String attrName = extractAttrNameFromDotted(dottedName);
int prefixLen = dottedName.length() - attrName.length();
String namePrefix = null;
if(prefixLen>0)
namePrefix = dottedName.substring(0, prefixLen);
ArrayList objectNames = getMBeanNamesFromDottedPattern(dottedName);
AttributeList attrList = new AttributeList();
for(int i=0; i<objectNames.size(); i++)
{
addAttributeToList(attrList, (ObjectName)objectNames.get(i), attrName);
}
if(namePrefix!=null && attrList!=null)
{
for(int i=0; i<attrList.size(); i++)
{
Attribute attr = (Attribute)attrList.get(i);
attrList.set(i, new Attribute(namePrefix+attr.getName(),attr.getValue()));
}
}
return attrList;
|
public javax.management.AttributeList | getGenericAttributeDefaultValues(java.lang.String instanceName, java.lang.String mbeanType, java.lang.String[] attrNames)Obtains the Default MBean Attributes values
sLogger.log(Level.FINEST, MSG_GET_ATTRIBUTE_DEFAULT, new String[]{instanceName, mbeanType});
ConfigMBeanNamingInfo info = new ConfigMBeanNamingInfo(mbeanType, new String[] {instanceName}, false);
ConfigMBeanBase mbean = info.constructConfigMBean();
AttributeList attrList = new AttributeList();
for(int i=0; i<attrNames.length; i++)
{
Object defaultValue;
try
{
defaultValue = mbean.getDefaultAttributeValue(attrNames[i]);
}
catch (AttributeNotFoundException e)
{
defaultValue = null;
}
catch (MBeanConfigException e)
{
defaultValue = null;
}
if(defaultValue!=null)
attrList.add(new Attribute(attrNames[i], defaultValue));
}
return attrList;
|
public javax.management.AttributeList | getGenericAttributes(java.lang.String[] dottedNames)Obtains the Dynamic MBean Attribute objects for given attribute patterns (in dotted notation).
AttributeList list = new AttributeList();
for(int i=0; i<dottedNames.length; i++)
{
list.addAll(getGenericAttribute(dottedNames[i]));
}
return list;
|
protected java.lang.Class | getImplementingClass()Every resource MBean should override this method to execute specific
operations on the MBean. This method is enhanced in 8.0. It was a no-op
in 7.0. In 8.0, it is modified to invoke the actual method through
reflection.
return ( this.getClass() );
|
protected java.lang.Object | getImplementingMBean()Reflection requires the implementing object.
return ( this );
|
public javax.management.MBeanInfo | getMBeanInfo()Implementation of getMBeanInfo()
Uses helper class MBeanEasyConfig to construct whole MBeanXXXInfo tree.
try
{
return (new MBeanEasyConfig(getClass(), mAttrs, mOpers, null)).getMBeanInfo();
}
catch(Throwable e)
{
sLogger.log(Level.FINE, MSG_GETMBEANINFO_FAILED, e);
return null;
}
|
java.util.ArrayList | getMBeanNamesFromDottedPattern(java.lang.String dottedStringName)
String attrName = extractAttrNameFromDotted(dottedStringName);
int idx = dottedStringName.length() - attrName.length() - 1;
if(idx<1) {
String msg = localStrings.getString( "admin.server.core.mbean.config.genericconfigurator_cannot_extract_attribute_name_from_dotted_notation", dottedStringName );
throw new MalformedNameException( msg );
}
ConfigMBeanNamingInfo info = new ConfigMBeanNamingInfo(dottedStringName.substring(0,idx));
ArrayList list = new ArrayList();
list.add(info.getObjectName());
return list;
|
public javax.management.AttributeList | getMonitor(java.lang.String dottedName)Method that returns the monitorable params as an attribute list. This
method will contact the running administered instance that is represented
in the name of the attribute and will return the values from various
monitoring data providers in the administered instance.
Note that this method gets the data as a whole. Returned list will have
all the attributes that represent the MBean attributes.
The semantics are similar to the generic get command so that
(server-name).application.(app-name).ejb-module.(mod-name).ejb.
(bean-name).pool.* will give all the monitorable attributes of
MBean corresponding to this name.
Name name = new Name(dottedName);
String instanceName = name.getNamePart(0).toString();
// 1. create MonitorCommand
CommandMapper cm = CommandMapper.getInstance(instanceName);
MonitorGetCommand command = cm.mapGetCommand(dottedName); //throws InvalidDottedNameException
// 2. create correspondent MonitoringEvent
MonitoringEvent event = new MonitoringEvent(instanceName, dottedName, MonitoringEvent.GET_MONITOR_DATA, command);
// 3. send/receive event to instance
AdminEventResult result = AdminEventMulticaster.multicastEvent(event);
// 4. analyse the result
if(!result.getResultCode().equals(result.SUCCESS))
{
handleMonitoringError(result, instanceName, dottedName);
}
// 5. extract result list
return (AttributeList)result.getAttribute(event.getEffectiveDestination(), MonitorCommand.MONITOR_RESULT);
|
public javax.management.AttributeList | getMonitor(java.lang.String[] dottedNames)
AttributeList list = new AttributeList();
for(int i=0; i<dottedNames.length; i++)
{
list.addAll(getMonitor(dottedNames[i]));
}
return list;
|
private java.util.ArrayList | getTargetObjectNames(javax.management.ObjectName objectNamePattern)
ArrayList list = new ArrayList();
if(objectNamePattern==null)
return list;
// call to MBeanServer.queryNames()
Set mNames = mServer.queryMBeans(objectNamePattern, null);
Iterator it = mNames.iterator();
while (it.hasNext())
{
list.add(it.next());
}
// because of lazy loading we can have no registered mbeans, in this case - add pattern
// FIXME: add check is ObjectName -> non-wildcarded pattern
// NOTE: it will be added only if no one registered bean with such pattern otherwise it will work as before
if(list.size()==0)
{
list.add(objectNamePattern);
}
// list.add(new ObjectName(objectNamePattern)); //for now
return list;
|
private void | handleMonitoringError(com.sun.enterprise.admin.event.AdminEventResult result, java.lang.String instance, java.lang.String compName)Handle monitoring error.
String resultCode = result.getResultCode();
if (AdminEventResult.TRANSMISSION_ERROR.equals(resultCode)) {
String msg = localStrings.getString( "admin.server.core.mbean.config.failed_to_connect_instance", instance );
throw new ServiceNotFoundException( msg );
} else if (AdminEventResult.MBEAN_NOT_FOUND.equals(resultCode)) {
String msg = localStrings.getString( "admin.server.core.mbean.config.unmatched_mbean", compName );
throw new InstanceNotFoundException( msg );
} else if (AdminEventResult.MBEAN_ATTR_NOT_FOUND.equals(resultCode)) {
String msg = localStrings.getString( "admin.server.core.mbean.config.unmatched_attribute", compName );
throw new AttributeNotFoundException( msg );
} else if (!AdminEventResult.SUCCESS.equals(resultCode)) {
String msg = localStrings.getString( "admin.server.core.mbean.config.other_monitoring_error", resultCode );
throw new JMRuntimeException( msg );
}
|
public java.lang.String[] | listGenericDottedNameContinuiations(java.lang.String dottedName)
sLogger.log(Level.FINEST, MSG_LIST_NAMES_CONTS, dottedName);
dottedName = dottedName.trim();
String instanceName = extractInstanceNameFromDotted(dottedName);
return ConfigMBeansNaming.findNameContinuation(instanceName, dottedName);
|
public java.lang.String[] | listMonitor(java.lang.String dottedName)Returns the list of immediate children of a node that represents
a component in a hierarchy of nodes. Note that this method will return
the list of names of children only. The idea is to aid in reaching the
leaf nodes in the hierarchy (Semantics of unix list command). The name
of the node is represented by a dotted name.
Name name = new Name(dottedName);
String instanceName = name.getNamePart(0).toString();
// 1. create MonitorCommand
CommandMapper cm = CommandMapper.getInstance(instanceName);
MonitorListCommand command = cm.mapListCommand(dottedName); //throws InvalidDottedNameException
// 2. create correspondent MonitoringEvent
MonitoringEvent event = new MonitoringEvent(instanceName, dottedName, MonitoringEvent.LIST_MONITORABLE, command);
// 3. send/receive event to instance
AdminEventResult result = AdminEventMulticaster.multicastEvent(event);
// 4. analyse the result
if(!result.getResultCode().equals(result.SUCCESS))
{
handleMonitoringError(result, instanceName, dottedName);
}
// 5. extract result list
return (String[])result.getAttribute(event.getEffectiveDestination(), MonitorCommand.MONITOR_RESULT);
|
public javax.management.AttributeList | setGenericAttribute(java.lang.String dottedName, java.lang.Object value)Set Dynamic MBean attribute values for given attribute pattern (in dotted notation).
sLogger.log(Level.FINEST, MSG_SET_ATTRIBUTE, new Object[]{dottedName, value});
if(mServer==null)
mServer=MBeanServerFactory.getMBeanServer();
String attrName = extractAttrNameFromDotted(dottedName);
ArrayList objectNames = getMBeanNamesFromDottedPattern(dottedName);
AttributeList attrList = new AttributeList();
for(int i=0; i<objectNames.size(); i++)
setMatchedAttributesToValue(attrList, (ObjectName)objectNames.get(i), attrName, value);
return attrList;
|
public javax.management.AttributeList | setGenericAttributes(javax.management.AttributeList al)
AttributeList list = new AttributeList();
Iterator it = al.iterator();
while (it.hasNext())
{
Attribute attribute = (Attribute) it.next();
String name = attribute.getName();
Object value = attribute.getValue();
try
{
list.addAll(setGenericAttribute(name, value));
}
catch (AttributeNotFoundException anfe)
{
sLogger.log(Level.FINE, MSG_ATTR_NOT_FOUND, name);
}
}
return list;
|
private int | setMatchedAttributesToValue(javax.management.AttributeList attrList, javax.management.ObjectName objName, java.lang.String attrPattern, java.lang.Object value)
ArrayList attrNames = getAttrNames(objName, attrPattern);
if(attrNames.size()==0)
{
String msg = localStrings.getString( "admin.server.core.mbean.config.no_attributes_matched_to_pattern", attrPattern );
throw new AttributeNotFoundException( msg );
}
for(int i=0; i<attrNames.size(); i++)
{
String name = (String)attrNames.get(i);
Object obj = convertValueToAttributeType(objName, name, value);
mServer.setAttribute(objName, new Attribute(name, obj));
attrList.add(new Attribute(name, obj));
}
return attrNames.size(); //number of added elements
|
public javax.management.AttributeList | setMonitor(javax.management.AttributeList al)
AttributeList list = new AttributeList();
Iterator it = al.iterator();
while (it.hasNext())
{
Attribute attribute = (Attribute) it.next();
String name = attribute.getName();
Object value = attribute.getValue();
try
{
list.addAll(setMonitor(name, value));
}
catch (AttributeNotFoundException anfe)
{
sLogger.log(Level.FINE, MSG_ATTR_NOT_FOUND, name);
}
}
return list;
|
public javax.management.AttributeList | setMonitor(java.lang.String dottedName, java.lang.Object value)
Name name = new Name(dottedName);
String instanceName = name.getNamePart(0).toString();
// 1. create MonitorCommand
CommandMapper cm = CommandMapper.getInstance(instanceName);
MonitorSetCommand command = cm.mapSetCommand(dottedName, value); //throws InvalidDottedNameException
// 2. create correspondent MonitoringEvent
MonitoringEvent event = new MonitoringEvent(instanceName, dottedName, MonitoringEvent.SET_MONITOR_DATA, command);
// 3. send/receive event to instance
AdminEventResult result = AdminEventMulticaster.multicastEvent(event);
// 4. analyse the result
if(!result.getResultCode().equals(result.SUCCESS))
{
handleMonitoringError(result, instanceName, dottedName);
}
// 5. extract result list
AttributeList resultList = null;
AttributeList tmp = (AttributeList)result.getAttribute(event.getEffectiveDestination(), MonitorCommand.MONITOR_RESULT);
Iterator it = tmp.iterator();
while (it.hasNext())
{
Attribute attribute = (Attribute) it.next();
resultList = (AttributeList)attribute.getValue();
}
return resultList;
|