Skip to content

Commit

Permalink
7198: Add websocket server that pushes data on selection updates
Browse files Browse the repository at this point in the history
Reviewed-by: hirt, aptmac
  • Loading branch information
cimi authored and thegreystone committed Nov 29, 2021
1 parent 4d1c087 commit ca20442
Show file tree
Hide file tree
Showing 19 changed files with 511 additions and 51 deletions.
59 changes: 47 additions & 12 deletions application/org.openjdk.jmc.feature.flightrecorder/feature.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
<!--
Copyright (c) 2018, 2021 Oracle and/or its affiliates. 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
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
Expand Down Expand Up @@ -114,7 +114,7 @@
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.openjdk.jmc.flightrecorder.serializers"
download-size="0"
Expand Down Expand Up @@ -150,6 +150,41 @@
version="0.0.0"
unpack="false"/>

<plugin
id="org.apache.aries.spifly.dynamic.bundle"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.eclipse.jetty.websocket.api"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.eclipse.jetty.websocket.servlet"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.eclipse.jetty.websocket.server"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.eclipse.jetty.websocket.javax.server"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.openjdk.jmc.flightrecorder.flameview"
download-size="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ Bundle-Version: 8.2.0.qualifier
Bundle-Vendor: Oracle Corporation
Bundle-Localization: plugin
Require-Bundle: org.openjdk.jmc.rjmx,
org.apache.aries.spifly.dynamic.bundle,
org.openjdk.jmc.common,
org.openjdk.jmc.flightrecorder;visibility:=reexport,
org.openjdk.jmc.ui;visibility:=reexport,
org.openjdk.jmc.flightrecorder.serializers,
org.openjdk.jmc.ui.celleditors,
org.openjdk.jmc.flightrecorder.rules,
org.openjdk.jmc.flightrecorder.rules.jdk,
org.openjdk.jmc.flightrecorder.configuration,
org.openjdk.jmc.commands,
org.openjdk.jmc.browser,
org.hdrhistogram.HdrHistogram
org.hdrhistogram.HdrHistogram,
org.eclipse.jetty.io,
org.eclipse.jetty.server,
org.eclipse.jetty.servlet,
org.eclipse.jetty.servlet-api,
org.eclipse.jetty.websocket.api,
org.eclipse.jetty.websocket.server,
org.eclipse.jetty.websocket.servlet,
org.eclipse.jetty.util
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.openjdk.jmc.flightrecorder.ui.FlightRecorderUI
Export-Package: org.openjdk.jmc.flightrecorder.ui,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. 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
Expand All @@ -10,17 +10,17 @@
*
* 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
Expand Down Expand Up @@ -143,6 +143,23 @@ public static IQuantity parseItemListSize(String size) {
}
}

public static int parseWebsocketPort(String port) {
try {
return Integer.parseInt(port);
} catch (NumberFormatException e) {
return PreferenceKeys.DEFAULT_WEBSOCKET_PORT;
}
}

public int getWebsocketPort() {
return parseWebsocketPort(getPreferenceStore().getString(PreferenceKeys.PROPERTY_WEBSOCKET_SERVER_PORT));
}

public boolean isWebsocketServerEnabled() {
int port = getWebsocketPort();
return port > 0 && port < 65535;
}

public static String validateDumpTimespan(String text) {
try {
IQuantity timespan = UnitLookup.TIMESPAN.parseInteractive(text);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. 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
Expand All @@ -10,17 +10,17 @@
*
* 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
Expand Down Expand Up @@ -83,6 +83,7 @@
import org.openjdk.jmc.flightrecorder.ui.preferences.PreferenceKeys;
import org.openjdk.jmc.flightrecorder.ui.selection.IFlavoredSelection;
import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStore;
import org.openjdk.jmc.flightrecorder.ui.websocket.WebsocketServer;
import org.openjdk.jmc.ui.MCPathEditorInput;
import org.openjdk.jmc.ui.idesupport.IDESupportUIToolkit;
import org.openjdk.jmc.ui.misc.CompositeToolkit;
Expand Down Expand Up @@ -112,6 +113,8 @@ public class JfrEditor extends EditorPart implements INavigationLocationProvider
private Reference<ResultPage> resultPageRef = new WeakReference<>(null);
private RuleManager ruleEngine;
private IPropertyChangeListener analysisEnabledListener;
private IPropertyChangeListener websocketServerEnabledListener;
private WebsocketServer websocketServer;

public JfrEditor() {
super();
Expand All @@ -123,7 +126,29 @@ public JfrEditor() {
}
}
};
if (FlightRecorderUI.getDefault().isWebsocketServerEnabled()) {
int websocketServerPort = FlightRecorderUI.getDefault().getWebsocketPort();
websocketServer = new WebsocketServer(websocketServerPort);
}
websocketServerEnabledListener = e -> {
if (e.getProperty().equals(PreferenceKeys.PROPERTY_WEBSOCKET_SERVER_PORT)) {
int newWebsocketServerPort = FlightRecorderUI.parseWebsocketPort((String) e.getNewValue());
if (newWebsocketServerPort > 0) {
if (websocketServer != null) {
websocketServer.shutdown();
websocketServer = null;
}
websocketServer = new WebsocketServer(newWebsocketServerPort);
} else {
if (websocketServer != null) {
websocketServer.shutdown();
websocketServer = null;
}
}
}
};
FlightRecorderUI.getDefault().getPreferenceStore().addPropertyChangeListener(analysisEnabledListener);
FlightRecorderUI.getDefault().getPreferenceStore().addPropertyChangeListener(websocketServerEnabledListener);
}

@Override
Expand Down Expand Up @@ -185,6 +210,9 @@ public void showSelection(IItemCollection items) {
if (!items.hasItems() && currentPage != null) {
selectionItems = getModel().getItems().apply(getDisplayablePage(currentPage).getDefaultSelectionFilter());
}
if (websocketServer != null) {
websocketServer.notifyAll(selectionItems);
}
getSite().getSelectionProvider().setSelection(new StructuredSelection(selectionItems));
}

Expand Down Expand Up @@ -397,6 +425,7 @@ public RuleManager getRuleManager() {
public void dispose() {
ruleEngine.dispose();
FlightRecorderUI.getDefault().getPreferenceStore().removePropertyChangeListener(analysisEnabledListener);
FlightRecorderUI.getDefault().getPreferenceStore().removePropertyChangeListener(websocketServerEnabledListener);
super.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018, 2021 Oracle and/or its affiliates. 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
Expand All @@ -10,17 +10,17 @@
*
* 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
Expand Down Expand Up @@ -453,6 +453,9 @@ public class Messages extends NLS {
public static String PREFERENCES_REMOVE_FINISHED_RECORDING_TEXT;
public static String PREFERENCES_RULES_CONFIGURE_SELECTED;
public static String PREFERENCES_SHOW_MONITORING_WARNING_TEXT;
public static String PREFERENCES_WEBSOCKET_SERVER_PORT_INVALID;
public static String PREFERENCES_WEBSOCKET_SERVER_PORT_TEXT;
public static String PREFERENCES_WEBSOCKET_SERVER_PORT_TOOLTIP;
public static String ProcessesPage_AGGR_CONCURRENT_PROCESSES;
public static String ProcessesPage_AGGR_CONCURRENT_PROCESSES_DESC;
public static String ProcessesPage_AGGR_FIRST_SAMPLE;
Expand Down
Loading

0 comments on commit ca20442

Please sign in to comment.