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 ServerNotifForwarder method snoopOnUnregister.
// The standard RMI connector client will register a listener on the MBeanServerDelegate
// in order to be told when MBeans are unregistered. We snoop on fetched notifications
// so that we can know too, and remove the corresponding entry from the listenerMap.
// See 6957378.
private void snoopOnUnregister(NotificationResult nr) {
List<IdAndFilter> copy = null;
synchronized (listenerMap) {
Set<IdAndFilter> delegateSet = listenerMap.get(MBeanServerDelegate.DELEGATE_NAME);
if (delegateSet == null || delegateSet.isEmpty()) {
return;
}
copy = new ArrayList<>(delegateSet);
}
for (TargetedNotification tn : nr.getTargetedNotifications()) {
Integer id = tn.getListenerID();
for (IdAndFilter idaf : copy) {
if (idaf.id == id) {
// This is a notification from the MBeanServerDelegate.
Notification n = tn.getNotification();
if (n instanceof MBeanServerNotification && n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
MBeanServerNotification mbsn = (MBeanServerNotification) n;
ObjectName gone = mbsn.getMBeanName();
synchronized (listenerMap) {
listenerMap.remove(gone);
}
}
}
}
}
}
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 ResultLogManager method clearMemoryLog.
// Clear the memory log, sends a notification indicating that
// the memory log was cleared.
//
private void clearMemoryLog() throws IOException {
synchronized (this) {
memoryLog.clear();
memCapacityReached = false;
}
sendNotification(new Notification(MEMORY_LOG_CLEARED, objectName, getNextSeqNumber(), "memory log cleared"));
}
Aggregations