Skip to content

Commit

Permalink
JMC-7455: Add plugin with support for Jolokia connections
Browse files Browse the repository at this point in the history
  • Loading branch information
skarsaune committed Jan 25, 2024
1 parent ff734b6 commit d477ccf
Show file tree
Hide file tree
Showing 34 changed files with 1,686 additions and 0 deletions.
7 changes: 7 additions & 0 deletions application/org.openjdk.jmc.feature.core/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,11 @@
version="0.0.0"
unpack="false"/>

<plugin
id="org.openjdk.jmc.jolokia"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
17 changes: 17 additions & 0 deletions application/org.openjdk.jmc.jolokia/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<!-- Convenience: Regarding access rules. It appears that these packages are exported from jolokia standalone. Wondering whether eclipse caps at 36 access rules or something. Setting access rules on that specific plugin dependency does not seem to be persisted to the .classpath file, hence setting access policy globally for all plugin dependencies-->
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="org/jolokia/**"/>
<accessrule kind="accessible" pattern="org/json/simple/*"/>
</accessrules>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
20 changes: 20 additions & 0 deletions application/org.openjdk.jmc.jolokia/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.openjdk.jmc.jolokia;singleton:=true
Bundle-Version: 9.0.0.qualifier
Automatic-Module-Name: org.openjdk.jmc.jolokia
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui,
org.jolokia.jmx-adapter.standalone;bundle-version="1.7.2";visibility:=reexport,
org.jolokia.jvm;bundle-version="1.7.2",
org.openjdk.jmc.common,
org.openjdk.jmc.rjmx,
org.openjdk.jmc.ui
Export-Package: org.openjdk.jmc.jolokia,
org.openjdk.jmc.jolokia.preferences
Import-Package: org.jolokia.converter,
org.json.simple
Bundle-Activator: org.openjdk.jmc.jolokia.JmcJolokiaPlugin
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Properties file for org.openjdk.jmc.jolokia
page.name = Jolokia
Bundle-Name = Jolokia JMC Connection
39 changes: 39 additions & 0 deletions application/org.openjdk.jmc.jolokia/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2024, Kantega AS. All rights reserved.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The contents of this file are subject to the terms of either the Universal Permissive License
# v 1.0 as shown at http://oss.oracle.com/licenses/upl
#
# or the following license:
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
# endorse or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
source.. = src/main/java/
output.. = target/classes/
bin.includes = META-INF/,\
OSGI-INF/,\
.,\
plugin.xml,\
OSGI-INF/l10n/bundle.properties
65 changes: 65 additions & 0 deletions application/org.openjdk.jmc.jolokia/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2024, Kantega AS. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
The contents of this file are subject to the terms of either the Universal Permissive License
v 1.0 as shown at http://oss.oracle.com/licenses/upl
or the following license:
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided with
the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.openjdk.jmc.rjmx.descriptorProvider">
<provider
class="org.openjdk.jmc.jolokia.JolokiaDiscoveryListener">
</provider>
</extension>
<extension
point="org.openjdk.jmc.rjmx.jmxProtocols">
<client
class="org.openjdk.jmc.jolokia.JmcJolokiaJmxConnectionProvider" protocol="jolokia">
<sysproperty name="running.in.jmc" include="true" />
</client>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.openjdk.jmc.browser.preferences.BrowserPreferencePage"
class="org.openjdk.jmc.jolokia.preferences.JolokiaPreferencePage"
id="org.openjdk.jmc.jolokia.preferences.JolokiaPreferencePage"
name="%page.name">
</page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.openjdk.jmc.jolokia.preferences.PreferenceInitializer">
</initializer>
</extension>
</plugin>
49 changes: 49 additions & 0 deletions application/org.openjdk.jmc.jolokia/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2024, Kantega AS. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
The contents of this file are subject to the terms of either the Universal Permissive License
v 1.0 as shown at http://oss.oracle.com/licenses/upl
or the following license:
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided with
the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openjdk.jmc</groupId>
<artifactId>missioncontrol.application</artifactId>
<version>${revision}${changelist}</version>
</parent>
<artifactId>org.openjdk.jmc.jolokia</artifactId>
<packaging>eclipse-plugin</packaging>
<properties>
<jmc.config.path>${project.basedir}/../../configuration</jmc.config.path>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, Kantega AS. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The contents of this file are subject to the terms of either the Universal Permissive License
* v 1.0 as shown at http://oss.oracle.com/licenses/upl
*
* or the following license:
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.openjdk.jmc.jolokia;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.openjdk.jmc.rjmx.descriptorprovider.AbstractDescriptorProvider;
import org.openjdk.jmc.rjmx.descriptorprovider.IDescriptorListener;

/**
* The {@code AbstractCachedDescriptorProvider} keeps a list of identified JVMs that can be
* refreshed in the background by some means of discovering JVMs. Listeners will be notified of any
* changes.
*/
@SuppressWarnings("restriction")
public abstract class AbstractCachedDescriptorProvider extends AbstractDescriptorProvider {

private static final long LOCAL_REFRESH_INTERVAL = 20000;
private Scanner scanner;
private Thread scannerThread;
/**
* Map<UUID, IServerDescriptor>
*/
private final Map<String, ServerConnectionDescriptor> knownDescriptors = new HashMap<>();

/**
* This is where we periodically scan and report deltas to the listeners.
*/
private class Scanner implements Runnable {
boolean isRunning;

@Override
public void run() {
isRunning = true;
while (isRunning) {
try {
scan();
Thread.sleep(LOCAL_REFRESH_INTERVAL);
} catch (InterruptedException ignore) {
// Don't mind being interrupted.
}
}
}

/**
* Marks this scanner as terminated.
*/
public void shutdown() {
isRunning = false;
}

protected void scan() {
Map<String, ServerConnectionDescriptor> newOnes = discoverJvms();

synchronized (knownDescriptors) {
// Remove stale ones...
for (Iterator<Entry<String, ServerConnectionDescriptor>> entryIterator = knownDescriptors.entrySet()
.iterator(); entryIterator.hasNext();) {
Entry<String, ServerConnectionDescriptor> entry = entryIterator.next();
if (newOnes.containsKey(entry.getKey())) {
continue;
}
entryIterator.remove();
onDescriptorRemoved(entry.getKey());
}

// Add new ones...
for (Entry<String, ServerConnectionDescriptor> entry : newOnes.entrySet()) {
if (knownDescriptors.containsKey(entry.getKey())) {
continue;
}
onDescriptorDetected(entry.getValue(), entry.getValue().getPath(), entry.getValue().serviceUrl(),
entry.getValue());
}
knownDescriptors.clear();
knownDescriptors.putAll(newOnes);
}
}
}

/**
* Sets up the thread.
*/
private void initialize() {

scanner = new Scanner();
scannerThread = new Thread(scanner, getName()); // $NON-NLS-1$
scannerThread.start();
}

protected abstract boolean isEnabled();

protected abstract Map<String, ServerConnectionDescriptor> discoverJvms();

@Override
public void addDescriptorListener(IDescriptorListener l) {
synchronized (m_descriptorListeners) {
if (m_descriptorListeners.size() == 0) {
super.addDescriptorListener(l);
initialize();
} else {
super.addDescriptorListener(l);
}
}
}

@Override
public void removeDescriptorListener(IDescriptorListener l) {
synchronized (m_descriptorListeners) {
super.removeDescriptorListener(l);
if (m_descriptorListeners.size() == 0 && scanner != null) {
scanner.shutdown();
scannerThread.interrupt();
}
}
}

/**
* Shuts down the scanner thread.
*/
public void shutdown() {
if (scanner != null) {
scanner.shutdown();
}
}

}
Loading

0 comments on commit d477ccf

Please sign in to comment.