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 0000000..6458389 --- /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 static org.graalvm.visualvm.host.Host.UNKNOWN_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 id the unique identifier for this application + */ + public MockApplication(String 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 1ddfd7d..fa385a4 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; @@ -167,6 +165,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 Model gets cleaned up + m_application = new MockApplication(String.valueOf(f_counter.incrementAndGet())); + } + boolean fClusterSnapshotEnabled = com.oracle.coherence.plugin.visualvm.GlobalPreferences .sharedInstance().isClusterSnapshotEnabled(); @@ -516,4 +520,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); }