From 96feb82bda01fe613095d7d640f3ce1d985addda Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Mon, 14 Jul 2025 12:12:20 +0800 Subject: [PATCH 1/2] Fix issue when reconnecting after connected via REST --- .../plugin/visualvm/MockApplication.java | 48 +++++++++++++++++++ .../plugin/visualvm/VisualVMView.java | 18 +++++-- 2 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java new file mode 100644 index 00000000..c527d885 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.coherence.plugin.visualvm; + +import org.graalvm.visualvm.application.Application; +import org.graalvm.visualvm.host.Host; + +/** + * MockApplication is a class used to register a REST connection to fix + * issue when unregistering application.. + */ +public class MockApplication extends Application + { + // ---- constructors ---------------------------------------------------- + + /** + * Constructs a new MockApplication instance. + * + * @param host the host associated with this application + * @param id the unique identifier for this application + */ + public MockApplication(Host host, String id) + { + super(host, id); + } + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java index 1ddfd7d8..c198a9a1 100644 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,11 +58,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; @@ -83,6 +81,8 @@ import org.openide.util.RequestProcessor; import org.openide.util.Utilities; +import static org.graalvm.visualvm.host.Host.UNKNOWN_HOST; + /** * The implementation of the {@link DataSourceView} for displaying the Coherence @@ -167,6 +167,12 @@ protected DataViewComponent createComponent() addModelForApplication(m_application, model); } + if (m_application == null) + { + // this is called from REST, so create a dummy application, so the visual VM mode gets cleaned up + m_application = new MockApplication(UNKNOWN_HOST, String.valueOf(f_counter.incrementAndGet())); + } + boolean fClusterSnapshotEnabled = com.oracle.coherence.plugin.visualvm.GlobalPreferences .sharedInstance().isClusterSnapshotEnabled(); @@ -516,4 +522,6 @@ public static void addModelForApplication(Application application, VisualVMModel * Set of panels to refresh and update. */ private final Set f_setPanels = new LinkedHashSet<>(); + + private static final AtomicInteger f_counter = new AtomicInteger(0); } From 1a6a6f72000fd3af1043bc8a4fb02b6556e602f9 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Mon, 14 Jul 2025 12:40:46 +0800 Subject: [PATCH 2/2] Minor cleanup --- .../oracle/coherence/plugin/visualvm/MockApplication.java | 8 ++++---- .../oracle/coherence/plugin/visualvm/VisualVMView.java | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java index c527d885..6458389c 100644 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/MockApplication.java @@ -25,7 +25,8 @@ package com.oracle.coherence.plugin.visualvm; import org.graalvm.visualvm.application.Application; -import org.graalvm.visualvm.host.Host; + +import static org.graalvm.visualvm.host.Host.UNKNOWN_HOST; /** * MockApplication is a class used to register a REST connection to fix @@ -38,11 +39,10 @@ public class MockApplication extends Application /** * Constructs a new MockApplication instance. * - * @param host the host associated with this application * @param id the unique identifier for this application */ - public MockApplication(Host host, String id) + public MockApplication(String id) { - super(host, id); + super(UNKNOWN_HOST, id); } } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java index c198a9a1..fa385a47 100644 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java @@ -81,8 +81,6 @@ import org.openide.util.RequestProcessor; import org.openide.util.Utilities; -import static org.graalvm.visualvm.host.Host.UNKNOWN_HOST; - /** * The implementation of the {@link DataSourceView} for displaying the Coherence @@ -169,8 +167,8 @@ protected DataViewComponent createComponent() if (m_application == null) { - // this is called from REST, so create a dummy application, so the visual VM mode gets cleaned up - m_application = new MockApplication(UNKNOWN_HOST, String.valueOf(f_counter.incrementAndGet())); + // this is called from REST, so create a dummy application, so the visual VM Model gets cleaned up + m_application = new MockApplication(String.valueOf(f_counter.incrementAndGet())); } boolean fClusterSnapshotEnabled = com.oracle.coherence.plugin.visualvm.GlobalPreferences