use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class Monitor method monitor.
/**
* This method is called by the monitor each time
* the granularity period has been exceeded.
* @param o The observed object.
*/
private void monitor(ObservedObject o, int index, int[] an) {
String attribute;
String notifType = null;
String msg = null;
Object derGauge = null;
Object trigger = null;
ObjectName object;
Comparable<?> value = null;
MonitorNotification alarm = null;
if (!isActive())
return;
//
synchronized (this) {
object = o.getObservedObject();
attribute = getObservedAttribute();
if (object == null || attribute == null) {
return;
}
}
// Check that the observed object is registered in the
// MBean server and that the observed attribute
// belongs to the observed object.
//
Object attributeValue = null;
try {
attributeValue = getAttribute(server, object, attribute);
if (attributeValue == null)
if (isAlreadyNotified(o, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED))
return;
else {
notifType = OBSERVED_ATTRIBUTE_TYPE_ERROR;
setAlreadyNotified(o, index, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED, an);
msg = "The observed attribute value is null.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
}
} catch (NullPointerException np_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = "The monitor must be registered in the MBean " + "server or an MBeanServerConnection must be " + "explicitly supplied.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", np_ex.toString());
}
} catch (InstanceNotFoundException inf_ex) {
if (isAlreadyNotified(o, OBSERVED_OBJECT_ERROR_NOTIFIED))
return;
else {
notifType = OBSERVED_OBJECT_ERROR;
setAlreadyNotified(o, index, OBSERVED_OBJECT_ERROR_NOTIFIED, an);
msg = "The observed object must be accessible in " + "the MBeanServerConnection.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", inf_ex.toString());
}
} catch (AttributeNotFoundException anf_ex) {
if (isAlreadyNotified(o, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED))
return;
else {
notifType = OBSERVED_ATTRIBUTE_ERROR;
setAlreadyNotified(o, index, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED, an);
msg = "The observed attribute must be accessible in " + "the observed object.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", anf_ex.toString());
}
} catch (MBeanException mb_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = mb_ex.getMessage() == null ? "" : mb_ex.getMessage();
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", mb_ex.toString());
}
} catch (ReflectionException ref_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED)) {
return;
} else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = ref_ex.getMessage() == null ? "" : ref_ex.getMessage();
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", ref_ex.toString());
}
} catch (IOException io_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = io_ex.getMessage() == null ? "" : io_ex.getMessage();
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", io_ex.toString());
}
} catch (RuntimeException rt_ex) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = rt_ex.getMessage() == null ? "" : rt_ex.getMessage();
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", rt_ex.toString());
}
}
synchronized (this) {
//
if (!isActive())
return;
//
if (!attribute.equals(getObservedAttribute()))
return;
//
if (msg == null) {
try {
value = getComparableFromAttribute(object, attribute, attributeValue);
} catch (ClassCastException e) {
if (isAlreadyNotified(o, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED))
return;
else {
notifType = OBSERVED_ATTRIBUTE_TYPE_ERROR;
setAlreadyNotified(o, index, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED, an);
msg = "The observed attribute value does not " + "implement the Comparable interface.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", e.toString());
}
} catch (AttributeNotFoundException e) {
if (isAlreadyNotified(o, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED))
return;
else {
notifType = OBSERVED_ATTRIBUTE_ERROR;
setAlreadyNotified(o, index, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED, an);
msg = "The observed attribute must be accessible in " + "the observed object.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", e.toString());
}
} catch (RuntimeException e) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
msg = e.getMessage() == null ? "" : e.getMessage();
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", e.toString());
}
}
}
//
if (msg == null) {
if (!isComparableTypeValid(object, attribute, value)) {
if (isAlreadyNotified(o, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED))
return;
else {
notifType = OBSERVED_ATTRIBUTE_TYPE_ERROR;
setAlreadyNotified(o, index, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED, an);
msg = "The observed attribute type is not valid.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
}
}
}
//
if (msg == null) {
if (!isThresholdTypeValid(object, attribute, value)) {
if (isAlreadyNotified(o, THRESHOLD_ERROR_NOTIFIED))
return;
else {
notifType = THRESHOLD_ERROR;
setAlreadyNotified(o, index, THRESHOLD_ERROR_NOTIFIED, an);
msg = "The threshold type is not valid.";
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
}
}
}
//
if (msg == null) {
msg = buildErrorNotification(object, attribute, value);
if (msg != null) {
if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
return;
else {
notifType = RUNTIME_ERROR;
setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
MONITOR_LOGGER.logp(Level.FINEST, Monitor.class.getName(), "monitor", msg);
}
}
}
//
if (msg == null) {
// Clear all already notified flags.
//
resetAllAlreadyNotified(o, index, an);
// Get derived gauge from comparable value.
//
derGauge = getDerivedGaugeFromComparable(object, attribute, value);
o.setDerivedGauge(derGauge);
o.setDerivedGaugeTimeStamp(System.currentTimeMillis());
// Check if an alarm must be fired.
//
alarm = buildAlarmNotification(object, attribute, (Comparable<?>) derGauge);
}
}
//
if (msg != null)
sendNotification(notifType, System.currentTimeMillis(), msg, derGauge, trigger, object, true);
//
if (alarm != null && alarm.getType() != null)
sendNotification(alarm.getType(), System.currentTimeMillis(), alarm.getMessage(), derGauge, alarm.getTrigger(), object, false);
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class MLet method getMBeansFromURL.
/**
* Loads a text file containing MLET tags that define the MBeans to
* be added to the MBean server. The location of the text file is specified by
* a URL. The MBeans specified in the MLET file will be instantiated and
* registered in the MBean server.
*
* @param url The URL of the text file to be loaded as String object.
*
* @return A set containing one entry per MLET tag in the m-let
* text file loaded. Each entry specifies either the
* ObjectInstance for the created MBean, or a throwable object
* (that is, an error or an exception) if the MBean could not be
* created.
*
* @exception ServiceNotFoundException One of the following
* errors has occurred: The m-let text file does not contain an
* MLET tag, the m-let text file is not found, a mandatory
* attribute of the MLET tag is not specified, the url is
* malformed.
* @exception IllegalStateException MLet MBean is not registered
* with an MBeanServer.
*
*/
public Set<Object> getMBeansFromURL(String url) throws ServiceNotFoundException {
String mth = "getMBeansFromURL";
if (server == null) {
throw new IllegalStateException("This MLet MBean is not " + "registered with an MBeanServer.");
}
// Parse arguments
if (url == null) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "URL is null");
throw new ServiceNotFoundException("The specified URL is null");
} else {
url = url.replace(File.separatorChar, '/');
}
if (MLET_LOGGER.isLoggable(Level.FINER)) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "<URL = " + url + ">");
}
// Parse URL
try {
MLetParser parser = new MLetParser();
mletList = parser.parseURL(url);
} catch (Exception e) {
final String msg = "Problems while parsing URL [" + url + "], got exception [" + e.toString() + "]";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
throw EnvHelp.initCause(new ServiceNotFoundException(msg), e);
}
// Check that the list of MLets is not empty
if (mletList.size() == 0) {
final String msg = "File " + url + " not found or MLET tag not defined in file";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
throw new ServiceNotFoundException(msg);
}
// Walk through the list of MLets
Set<Object> mbeans = new HashSet<Object>();
for (MLetContent elmt : mletList) {
// Initialize local variables
String code = elmt.getCode();
if (code != null) {
if (code.endsWith(".class")) {
code = code.substring(0, code.length() - 6);
}
}
String name = elmt.getName();
URL codebase = elmt.getCodeBase();
String version = elmt.getVersion();
String serName = elmt.getSerializedObject();
String jarFiles = elmt.getJarFiles();
URL documentBase = elmt.getDocumentBase();
// Display debug information
if (MLET_LOGGER.isLoggable(Level.FINER)) {
final StringBuilder strb = new StringBuilder().append("\n\tMLET TAG = ").append(elmt.getAttributes()).append("\n\tCODEBASE = ").append(codebase).append("\n\tARCHIVE = ").append(jarFiles).append("\n\tCODE = ").append(code).append("\n\tOBJECT = ").append(serName).append("\n\tNAME = ").append(name).append("\n\tVERSION = ").append(version).append("\n\tDOCUMENT URL = ").append(documentBase);
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, strb.toString());
}
// Load classes from JAR files
StringTokenizer st = new StringTokenizer(jarFiles, ",", false);
while (st.hasMoreTokens()) {
String tok = st.nextToken().trim();
if (MLET_LOGGER.isLoggable(Level.FINER)) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "Load archive for codebase <" + codebase + ">, file <" + tok + ">");
}
//
try {
codebase = check(version, codebase, tok, elmt);
} catch (Exception ex) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), mth, "Got unexpected exception", ex);
mbeans.add(ex);
continue;
}
// URLs to search for classes and resources.
try {
if (!Arrays.asList(getURLs()).contains(new URL(codebase.toString() + tok))) {
addURL(codebase + tok);
}
} catch (MalformedURLException me) {
// OK : Ignore jar file if its name provokes the
// URL to be an invalid one.
}
}
// Instantiate the class specified in the
// CODE or OBJECT section of the MLet tag
//
Object o;
ObjectInstance objInst;
if (code != null && serName != null) {
final String msg = "CODE and OBJECT parameters cannot be specified at the " + "same time in tag MLET";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
mbeans.add(new Error(msg));
continue;
}
if (code == null && serName == null) {
final String msg = "Either CODE or OBJECT parameter must be specified in " + "tag MLET";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
mbeans.add(new Error(msg));
continue;
}
try {
if (code != null) {
List<String> signat = elmt.getParameterTypes();
List<String> stringPars = elmt.getParameterValues();
List<Object> objectPars = new ArrayList<Object>();
for (int i = 0; i < signat.size(); i++) {
objectPars.add(constructParameter(stringPars.get(i), signat.get(i)));
}
if (signat.isEmpty()) {
if (name == null) {
objInst = server.createMBean(code, null, mletObjectName);
} else {
objInst = server.createMBean(code, new ObjectName(name), mletObjectName);
}
} else {
Object[] parms = objectPars.toArray();
String[] signature = new String[signat.size()];
signat.toArray(signature);
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
final StringBuilder strb = new StringBuilder();
for (int i = 0; i < signature.length; i++) {
strb.append("\n\tSignature = ").append(signature[i]).append("\t\nParams = ").append(parms[i]);
}
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), mth, strb.toString());
}
if (name == null) {
objInst = server.createMBean(code, null, mletObjectName, parms, signature);
} else {
objInst = server.createMBean(code, new ObjectName(name), mletObjectName, parms, signature);
}
}
} else {
o = loadSerializedObject(codebase, serName);
if (name == null) {
server.registerMBean(o, null);
} else {
server.registerMBean(o, new ObjectName(name));
}
objInst = new ObjectInstance(name, o.getClass().getName());
}
} catch (ReflectionException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "ReflectionException", ex);
mbeans.add(ex);
continue;
} catch (InstanceAlreadyExistsException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "InstanceAlreadyExistsException", ex);
mbeans.add(ex);
continue;
} catch (MBeanRegistrationException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "MBeanRegistrationException", ex);
mbeans.add(ex);
continue;
} catch (MBeanException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "MBeanException", ex);
mbeans.add(ex);
continue;
} catch (NotCompliantMBeanException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "NotCompliantMBeanException", ex);
mbeans.add(ex);
continue;
} catch (InstanceNotFoundException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "InstanceNotFoundException", ex);
mbeans.add(ex);
continue;
} catch (IOException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "IOException", ex);
mbeans.add(ex);
continue;
} catch (SecurityException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "SecurityException", ex);
mbeans.add(ex);
continue;
} catch (Exception ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "Exception", ex);
mbeans.add(ex);
continue;
} catch (Error ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "Error", ex);
mbeans.add(ex);
continue;
}
mbeans.add(objInst);
}
return mbeans;
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class ManagementFactoryHelper method unregisterMBean.
private static void unregisterMBean(MBeanServer mbs, String mbeanName) {
try {
final ObjectName objName = Util.newObjectName(mbeanName);
// inner class requires these fields to be final
final MBeanServer mbs0 = mbs;
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
public Void run() throws MBeanRegistrationException, RuntimeOperationsException {
try {
mbs0.unregisterMBean(objName);
} catch (InstanceNotFoundException e) {
// ignore exception if not found
}
return null;
}
});
} catch (PrivilegedActionException e) {
throw Util.newException(e.getException());
}
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class XSheet method displayMBeanOperationsNode.
// Call on EDT
private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
if (!uo.getType().equals(Type.OPERATIONS)) {
return;
}
mbean = (XMBean) uo.getData();
SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
@Override
public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
return mbean.getMBeanInfo();
}
@Override
protected void done() {
try {
MBeanInfo mbi = get();
if (mbi != null) {
if (!isSelectedNode(node, currentNode)) {
return;
}
mbeanOperations.loadOperations(mbean, mbi);
invalidate();
mainPanel.removeAll();
JPanel borderPanel = new JPanel(new BorderLayout());
borderPanel.setBorder(BorderFactory.createTitledBorder(Messages.OPERATION_INVOCATION));
borderPanel.add(new JScrollPane(mbeanOperations));
mainPanel.add(borderPanel, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
}
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Problem displaying MBean " + "operations for MBean [" + mbean.getObjectName() + "]");
t.printStackTrace();
}
showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
}
}
};
sw.execute();
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class DcmdMBeanPermissionsTest method main.
public static void main(final String[] args) {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName on = null;
try {
on = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
} catch (MalformedObjectNameException ex) {
ex.printStackTrace();
throw new RuntimeException("TEST FAILED");
}
MBeanInfo info = null;
try {
info = mbs.getMBeanInfo(on);
} catch (InstanceNotFoundException | IntrospectionException | ReflectionException ex) {
ex.printStackTrace();
throw new RuntimeException("TEST FAILED");
}
CustomSecurityManager sm = new CustomSecurityManager();
System.setSecurityManager(sm);
// Set of permission required to run the test cleanly
// Some permissions are required by the MBeanServer and other
// platform services (RuntimePermission("createClassLoader"),
// ReflectPermission("suppressAccessChecks"),
// java.util.logging.LoggingPermission("control"),
// RuntimePermission("exitVM.97")).
// Other permissions are required by commands being invoked
// in the test (for instance, RuntimePermission("modifyThreadGroup")
// and RuntimePermission("modifyThread") are checked when
// runFinalization() is invoked by the gcRunFinalization command.
sm.grantPermission(new RuntimePermission("createClassLoader"));
sm.grantPermission(new ReflectPermission("suppressAccessChecks"));
sm.grantPermission(new java.util.logging.LoggingPermission("control", ""));
sm.grantPermission(new java.lang.RuntimePermission("exitVM.97"));
sm.grantPermission(new java.lang.RuntimePermission("modifyThreadGroup"));
sm.grantPermission(new java.lang.RuntimePermission("modifyThread"));
for (MBeanOperationInfo opInfo : info.getOperations()) {
Permission opPermission = new MBeanPermission(info.getClassName(), opInfo.getName(), on, "invoke");
sm.grantPermission(opPermission);
testOperation(mbs, sm, on, opInfo);
sm.denyPermission(opPermission);
}
System.out.println("TEST PASSED");
}
Aggregations