Skip to content

Commit 815e194

Browse files
committed
Heartbeat can be explicitly disabled for a JMX connection
1 parent f57a750 commit 815e194

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

visualvm/jmx/src/org/graalvm/visualvm/jmx/impl/JmxApplicationProvider.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class JmxApplicationProvider {
108108
CURRENT_SNAPSHOT_VERSION_MINOR;
109109

110110
public static final String PROPERTY_RETRY_WITHOUT_SSL = "prop_retry_without_ssl"; // NOI18N
111+
static final String PROPERTY_DISABLE_HEARTBEAT = "prop_disable_heartbeat"; // NOI18N
111112
private static final String PROPERTY_CONNECTION_STRING = "prop_conn_string"; // NOI18N
112113
private static final String PROPERTY_HOSTNAME = "prop_conn_hostname"; // NOI18N
113114
private static final String PROPERTY_ENV_PROVIDER_ID = "prop_env_provider_id"; // NOI18N
@@ -384,8 +385,7 @@ private void scheduleHeartbeatImpl(boolean immediately) {
384385
unavailableApps.clear();
385386
}
386387

387-
Iterator<JmxApplication> appsI = apps.iterator();
388-
while (appsI.hasNext()) if (appsI.next().isRemoved()) appsI.remove();
388+
cleanupUnavailableApps(apps);
389389
if (apps.isEmpty()) {
390390
heartbeatRunning = false;
391391
if (anotherHeartbeatPending) { // just a safe fallback, likely not needed at all
@@ -443,8 +443,7 @@ public void propertyChange(PropertyChangeEvent evt) {
443443
boolean pendingApps;
444444

445445
synchronized (unavailableApps) {
446-
Iterator<JmxApplication> appsI = unavailableApps.iterator();
447-
while (appsI.hasNext()) if (appsI.next().isRemoved()) appsI.remove();
446+
cleanupUnavailableApps(unavailableApps);
448447
pendingApps = !unavailableApps.isEmpty();
449448
heartbeatRunning = false;
450449
}
@@ -461,6 +460,16 @@ public void propertyChange(PropertyChangeEvent evt) {
461460
}
462461

463462

463+
private void cleanupUnavailableApps(Set<JmxApplication> apps) {
464+
String trueS = Boolean.TRUE.toString();
465+
Iterator<JmxApplication> appsI = apps.iterator();
466+
while (appsI.hasNext()) {
467+
JmxApplication app = appsI.next();
468+
if (app.isRemoved() || trueS.equals(app.getStorage().getCustomProperty(PROPERTY_DISABLE_HEARTBEAT)))
469+
appsI.remove();
470+
}
471+
}
472+
464473

465474
private void cleanupCreatedHost(Set<Host> hosts, Host host) {
466475
// NOTE: this is not absolutely failsafe, if resolving the JMX application

visualvm/jmx/src/org/graalvm/visualvm/jmx/impl/ProxyClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ void connect() {
214214
CredentialsConfigurator supplyCredentials() {
215215
String displayName = app.getStorage().getCustomProperty(DataSourceDescriptor.PROPERTY_NAME);
216216
if (displayName == null) displayName = getUrl().toString();
217-
CredentialsConfigurator jsc =
218-
CredentialsConfigurator.supplyCredentials(displayName);
219-
if (jsc != null)
220-
setCredentials(jsc.getUsername(), jsc.getPassword());
217+
CredentialsConfigurator jsc = CredentialsConfigurator.supplyCredentials(displayName);
218+
if (jsc != null) setCredentials(jsc.getUsername(), jsc.getPassword());
219+
else app.getStorage().setCustomProperty(JmxApplicationProvider.PROPERTY_DISABLE_HEARTBEAT, Boolean.TRUE.toString());
221220
return jsc;
222221
}
223222

0 commit comments

Comments
 (0)