下面列出了javax.management.RuntimeOperationsException#javax.management.AttributeList 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void checkRegionLatencyCounters(JMXOperations ops, ObjectName targetMbean){
logInfo(prefix + " Calling checkRegionLatencyCounters");
String attributes[] = {
"CacheListenerCallsAvgLatency",
"CacheWriterCallsAvgLatency",
//"CreatesAvgLatency",
//"DestroyAvgLatency",
//"GeAllAvgLatency",
"GetsAvgLatency",
"LoadsAverageLatency",
"NetLoadsAverageLatency",
"NetSearchAverageLatency",
"PutAllAvgLatency",
"PutsAvgLatency",
};
String url = ops.selectManagingNode();
AttributeList attrList = (AttributeList) ops.getAttributes(url, targetMbean, attributes);
logInfo("checkRegionLatencyCounters " + HydraUtil.ObjectToString(attrList));
logInfo(prefix + " Completed checkRegionLatencyCounters test successfully");
}
@Override
public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException,
ReflectionException {
Throwable error = null;
MBeanServerPlugin delegate = null;
final boolean readOnly = true;
try {
delegate = findDelegate(name);
if (delegate.shouldAuthorize()) {
for(String attribute : attributes) {
authorizeMBeanOperation(delegate, name, GET_ATTRIBUTES, attribute, JmxAction.Impact.READ_ONLY);
}
}
return delegate.getAttributes(name, attributes);
} catch (Exception e) {
error = e;
if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e;
if (e instanceof ReflectionException) throw (ReflectionException)e;
throw makeRuntimeException(e);
} finally {
if (shouldAuditLog(delegate, readOnly)) {
new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getAttributes(name, attributes);
}
}
}
/**
* @see javax.management.MBeanServerConnection#getAttributes(javax.management.ObjectName, java.lang.String[])
*/
public AttributeList getAttributes(final ObjectName name, final String[] attributes)
throws InstanceNotFoundException, ReflectionException, IOException {
if (this.subject == null) {
return this.mbs.getAttributes(name, attributes);
}
try {
return (AttributeList) Subject.doAsPrivileged(this.subject, new PrivilegedExceptionAction<AttributeList>() {
public final AttributeList run() throws Exception {
return mbs.getAttributes(name, attributes);
}
}, this.context);
} catch (final PrivilegedActionException pe) {
final Exception e = JMXProviderUtils.extractException(pe);
if (e instanceof InstanceNotFoundException)
throw (InstanceNotFoundException) e;
if (e instanceof ReflectionException)
throw (ReflectionException) e;
if (e instanceof IOException)
throw (IOException) e;
throw JMXProviderUtils.newIOException("Got unexpected server exception: " + e, e);
}
}
@Override
public String getStatHistory(String sessionId, String range1, String function)
throws ReflectionException, InterruptedException, IntrospectionException, NotConnectedException,
InstanceNotFoundException, MalformedObjectNameException, IOException {
String newRange = MBeanInfoViewer.possibleModifyRange(range1, dataSources, 'a');
StatHistoryCacheEntry entry = StatHistoryCaching.getInstance().getEntryOrCompute(newRange, () -> {
RMProxyUserInterface rm = checkAccess(sessionId);
AttributeList attrs = rm.getMBeanAttributes(new ObjectName(RMJMXBeans.RUNTIMEDATA_MBEAN_NAME),
new String[] { "StatisticHistory" });
Attribute attr = (Attribute) attrs.get(0);
// content of the RRD4J database backing file
byte[] rrd4j = (byte[]) attr.getValue();
return MBeanInfoViewer.rrdContent(rrd4j, newRange, dataSources, function);
});
return entry.getValue();
}
@Override
public AttributeList setAttributes( AttributeList attributeList )
{
AttributeList list = new AttributeList();
for ( int i = 0; i < list.size(); i++ ) {
Attribute attribute = ( Attribute ) list.get( i );
try {
setAttribute( attribute );
list.add( attribute );
} catch ( AttributeNotFoundException | InvalidAttributeValueException | ReflectionException | MBeanException e ) {
e.printStackTrace();
}
}
return list;
}
@Override
public AttributeList getAttributes(String[] attributeNames) {
if (attributeNames == null || attributeNames.length == 0)
throw new IllegalArgumentException();
updateMbeanInfoIfMetricsListChanged();
AttributeList result = new AttributeList(attributeNames.length);
for (String iAttributeName : attributeNames) {
try {
Object value = getAttribute(iAttributeName);
result.add(new Attribute(iAttributeName, value));
} catch (Exception e) {
continue;
}
}
return result;
}
private synchronized NameValueMap getCachedAttributes(
ObjectName objName, Set<String> attrNames) throws
InstanceNotFoundException, ReflectionException, IOException {
NameValueMap values = cachedValues.get(objName);
if (values != null && values.keySet().containsAll(attrNames)) {
return values;
}
attrNames = new TreeSet<String>(attrNames);
Set<String> oldNames = cachedNames.get(objName);
if (oldNames != null) {
attrNames.addAll(oldNames);
}
values = new NameValueMap();
final AttributeList attrs = conn.getAttributes(
objName,
attrNames.toArray(new String[attrNames.size()]));
for (Attribute attr : attrs.asList()) {
values.put(attr.getName(), attr.getValue());
}
cachedValues.put(objName, values);
cachedNames.put(objName, attrNames);
return values;
}
public void checkRegionRuntimeAttributes(JMXOperations ops, ObjectName targetMbean){
logInfo(prefix + " Calling checkRegionRuntimeAttributes");
String attributes[] = {
"LastModifiedTime",
"LastAccessedTime",
"MissCount",
"HitCount",
"HitRatio",
"EntryCount",
"TotalEntriesOnlyOnDisk",
"TotalDiskEntriesInVM"
};
String url = ops.selectManagingNode();
AttributeList attrList = (AttributeList) ops.getAttributes(url, targetMbean, attributes);
logInfo("checkRegionRuntimeAttributes " + HydraUtil.ObjectToString(attrList));
logInfo(prefix + " Completed checkRegionRuntimeAttributes test successfully");
}
@Test
public void registersMBeansForMeters() throws Exception {
final AttributeList attributes = getAttributes("test.meter",
"Count",
"MeanRate",
"OneMinuteRate",
"FiveMinuteRate",
"FifteenMinuteRate",
"RateUnit");
Assertions.assertThat(values(attributes))
.contains(Assertions.entry("Count", 1L))
.contains(Assertions.entry("MeanRate", 2.0))
.contains(Assertions.entry("OneMinuteRate", 3.0))
.contains(Assertions.entry("FiveMinuteRate", 4.0))
.contains(Assertions.entry("FifteenMinuteRate", 5.0))
.contains(Assertions.entry("RateUnit", "events/second"));
}
public void checkRegionStatistics(JMXOperations ops, ObjectName targetMbean){
logInfo(prefix + " Calling checkRegionStatistics");
String attributes[] = {
"GetsRate",
"PutsRate",
"CreatesRate",
"DestroyRate",
"PutAllRate",
"PutLocalRate",
"PutRemoteRate",
"PutRemoteLatency",
"PutRemoteAvgLatency",
"DiskReadsRate",
"DiskWritesRate",
"CacheWriterCallsAvgLatency",
"CacheListenerCallsAvgLatency",
"LruEvictionRate",
"LruDestroyRate"
};
String url = ops.selectManagingNode();
AttributeList attrList = (AttributeList) ops.getAttributes(url, targetMbean, attributes);
logInfo("checkRegionStatistics " + HydraUtil.ObjectToString(attrList));
logInfo(prefix + " Completed checkRegionStatistics test successfully");
}
public static void matchValues(AttributeList list, Map<String, Object> expectedMap) {
for (Entry<String, Object> entry : expectedMap.entrySet()) {
boolean found = false;
for (int i = 0; i < list.size(); i++) {
Attribute attr = (Attribute) list.get(i);
if (attr.getName().equals(entry.getKey())) {
found = true;
Log.getLogWriter().info(
entry.getKey() + "--> JMX : " + attr.getValue() + " BB : "
+ entry.getValue());
if (!attr.getValue().equals(entry.getValue())) {
printAndSaveError("Attribute", null, attr, entry.getValue());
}
}
}
if (!found)
throw new TestException("Error attribute " + entry.getKey()
+ " not found");
}
}
@Override
public AttributeList getAttributes(String[] attributeNames) {
if (attributeNames == null || attributeNames.length == 0)
throw new IllegalArgumentException();
updateMbeanInfoIfMetricsListChanged();
AttributeList result = new AttributeList(attributeNames.length);
for (String iAttributeName : attributeNames) {
try {
Object value = getAttribute(iAttributeName);
result.add(new Attribute(iAttributeName, value));
} catch (Exception e) {
continue;
}
}
return result;
}
/**
* Returns the values of several attributes in the ModelMBean.
* Executes a getAttribute for each attribute name in the
* attrNames array passed in.
*
* @param attrNames A String array of names of the attributes
* to be retrieved.
*
* @return The array of the retrieved attributes.
*
* @exception RuntimeOperationsException Wraps an
* {@link IllegalArgumentException}: The object name in parameter is
* null or attributes in parameter is null.
*
* @see #setAttributes(javax.management.AttributeList)
*/
public AttributeList getAttributes(String[] attrNames) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
"getAttributes(String[])","Entry");
}
if (attrNames == null)
throw new RuntimeOperationsException(new
IllegalArgumentException("attributeNames must not be null"),
"Exception occurred trying to get attributes of a "+
"RequiredModelMBean");
AttributeList responseList = new AttributeList();
for (int i = 0; i < attrNames.length; i++) {
try {
responseList.add(new Attribute(attrNames[i],
getAttribute(attrNames[i])));
} catch (Exception e) {
// eat exceptions because interface doesn't have an
// exception on it
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
"getAttributes(String[])",
"Failed to get \"" + attrNames[i] + "\": ", e);
}
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
"getAttributes(String[])","Exit");
}
return responseList;
}
public AttributeList setAttributes(AttributeList attributes) {
AttributeList list = new AttributeList();
// We carefully avoid using any new stuff from AttributeList here!
for (Iterator<?> it = attributes.iterator(); it.hasNext(); ) {
Attribute attr = (Attribute) it.next();
try {
setAttribute(attr);
list.add(attr);
} catch (Exception e) {
// OK: ignore per spec
}
}
return list;
}
public void checkDiskCounters(JMXOperations ops, ObjectName targetMbean){
String attributes[] = {
"QueueSize",
"TotalBytesOnDisk",
"TotalQueueSize",
"TotalBackupInProgress",
"TotalRecoveriesInProgress"
};
logInfo(prefix + " Calling checkDiskCounters");
String url = ops.selectManagingNode();
AttributeList attrList = (AttributeList) ops.getAttributes(url, targetMbean, attributes);
logInfo("checkDiskCounters " + HydraUtil.ObjectToString(attrList));
}
@Override
public AttributeList setAttributes(AttributeList attributes) {
AttributeList successful = new AttributeList();
for (Attribute attribute: attributes.asList()) {
try {
setAttribute(attribute);
successful.add(attribute);
} catch (AttributeNotFoundException | InvalidAttributeValueException | MBeanException | ReflectionException e) {
// Ignore as we just won't return it in the result.
}
}
return successful;
}
public AttributeList getAttributes(String[] attributes) {
AttributeList list = new AttributeList();
for (String attr : attributes) {
try {
list.add(new Attribute(attr, getAttribute(attr)));
} catch (Exception e) {
// OK: ignore per spec
}
}
return list;
}
/**
* Makes it possible to get the values of several attributes of
* the MBeanServerDelegate.
*
* @param attributes A list of the attributes to be retrieved.
*
* @return The list of attributes retrieved.
*
*/
public AttributeList getAttributes(String[] attributes) {
// If attributes is null, the get all attributes.
//
final String[] attn = (attributes==null?attributeNames:attributes);
// Prepare the result list.
//
final int len = attn.length;
final AttributeList list = new AttributeList(len);
// Get each requested attribute.
//
for (int i=0;i<len;i++) {
try {
final Attribute a =
new Attribute(attn[i],getAttribute(attn[i]));
list.add(a);
} catch (Exception x) {
// Skip the attribute that couldn't be obtained.
//
if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) {
MBEANSERVER_LOGGER.log(Level.TRACE,
"Attribute " + attn[i] + " not found");
}
}
}
// Finally return the result.
//
return list;
}
@Override
protected AttributeList getAttributes(String[] attributes) throws SchedulerException {
try {
return server.getAttributes(getSchedulerObjectName(), attributes);
} catch (Exception e) {
throw new SchedulerException("Failed to get Scheduler MBean attributes: " + Arrays.asList(attributes), e);
}
}
/**
* Returns the values of several attributes in the ModelMBean.
* Executes a getAttribute for each attribute name in the
* attrNames array passed in.
*
* @param attrNames A String array of names of the attributes
* to be retrieved.
*
* @return The array of the retrieved attributes.
*
* @exception RuntimeOperationsException Wraps an
* {@link IllegalArgumentException}: The object name in parameter is
* null or attributes in parameter is null.
*
* @see #setAttributes(javax.management.AttributeList)
*/
public AttributeList getAttributes(String[] attrNames) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
"getAttributes(String[])","Entry");
}
if (attrNames == null)
throw new RuntimeOperationsException(new
IllegalArgumentException("attributeNames must not be null"),
"Exception occurred trying to get attributes of a "+
"RequiredModelMBean");
AttributeList responseList = new AttributeList();
for (int i = 0; i < attrNames.length; i++) {
try {
responseList.add(new Attribute(attrNames[i],
getAttribute(attrNames[i])));
} catch (Exception e) {
// eat exceptions because interface doesn't have an
// exception on it
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
"getAttributes(String[])",
"Failed to get \"" + attrNames[i] + "\": ", e);
}
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
"getAttributes(String[])","Exit");
}
return responseList;
}
public AttributeList getAttributes(String[] attributes) {
AttributeList list = new AttributeList();
for (String attr : attributes) {
try {
list.add(new Attribute(attr, getAttribute(attr)));
} catch (Exception e) {
// OK: ignore per spec
}
}
return list;
}
public static void register(ConnectorConnectionPool resource, ServerInterface mejb, boolean update) throws Exception{
AttributeList attrList = ResourceUtils.getResourceAttributes(resource);
PropertyElement[] props = resource.getPropertyElement();
Properties propsList = getProperties(props);
Object[] params = new Object[]{attrList, propsList, null};
String resourceName = resource.getName();
if(!isResourceUpdated(resourceName, mejb, attrList, propsList, __GetConnPoolResource)){
createResource(__CreateConnPool, params, mejb);
}
}
@Override
public AttributeList setAttributes(ObjectName name, AttributeList attributes)
throws InstanceNotFoundException, ReflectionException {
Boolean originalValue = AUTHORIZING.get();
try {
AUTHORIZING.set(Boolean.TRUE);
return delegate.setAttributes(name, attributes);
} finally {
AUTHORIZING.set(originalValue);
}
}
public AttributeList setAttributes(ObjectName name,
AttributeList attributes)
throws InstanceNotFoundException,
ReflectionException,
IOException {
if (logger.debugOn()) logger.debug("setAttributes",
"name=" + name + ", attributes="
+ attributes);
final MarshalledObject<AttributeList> sAttributes =
new MarshalledObject<AttributeList>(attributes);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.setAttributes(name,
sAttributes,
delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.setAttributes(name,
sAttributes,
delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
/**
* Set attributes on a MBean
* @param name The name of the bean
* @param attributes The attributes
* @return The updated attributes list
* @exception PrivilegedExceptionAction Thrown if the operation cannot be performed
*/
@SuppressWarnings({ "unchecked" })
private AttributeList setAttributes(final String name, final HashMap attributes) throws PrivilegedActionException
{
return AccessController.doPrivileged(new PrivilegedExceptionAction<AttributeList>()
{
public AttributeList run() throws Exception
{
return Server.setAttributes(name, attributes);
}
});
}
/**
* Call <code>checkWrite()</code>, then forward this method to the
* wrapped object.
*/
public AttributeList setAttributes(ObjectName name,
AttributeList attributes)
throws InstanceNotFoundException, ReflectionException {
checkWrite();
return getMBeanServer().setAttributes(name, attributes);
}
public final AttributeList setAttributes(AttributeList attributes) {
final AttributeList result = new AttributeList(attributes.size());
for (Object attrObj : attributes) {
// We can't use AttributeList.asList because it has side-effects
Attribute attr = (Attribute) attrObj;
try {
setAttribute(attr);
result.add(new Attribute(attr.getName(), attr.getValue()));
} catch (Exception e) {
// OK: attribute is not included in returned list, per spec
// XXX: log the exception
}
}
return result;
}
@Override
public AttributeList getAttributes(String[] attributeNames) {
AttributeList returnList = new AttributeList();
for (String name : attributeNames) {
try {
returnList.add(new Attribute(name, getAttribute(name)));
} catch (Exception e) {
returnList.add(new Attribute(name, "Getting attribute threw: " + e.getMessage()));
}
}
return returnList;
}
public void checkGemfireLockCounters(JMXOperations ops, ObjectName targetMbean){
logInfo(prefix + " Calling checkGemfireLockCounters");
String attributes[] = {
"LockRequestQueues",
"LockWaitsInProgress",
"TotalLockWaitTime",
"TotalNumberOfLockService"
};
String url = ops.selectManagingNode();
AttributeList attrList = (AttributeList) ops.getAttributes(url, targetMbean, attributes);
logInfo("checkGemfireLockCounters " + HydraUtil.ObjectToString(attrList));
logInfo(prefix + " Completed checkGemfireLockCounters test successfully");
}
public AttributeList getAttributes(String[] attributes) {
AttributeList list = new AttributeList();
for (String attr : attributes) {
try {
list.add(new Attribute(attr, getAttribute(attr)));
} catch (Exception e) {
// OK: ignore per spec
}
}
return list;
}