use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class GarbageCollectorImpl method createGCNotification.
void createGCNotification(long timestamp, String gcName, String gcAction, String gcCause, GcInfo gcInfo) {
if (!hasListeners()) {
return;
}
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION, getObjectName(), getNextSeqNumber(), timestamp, gcName);
GarbageCollectionNotificationInfo info = new GarbageCollectionNotificationInfo(gcName, gcAction, gcCause, gcInfo);
CompositeData cd = GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
sendNotification(notif);
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class MemoryImpl method createNotification.
static void createNotification(String notifType, String poolName, MemoryUsage usage, long count) {
MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
if (!mbean.hasListeners()) {
// if no listener is registered.
return;
}
long timestamp = System.currentTimeMillis();
String msg = getNotifMsg(notifType);
Notification notif = new Notification(notifType, mbean.getObjectName(), getNextSeqNumber(), timestamp, msg);
MemoryNotificationInfo info = new MemoryNotificationInfo(poolName, usage, count);
CompositeData cd = MemoryNotifInfoCompositeData.toCompositeData(info);
notif.setUserData(cd);
mbean.sendNotification(notif);
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class RMIConnector method connect.
/**
* @throws IOException if the connection could not be made because of a
* communication problem, or in the case of the {@code iiop} protocol,
* that RMI/IIOP is not supported
*/
public synchronized void connect(Map<String, ?> environment) throws IOException {
final boolean tracing = logger.traceOn();
String idstr = (tracing ? "[" + this.toString() + "]" : null);
if (terminated) {
logger.trace("connect", idstr + " already closed.");
throw new IOException("Connector closed");
}
if (connected) {
logger.trace("connect", idstr + " already connected.");
return;
}
try {
if (tracing)
logger.trace("connect", idstr + " connecting...");
final Map<String, Object> usemap = new HashMap<String, Object>((this.env == null) ? Collections.<String, Object>emptyMap() : this.env);
if (environment != null) {
EnvHelp.checkAttributes(environment);
usemap.putAll(environment);
}
// Get RMIServer stub from directory or URL encoding if needed.
if (tracing)
logger.trace("connect", idstr + " finding stub...");
RMIServer stub = (rmiServer != null) ? rmiServer : findRMIServer(jmxServiceURL, usemap);
// Check for secure RMIServer stub if the corresponding
// client-side environment property is set to "true".
//
String stringBoolean = (String) usemap.get("jmx.remote.x.check.stub");
boolean checkStub = EnvHelp.computeBooleanFromString(stringBoolean);
if (checkStub)
checkStub(stub, rmiServerImplStubClass);
// Connect IIOP Stub if needed.
if (tracing)
logger.trace("connect", idstr + " connecting stub...");
stub = connectStub(stub, usemap);
idstr = (tracing ? "[" + this.toString() + "]" : null);
// Calling newClient on the RMIServer stub.
if (tracing)
logger.trace("connect", idstr + " getting connection...");
Object credentials = usemap.get(CREDENTIALS);
try {
connection = getConnection(stub, credentials, checkStub);
} catch (java.rmi.RemoteException re) {
if (jmxServiceURL != null) {
final String pro = jmxServiceURL.getProtocol();
final String path = jmxServiceURL.getURLPath();
if ("rmi".equals(pro) && path.startsWith("/jndi/iiop:")) {
MalformedURLException mfe = new MalformedURLException("Protocol is rmi but JNDI scheme is iiop: " + jmxServiceURL);
mfe.initCause(re);
throw mfe;
}
}
throw re;
}
// or contextClassLoader at connect time.
if (tracing)
logger.trace("connect", idstr + " getting class loader...");
defaultClassLoader = EnvHelp.resolveClientClassLoader(usemap);
usemap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, defaultClassLoader);
rmiNotifClient = new RMINotifClient(defaultClassLoader, usemap);
env = usemap;
final long checkPeriod = EnvHelp.getConnectionCheckPeriod(usemap);
communicatorAdmin = new RMIClientCommunicatorAdmin(checkPeriod);
connected = true;
// The connectionId variable is used in doStart(), when
// reconnecting, to identify the "old" connection.
//
connectionId = getConnectionId();
Notification connectedNotif = new JMXConnectionNotification(JMXConnectionNotification.OPENED, this, connectionId, clientNotifSeqNo++, "Successful connection", null);
sendNotification(connectedNotif);
if (tracing)
logger.trace("connect", idstr + " done...");
} catch (IOException e) {
if (tracing)
logger.trace("connect", idstr + " failed to connect: " + e);
throw e;
} catch (RuntimeException e) {
if (tracing)
logger.trace("connect", idstr + " failed to connect: " + e);
throw e;
} catch (NamingException e) {
final String msg = "Failed to retrieve RMIServer stub: " + e;
if (tracing)
logger.trace("connect", idstr + " " + msg);
throw EnvHelp.initCause(new IOException(msg), e);
}
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class RequiredModelMBean method sendNotification.
public void sendNotification(String ntfyText) throws MBeanException, RuntimeOperationsException {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(String)", "Entry");
}
if (ntfyText == null)
throw new RuntimeOperationsException(new IllegalArgumentException("notification message must not " + "be null"), "Exception occurred trying to send a text notification " + "from a ModelMBean");
Notification myNtfyObj = new Notification("jmx.modelmbean.generic", this, 1, ntfyText);
sendNotification(myNtfyObj);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(String)", "Notification sent");
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(String)", "Exit");
}
}
use of javax.management.Notification in project jdk8u_jdk by JetBrains.
the class OldMBeanServerTest method testBasic.
private static void testBasic() throws Exception {
CountListener countListener = new CountListener();
mbsc.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, countListener, null, null);
assert countListener.count == 0;
ObjectName name = new ObjectName("a:b=c");
if (mbsc instanceof MBeanServer)
((MBeanServer) mbsc).registerMBean(new Boring(), name);
else
mbsc.createMBean(Boring.class.getName(), name);
countListener.waitForCount(1);
assert mbsc.isRegistered(name);
assert mbsc.queryNames(null, null).contains(name);
assert mbsc.getAttribute(name, "Name").equals("Jessica");
assert mbsc.invoke(name, "add", new Object[] { 2, 3 }, new String[] { "int", "int" }).equals(5);
mbsc.unregisterMBean(name);
countListener.waitForCount(2);
assert !mbsc.isRegistered(name);
assert !mbsc.queryNames(null, null).contains(name);
mbsc.createMBean(BoringNotifier.class.getName(), name);
countListener.waitForCount(3);
CountListener boringListener = new CountListener();
class AlwaysNotificationFilter implements NotificationFilter {
public boolean isNotificationEnabled(Notification notification) {
return true;
}
}
mbsc.addNotificationListener(name, boringListener, new AlwaysNotificationFilter(), 5);
mbsc.invoke(name, "send", null, null);
boringListener.waitForCount(5);
}
Aggregations