Skip to content

Commit d4985f2

Browse files
committed
Make service trackers instance scoped in terminal.view.ui
Currently service trackers are using a static field, what could lead to wrong behavior when the bundle is restarted. This now converts the tracker to instance fields to account for bundle restarts and clears up an unnecessary static reference in TerminalService. Beside that, access to relevant service relevant in the context are added to the required AbstractImpl classes so there is no need for individual plugins to track these services.
1 parent b47f9cd commit d4985f2

File tree

23 files changed

+93
-148
lines changed

23 files changed

+93
-148
lines changed

terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/activator/UIPlugin.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.eclipse.jface.resource.ImageDescriptor;
1515
import org.eclipse.jface.resource.ImageRegistry;
1616
import org.eclipse.swt.graphics.Image;
17-
import org.eclipse.terminal.view.core.ITerminalService;
1817
import org.eclipse.terminal.view.core.utils.ScopedEclipsePreferences;
1918
import org.eclipse.terminal.view.core.utils.TraceHandler;
2019
import org.eclipse.terminal.view.ui.launcher.ILaunchDelegateManager;
@@ -27,17 +26,13 @@
2726
*/
2827
public class UIPlugin extends AbstractUIPlugin {
2928
// The shared instance
30-
private static UIPlugin plugin;
29+
private static volatile UIPlugin plugin;
3130
// The scoped preferences instance
3231
private static volatile ScopedEclipsePreferences scopedPreferences;
3332
// The trace handler instance
3433
private static volatile TraceHandler traceHandler;
3534

36-
/**
37-
* The constructor
38-
*/
39-
public UIPlugin() {
40-
}
35+
private ServiceTracker<ILaunchDelegateManager, ILaunchDelegateManager> launchDelegateServiceTracker;
4136

4237
/**
4338
* Returns the shared instance
@@ -83,6 +78,8 @@ public static TraceHandler getTraceHandler() {
8378
@Override
8479
public void start(BundleContext context) throws Exception {
8580
super.start(context);
81+
launchDelegateServiceTracker = new ServiceTracker<>(context, ILaunchDelegateManager.class, null);
82+
launchDelegateServiceTracker.open();
8683
plugin = this;
8784
}
8885

@@ -121,25 +118,11 @@ public static ImageDescriptor getImageDescriptor(String key) {
121118
return getDefault().getImageRegistry().getDescriptor(key);
122119
}
123120

124-
private static ServiceTracker<ITerminalService, ITerminalService> terminalServiceTracker;
125-
126-
public static synchronized ITerminalService getTerminalService() {
127-
if (terminalServiceTracker == null) {
128-
terminalServiceTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(),
129-
ITerminalService.class, null);
130-
terminalServiceTracker.open();
131-
}
132-
return terminalServiceTracker.getService();
133-
}
134-
135-
private static ServiceTracker<ILaunchDelegateManager, ILaunchDelegateManager> launchDelegateServiceTracker;
136-
137121
public static synchronized ILaunchDelegateManager getLaunchDelegateManager() {
138-
if (launchDelegateServiceTracker == null) {
139-
launchDelegateServiceTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(),
140-
ILaunchDelegateManager.class, null);
141-
launchDelegateServiceTracker.open();
122+
UIPlugin plugin = getDefault();
123+
if (plugin == null) {
124+
return null;
142125
}
143-
return launchDelegateServiceTracker.getService();
126+
return plugin.launchDelegateServiceTracker.getService();
144127
}
145128
}

terminal/bundles/org.eclipse.terminal.connector.local/src/org/eclipse/terminal/connector/local/launcher/LocalLauncherDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
222222
}
223223

224224
// Get the terminal service
225-
ITerminalService terminal = UIPlugin.getTerminalService();
225+
ITerminalService terminal = getTerminalService();
226226
// If not available, we cannot fulfill this request
227227
if (terminal != null) {
228228
terminal.openConsole(properties, done);

terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/ProcessConnector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void connect(ITerminalControl control) {
209209
// Save the shell so the error message can have somewhere to display
210210
Shell shell = control.getShell();
211211
// Lookup the tab item
212-
UIPlugin.getConsoleManager().findConsole(control).ifPresent(Widget::dispose);
212+
getConsoleViewManager().findConsole(control).ifPresent(Widget::dispose);
213213
// Get the error message from the exception
214214
String msg = e.getLocalizedMessage() != null ? e.getLocalizedMessage() : ""; //$NON-NLS-1$
215215
Assert.isNotNull(msg);

terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/ProcessLauncherDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
4747
Assert.isNotNull(properties);
4848

4949
// Get the terminal service
50-
ITerminalService terminal = UIPlugin.getTerminalService();
50+
ITerminalService terminal = getTerminalService();
5151
// If not available, we cannot fulfill this request
5252
if (terminal != null) {
5353
terminal.openConsole(properties, done);

terminal/bundles/org.eclipse.terminal.connector.process/src/org/eclipse/terminal/connector/process/internal/UIPlugin.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
import org.eclipse.jface.resource.ImageDescriptor;
1717
import org.eclipse.jface.resource.ImageRegistry;
1818
import org.eclipse.swt.graphics.Image;
19-
import org.eclipse.terminal.view.core.ITerminalService;
2019
import org.eclipse.terminal.view.core.utils.TraceHandler;
21-
import org.eclipse.terminal.view.ui.launcher.ITerminalConsoleViewManager;
2220
import org.eclipse.ui.plugin.AbstractUIPlugin;
2321
import org.osgi.framework.BundleContext;
24-
import org.osgi.util.tracker.ServiceTracker;
2522

2623
/**
2724
* The activator class controls the plug-in life cycle
@@ -117,26 +114,4 @@ public static void log(IStatus status) {
117114
getDefault().getLog().log(status);
118115
}
119116

120-
private static ServiceTracker<ITerminalService, ITerminalService> serviceTracker;
121-
122-
public static synchronized ITerminalService getTerminalService() {
123-
if (serviceTracker == null) {
124-
serviceTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(), ITerminalService.class,
125-
null);
126-
serviceTracker.open();
127-
}
128-
return serviceTracker.getService();
129-
}
130-
131-
private static ServiceTracker<ITerminalConsoleViewManager, ITerminalConsoleViewManager> consoleManagerTracker;
132-
133-
public static synchronized ITerminalConsoleViewManager getConsoleManager() {
134-
if (consoleManagerTracker == null) {
135-
consoleManagerTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(),
136-
ITerminalConsoleViewManager.class, null);
137-
consoleManagerTracker.open();
138-
}
139-
return consoleManagerTracker.getService();
140-
}
141-
142117
}

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/activator/UIPlugin.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.eclipse.jsch.core.IJSchService;
1717
import org.eclipse.swt.graphics.Image;
1818
import org.eclipse.terminal.connector.ssh.connector.SshConnection;
19-
import org.eclipse.terminal.view.core.ITerminalService;
2019
import org.eclipse.terminal.view.core.utils.TraceHandler;
2120
import org.eclipse.ui.plugin.AbstractUIPlugin;
2221
import org.osgi.framework.BundleContext;
@@ -143,14 +142,4 @@ public static ImageDescriptor getImageDescriptor(String key) {
143142
return getDefault().getImageRegistry().getDescriptor(key);
144143
}
145144

146-
private static ServiceTracker<ITerminalService, ITerminalService> serviceTracker;
147-
148-
public static synchronized ITerminalService getTerminalService() {
149-
if (serviceTracker == null) {
150-
serviceTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(), ITerminalService.class,
151-
null);
152-
serviceTracker.open();
153-
}
154-
return serviceTracker.getService();
155-
}
156145
}

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/connector/SshConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import org.eclipse.terminal.connector.ITerminalControl;
2323
import org.eclipse.terminal.connector.Logger;
2424
import org.eclipse.terminal.connector.NullSettingsStore;
25-
import org.eclipse.terminal.connector.provider.TerminalConnectorImpl;
25+
import org.eclipse.terminal.connector.provider.AbstractTerminalConnector;
2626

2727
import com.jcraft.jsch.ChannelShell;
2828
import com.jcraft.jsch.JSch;
2929

30-
public class SshConnector extends TerminalConnectorImpl {
30+
public class SshConnector extends AbstractTerminalConnector {
3131
private OutputStream fOutputStream;
3232
private InputStream fInputStream;
3333
private JSch fJsch;

terminal/bundles/org.eclipse.terminal.connector.ssh/src/org/eclipse/terminal/connector/ssh/launcher/SshLauncherDelegate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.eclipse.terminal.connector.ITerminalConnector;
2323
import org.eclipse.terminal.connector.InMemorySettingsStore;
2424
import org.eclipse.terminal.connector.TerminalConnectorExtension;
25-
import org.eclipse.terminal.connector.ssh.activator.UIPlugin;
2625
import org.eclipse.terminal.connector.ssh.connector.ISshSettings;
2726
import org.eclipse.terminal.connector.ssh.connector.SshSettings;
2827
import org.eclipse.terminal.connector.ssh.controls.SshWizardConfigurationPanel;
@@ -68,7 +67,7 @@ public void execute(Map<String, Object> properties, ITerminalService.Done done)
6867
}
6968

7069
// Get the terminal service
71-
ITerminalService terminal = UIPlugin.getTerminalService();
70+
ITerminalService terminal = getTerminalService();
7271
// If not available, we cannot fulfill this request
7372
if (terminal != null) {
7473
terminal.openConsole(properties, done);

terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/activator/UIPlugin.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
import org.eclipse.jface.resource.ImageDescriptor;
1616
import org.eclipse.jface.resource.ImageRegistry;
1717
import org.eclipse.swt.graphics.Image;
18-
import org.eclipse.terminal.view.core.ITerminalService;
1918
import org.eclipse.terminal.view.core.utils.TraceHandler;
2019
import org.eclipse.ui.plugin.AbstractUIPlugin;
2120
import org.osgi.framework.BundleContext;
22-
import org.osgi.util.tracker.ServiceTracker;
2321

2422
/**
2523
* The activator class controls the plug-in life cycle
@@ -105,14 +103,4 @@ public static ImageDescriptor getImageDescriptor(String key) {
105103
return getDefault().getImageRegistry().getDescriptor(key);
106104
}
107105

108-
private static ServiceTracker<ITerminalService, ITerminalService> serviceTracker;
109-
110-
public static synchronized ITerminalService getTerminalService() {
111-
if (serviceTracker == null) {
112-
serviceTracker = new ServiceTracker<>(getDefault().getBundle().getBundleContext(), ITerminalService.class,
113-
null);
114-
serviceTracker.open();
115-
}
116-
return serviceTracker.getService();
117-
}
118106
}

terminal/bundles/org.eclipse.terminal.connector.telnet/src/org/eclipse/terminal/connector/telnet/connector/TelnetConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import org.eclipse.terminal.connector.Logger;
3434
import org.eclipse.terminal.connector.NullSettingsStore;
3535
import org.eclipse.terminal.connector.TerminalState;
36-
import org.eclipse.terminal.connector.provider.TerminalConnectorImpl;
36+
import org.eclipse.terminal.connector.provider.AbstractTerminalConnector;
3737

38-
public class TelnetConnector extends TerminalConnectorImpl {
38+
public class TelnetConnector extends AbstractTerminalConnector {
3939

4040
static final class TelnetOutputStream extends FilterOutputStream {
4141
final static byte CR = 13;

0 commit comments

Comments
 (0)