Skip to content

Commit 2e25d93

Browse files
committed
8476: Websocket server is tied to JfrEditor
1 parent 2c9ad54 commit 2e25d93

22 files changed

Lines changed: 637 additions & 178 deletions

File tree

‎application/coverage/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@
267267
<artifactId>org.openjdk.jmc.ui.celleditors</artifactId>
268268
<version>${project.version}</version>
269269
</dependency>
270+
<dependency>
271+
<groupId>org.openjdk.jmc</groupId>
272+
<artifactId>org.openjdk.jmc.ui.websocket</artifactId>
273+
<version>${project.version}</version>
274+
</dependency>
270275
<dependency>
271276
<groupId>org.openjdk.jmc</groupId>
272277
<artifactId>org.openjdk.jmc.ui.common</artifactId>

‎application/org.openjdk.jmc.feature.core/feature.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@
166166
version="0.0.0"
167167
unpack="false"/>
168168

169+
<plugin
170+
id="org.openjdk.jmc.ui.websocket"
171+
download-size="0"
172+
install-size="0"
173+
version="0.0.0"
174+
unpack="false"/>
175+
169176
<plugin
170177
id="org.openjdk.jmc.rjmx.common"
171178
download-size="0"

‎application/org.openjdk.jmc.flightrecorder.ui/META-INF/MANIFEST.MF‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Require-Bundle: org.openjdk.jmc.rjmx,
1818
org.openjdk.jmc.flightrecorder.configuration,
1919
org.openjdk.jmc.commands,
2020
org.openjdk.jmc.browser,
21+
org.openjdk.jmc.ui.websocket,
2122
org.hdrhistogram.HdrHistogram,
2223
org.eclipse.jetty.io,
2324
org.eclipse.jetty.websocket.server,

‎application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/FlightRecorderUI.java‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,6 @@ public static IQuantity parseItemListSize(String size) {
143143
}
144144
}
145145

146-
public static int parseWebsocketPort(String port) {
147-
try {
148-
return Integer.parseInt(port);
149-
} catch (NumberFormatException e) {
150-
return PreferenceKeys.DEFAULT_WEBSOCKET_PORT;
151-
}
152-
}
153-
154-
public int getWebsocketPort() {
155-
return parseWebsocketPort(getPreferenceStore().getString(PreferenceKeys.PROPERTY_WEBSOCKET_SERVER_PORT));
156-
}
157-
158-
public boolean isWebsocketServerEnabled() {
159-
int port = getWebsocketPort();
160-
return port > 0 && port < 65535;
161-
}
162-
163146
public static String validateDumpTimespan(String text) {
164147
try {
165148
IQuantity timespan = UnitLookup.TIMESPAN.parseInteractive(text);

‎application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/JfrEditor.java‎

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@
8383
import org.openjdk.jmc.flightrecorder.ui.preferences.PreferenceKeys;
8484
import org.openjdk.jmc.flightrecorder.ui.selection.IFlavoredSelection;
8585
import org.openjdk.jmc.flightrecorder.ui.selection.SelectionStore;
86-
import org.openjdk.jmc.flightrecorder.ui.websocket.WebsocketServer;
8786
import org.openjdk.jmc.ui.MCPathEditorInput;
8887
import org.openjdk.jmc.ui.idesupport.IDESupportUIToolkit;
8988
import org.openjdk.jmc.ui.misc.CompositeToolkit;
9089
import org.openjdk.jmc.ui.misc.DialogToolkit;
9190
import org.openjdk.jmc.ui.misc.DisplayToolkit;
9291
import org.openjdk.jmc.ui.misc.SelectionProvider;
92+
import org.openjdk.jmc.ui.websocket.WebsocketPlugin;
9393

9494
public class JfrEditor extends EditorPart implements INavigationLocationProvider, IPageContainer {
9595

@@ -113,8 +113,6 @@ public class JfrEditor extends EditorPart implements INavigationLocationProvider
113113
private Reference<ResultPage> resultPageRef = new WeakReference<>(null);
114114
private RuleManager ruleEngine;
115115
private IPropertyChangeListener analysisEnabledListener;
116-
private IPropertyChangeListener websocketServerEnabledListener;
117-
private WebsocketServer websocketServer;
118116

119117
public JfrEditor() {
120118
super();
@@ -126,29 +124,7 @@ public JfrEditor() {
126124
}
127125
}
128126
};
129-
if (FlightRecorderUI.getDefault().isWebsocketServerEnabled()) {
130-
int websocketServerPort = FlightRecorderUI.getDefault().getWebsocketPort();
131-
websocketServer = new WebsocketServer(websocketServerPort);
132-
}
133-
websocketServerEnabledListener = e -> {
134-
if (e.getProperty().equals(PreferenceKeys.PROPERTY_WEBSOCKET_SERVER_PORT)) {
135-
int newWebsocketServerPort = FlightRecorderUI.parseWebsocketPort((String) e.getNewValue());
136-
if (newWebsocketServerPort > 0) {
137-
if (websocketServer != null) {
138-
websocketServer.shutdown();
139-
websocketServer = null;
140-
}
141-
websocketServer = new WebsocketServer(newWebsocketServerPort);
142-
} else {
143-
if (websocketServer != null) {
144-
websocketServer.shutdown();
145-
websocketServer = null;
146-
}
147-
}
148-
}
149-
};
150127
FlightRecorderUI.getDefault().getPreferenceStore().addPropertyChangeListener(analysisEnabledListener);
151-
FlightRecorderUI.getDefault().getPreferenceStore().addPropertyChangeListener(websocketServerEnabledListener);
152128
}
153129

154130
@Override
@@ -214,8 +190,8 @@ public void showSelection(IItemCollection items) {
214190
if (!items.hasItems() && currentPage != null) {
215191
selectionItems = getModel().getItems().apply(getDisplayablePage(currentPage).getDefaultSelectionFilter());
216192
}
217-
if (websocketServer != null) {
218-
websocketServer.notifyAll(selectionItems);
193+
if (WebsocketPlugin.getDefault().getServerEnabled() == true) {
194+
WebsocketPlugin.getDefault().notifyAll(selectionItems);
219195
}
220196
getSite().getSelectionProvider().setSelection(new StructuredSelection(selectionItems));
221197
}
@@ -429,7 +405,6 @@ public RuleManager getRuleManager() {
429405
public void dispose() {
430406
ruleEngine.dispose();
431407
FlightRecorderUI.getDefault().getPreferenceStore().removePropertyChangeListener(analysisEnabledListener);
432-
FlightRecorderUI.getDefault().getPreferenceStore().removePropertyChangeListener(websocketServerEnabledListener);
433408
super.dispose();
434409
}
435410

‎application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/messages/internal/Messages.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,6 @@ public class Messages extends NLS {
470470
public static String PREFERENCES_RULES_CONFIGURE_SELECTED;
471471
public static String PREFERENCES_SHOW_MONITORING_WARNING_TEXT;
472472
public static String PREFERENCES_STACKTRACE_SHOW_HIDDEN_FRAMES;
473-
public static String PREFERENCES_WEBSOCKET_SERVER_PORT_INVALID;
474-
public static String PREFERENCES_WEBSOCKET_SERVER_PORT_TEXT;
475-
public static String PREFERENCES_WEBSOCKET_SERVER_PORT_TOOLTIP;
476473
public static String ProcessesPage_AGGR_CONCURRENT_PROCESSES;
477474
public static String ProcessesPage_AGGR_CONCURRENT_PROCESSES_DESC;
478475
public static String ProcessesPage_AGGR_FIRST_SAMPLE;

‎application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/preferences/GeneralPage.java‎

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public void setToDefault() {
9393
private Text itemListValue;
9494
private Text propertiesArrayStringSizeValue;
9595
private Text editorRuleEvaluationThreadsValue;
96-
private Text websocketPortValue;
9796

9897
@Override
9998
protected Control createContents(Composite parent) {
@@ -172,21 +171,12 @@ protected Control createContents(Composite parent) {
172171
editorRuleEvaluationThreadsValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
173172
QuantityKindProposal.install(editorRuleEvaluationThreadsValue, UnitLookup.NUMBER);
174173

175-
Label websocketPortLabel = new Label(defaultTimespanContainer, SWT.NONE);
176-
websocketPortLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
177-
websocketPortLabel.setText(Messages.PREFERENCES_WEBSOCKET_SERVER_PORT_TEXT);
178-
websocketPortLabel.setToolTipText(Messages.PREFERENCES_WEBSOCKET_SERVER_PORT_TOOLTIP);
179-
websocketPortValue = new Text(defaultTimespanContainer, SWT.BORDER);
180-
websocketPortValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
181-
QuantityKindProposal.install(websocketPortValue, UnitLookup.NUMBER);
182-
183174
loadDumpTypeFromPrefStore(false);
184175
loadTimespanFromPrefStore(false);
185176
loadSelectionStoreSizeFromPrefStore(false);
186177
loadItemListSizeFromPrefStore(false);
187178
loadPropertiesArrayStringSizeFromPrefStore(false);
188179
loadEditorRuleEvaluationThreadsFromPrefStore(false);
189-
loadWebsocketPortFromPrefStore(false);
190180
timespanValue.addModifyListener(new ModifyListener() {
191181
@Override
192182
public void modifyText(ModifyEvent e) {
@@ -217,12 +207,6 @@ public void modifyText(ModifyEvent e) {
217207
validatePage();
218208
}
219209
});
220-
websocketPortValue.addModifyListener(new ModifyListener() {
221-
@Override
222-
public void modifyText(ModifyEvent e) {
223-
validatePage();
224-
}
225-
});
226210

227211
return container;
228212
}
@@ -243,23 +227,7 @@ private void validatePage() {
243227
if (error == null && error2 == null && error3 == null) {
244228
setErrorMessage(error4);
245229
}
246-
String error5 = validateWebsocketPort(websocketPortValue.getText());
247-
if (error == null && error2 == null && error3 == null) {
248-
setErrorMessage(error5);
249-
}
250-
setValid(error == null && error2 == null && error3 == null && error4 == null && error5 == null);
251-
}
252-
253-
public static String validateWebsocketPort(String text) {
254-
try {
255-
int port = Integer.parseInt(text);
256-
if (port < 0 || port > 65535) {
257-
return Messages.PREFERENCES_WEBSOCKET_SERVER_PORT_INVALID;
258-
}
259-
} catch (NumberFormatException e) {
260-
return Messages.PREFERENCES_WEBSOCKET_SERVER_PORT_INVALID;
261-
}
262-
return null;
230+
setValid(error == null && error2 == null && error3 == null && error4 == null);
263231
}
264232

265233
public static String validateNumEvaluationThreads(String text) {
@@ -339,52 +307,6 @@ private void loadEditorRuleEvaluationThreadsFromPrefStore(boolean loadDefault) {
339307
editorRuleEvaluationThreadsValue.setText(FlightRecorderUI.parseItemListSize(size).interactiveFormat());
340308
}
341309

342-
private void loadWebsocketPortFromPrefStore(boolean loadDefault) {
343-
String port = loadDefault ? getPreferenceStore().getDefaultString(PreferenceKeys.PROPERTY_WEBSOCKET_SERVER_PORT)
344-
: getPreferenceStore().getString(PreferenceKeys.PROPERTY_WEBSOCKET_SERVER_PORT);
345-
websocketPortValue.setText(Integer.toString(FlightRecorderUI.parseWebsocketPort(port)));
346-
}
347-
348-
// private Button createClearButton(Composite parent) {
349-
// Button button = new Button(parent, SWT.NONE);
350-
// button.setText(Messages.PREFERENCES_CLEAR_USER_SETTINGS_TEXT);
351-
// button.addSelectionListener(new SelectionAdapter() {
352-
// @Override
353-
// public void widgetSelected(SelectionEvent e) {
354-
// if (ensureAllEditorsClosed()) {
355-
// showConfirmUserSettingReset();
356-
// }
357-
// }
358-
// });
359-
// return button;
360-
// }
361-
//
362-
// private boolean ensureAllEditorsClosed() {
363-
// for (IEditorReference ref : m_workbench.getActiveWorkbenchWindow().getActivePage().getEditorReferences()) {
364-
// if (JfrEditor.EDITOR_ID.equals(ref.getId())) {
365-
// showMustCloseEditor();
366-
// return false;
367-
// }
368-
// }
369-
// return true;
370-
// }
371-
//
372-
// private void showMustCloseEditor() {
373-
// MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION);
374-
// messageBox.setMessage(Messages.PREFERENCES_OPEN_FLIGHT_RECORDING_DIALOG_TEXT);
375-
// messageBox.setText(Messages.PREFERENCES_OPEN_FLIGHT_RECORDING_DIALOG_TITLE);
376-
// messageBox.open();
377-
// }
378-
//
379-
// private void showConfirmUserSettingReset() {
380-
// MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
381-
// messageBox.setMessage(Messages.PREFERENCES_RESET_USER_SETTINGS_DIALOG_TEXT);
382-
// messageBox.setText(Messages.PREFERENCES_RESET_USER_SETTINGS_DIALOG_TITLE);
383-
// if (messageBox.open() == SWT.YES) {
384-
// ComponentsPlugin.getDefault().getUserInterfaceRepository().clearUserSettings(JfrEditor.EDITOR_ID);
385-
// }
386-
// }
387-
388310
private Button createRemoveRecordingsCheckBox(Composite parent) {
389311
return createCheckBox(parent, Messages.PREFERENCES_REMOVE_FINISHED_RECORDING_TEXT,
390312
PreferenceKeys.PROPERTY_REMOVE_FINISHED_RECORDING);
@@ -431,7 +353,6 @@ protected void performDefaults() {
431353
loadItemListSizeFromPrefStore(true);
432354
loadPropertiesArrayStringSizeFromPrefStore(true);
433355
loadEditorRuleEvaluationThreadsFromPrefStore(true);
434-
loadWebsocketPortFromPrefStore(true);
435356
super.performDefaults();
436357
}
437358

@@ -483,13 +404,6 @@ public boolean performOk() {
483404
setErrorMessage(qce.getLocalizedMessage());
484405
return false;
485406
}
486-
try {
487-
int port = Integer.parseInt(websocketPortValue.getText());
488-
getPreferenceStore().setValue(PreferenceKeys.PROPERTY_WEBSOCKET_SERVER_PORT, Integer.toString(port));
489-
} catch (NumberFormatException e) {
490-
setErrorMessage(Messages.PREFERENCES_WEBSOCKET_SERVER_PORT_INVALID);
491-
return false;
492-
}
493407

494408
setErrorMessage(null);
495409
if (timespanRadio.getSelection()) {

‎application/org.openjdk.jmc.flightrecorder.ui/src/main/resources/org/openjdk/jmc/flightrecorder/ui/messages/internal/messages.properties‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,6 @@ NAVIGATOR_ZOOM_OUT_TEXT=Zoom Out
405405

406406
PREFERENCES_CONFIRM_REMOVE_TEMPLATE_TEXT=Ask for confirmation before removing flight recording templates
407407
PREFERENCES_ENABLE_RECORDING_ANALYSIS=Enable flight recording analysis
408-
PREFERENCES_WEBSOCKET_SERVER_PORT_TEXT=Websocket server port (set to 0 to disable)
409-
PREFERENCES_WEBSOCKET_SERVER_PORT_TOOLTIP=Start a websocket server bound to 127.0.0.1 and the selected port. The server pushes updates whenever the selection changes in the UI.
410408
PREFERENCES_INCLUDE_EXPERIMENTAL_EVENTS_AND_FIELDS=Include experimental events and fields when reading flight recording files
411409
PREFERENCES_ALLOW_INCOMPLETE_RECORDING_FILE=Enable reading of incomplete flight recording files
412410
PREFERENCES_STACKTRACE_SHOW_HIDDEN_FRAMES=Show hidden frames in stacktraces
@@ -417,7 +415,6 @@ PREFERENCES_ENABLED_RULES=Enabled Rules
417415
PREFERENCES_EVALUATION_THREAD_NUMBER_TEXT=Number of rule evaluation threads:
418416
PREFERENCES_EVALUATION_THREAD_NUMBER_TOOLTIP=This sets the number of threads each editor will create and run in parallel to evaluate rules for that flight recording.
419417
PREFERENCES_EVALUATION_THREAD_NUMBER_LESS_THAN_ONE=Number of rule evaluation threads: Must be at least 1
420-
PREFERENCES_WEBSOCKET_SERVER_PORT_INVALID=Websocket server port must be a number between 0 and 65535
421418
# {0} is an exception message
422419
PREFERENCES_EVALUATION_THREAD_NUMBER_UNPARSEABLE=Number of rule evaluation threads: {0}
423420
PREFERENCES_PROPERTIES_ARRAY_STRING_SIZE_TEXT=Maximum display length of arrays in Properties view
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: %Bundle-Name
4+
Bundle-SymbolicName: org.openjdk.jmc.ui.websocket;singleton:=true
5+
Bundle-Version: 10.0.0.qualifier
6+
Automatic-Module-Name: org.openjdk.jmc.ui.websocket
7+
Bundle-RequiredExecutionEnvironment: JavaSE-21
8+
Require-Bundle: org.eclipse.core.runtime,
9+
org.eclipse.osgi,
10+
org.eclipse.ui,
11+
org.eclipse.jetty.ee9.server,
12+
org.eclipse.jetty.ee9.servlet,
13+
org.eclipse.jetty.ee9.websocket.api,
14+
org.eclipse.jetty.ee9.websocket.server,
15+
org.eclipse.jetty.server,
16+
org.eclipse.jetty.servlet-api,
17+
org.eclipse.jetty.util,
18+
org.openjdk.jmc.common,
19+
org.openjdk.jmc.flightrecorder.serializers,
20+
org.openjdk.jmc.flightrecorder
21+
Export-Package: org.openjdk.jmc.ui.websocket
22+
Bundle-Activator: org.openjdk.jmc.ui.websocket.WebsocketPlugin
23+
Bundle-ActivationPolicy: lazy
24+
Import-Package: org.openjdk.jmc.ui
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2025 IBM Corporation. All rights reserved.
4+
#
5+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6+
#
7+
# The contents of this file are subject to the terms of either the Universal Permissive License
8+
# v 1.0 as shown at https://oss.oracle.com/licenses/upl
9+
#
10+
# or the following license:
11+
#
12+
# Redistribution and use in source and binary forms, with or without modification, are permitted
13+
# provided that the following conditions are met:
14+
#
15+
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
16+
# and the following disclaimer.
17+
#
18+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
19+
# conditions and the following disclaimer in the documentation and/or other materials provided with
20+
# the distribution.
21+
#
22+
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
23+
# endorse or promote products derived from this software without specific prior written permission.
24+
#
25+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
26+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
27+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
32+
# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
source.. = src/main/java/
34+
output.. = target/classes/
35+
bin.includes = META-INF/,\
36+
.,\
37+
plugin.xml,\
38+
plugin.properties

0 commit comments

Comments
 (0)