Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2013-05-20 10:26:35 -0400
committerUwe Stieber2013-05-20 10:26:35 -0400
commita208df59737db0fa329bc999094b621c3b30a4fb (patch)
tree9275266951ac9f9a0939a2c6d0127cc73a85df58 /target_explorer
parent2ee1fbe519139aab8bed61efa5ee0d9f26ef5230 (diff)
downloadorg.eclipse.tcf-a208df59737db0fa329bc999094b621c3b30a4fb.tar.gz
org.eclipse.tcf-a208df59737db0fa329bc999094b621c3b30a4fb.tar.xz
org.eclipse.tcf-a208df59737db0fa329bc999094b621c3b30a4fb.zip
Target Explorer: Add abstract job implementation where the logic is executed in the TCF event dispatch thread
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF83
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/help/IContextHelpIds.java28
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/jobs/AbstractJob.java139
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.properties2
5 files changed, 214 insertions, 40 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF
index 59b0cc287..4a64c2f68 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/META-INF/MANIFEST.MF
@@ -1,40 +1,43 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.tcf.te.tcf.core;singleton:=true
-Bundle-Version: 1.1.0.qualifier
-Bundle-Activator: org.eclipse.tcf.te.tcf.core.activator.CoreBundleActivator
-Bundle-Vendor: %providerName
-Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
- org.eclipse.core.expressions;bundle-version="3.4.400",
- org.eclipse.tcf;bundle-version="1.1.0",
- org.eclipse.tcf.core;bundle-version="1.1.0",
- org.eclipse.tcf.te.runtime;bundle-version="1.1.0",
- org.eclipse.tcf.te.core;bundle-version="1.1.0",
- org.eclipse.tcf.te.runtime.persistence;bundle-version="1.1.0",
- org.eclipse.tcf.te.runtime.services;bundle-version="1.1.0",
- org.eclipse.tcf.te.runtime.stepper;bundle-version="1.1.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ActivationPolicy: lazy
-Bundle-Localization: plugin
-Export-Package: org.eclipse.tcf.te.tcf.core,
- org.eclipse.tcf.te.tcf.core.activator;x-internal:=true,
- org.eclipse.tcf.te.tcf.core.async,
- org.eclipse.tcf.te.tcf.core.concurrent,
- org.eclipse.tcf.te.tcf.core.interfaces,
- org.eclipse.tcf.te.tcf.core.interfaces.steps,
- org.eclipse.tcf.te.tcf.core.interfaces.tracing,
- org.eclipse.tcf.te.tcf.core.internal;x-internal:=true,
- org.eclipse.tcf.te.tcf.core.internal.utils;x-internal:=true,
- org.eclipse.tcf.te.tcf.core.iterators,
- org.eclipse.tcf.te.tcf.core.listeners,
- org.eclipse.tcf.te.tcf.core.listeners.interfaces,
- org.eclipse.tcf.te.tcf.core.nls;x-internal:=true,
- org.eclipse.tcf.te.tcf.core.peers,
- org.eclipse.tcf.te.tcf.core.steps,
- org.eclipse.tcf.te.tcf.core.streams,
- org.eclipse.tcf.te.tcf.core.util,
- org.eclipse.tcf.te.tcf.core.util.persistence,
- org.eclipse.tcf.te.tcf.core.va,
- org.eclipse.tcf.te.tcf.core.va.interfaces,
- org.eclipse.tcf.te.tcf.core.va.internal;x-internal:=true
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.tcf.te.tcf.core;singleton:=true
+Bundle-Version: 1.1.0.qualifier
+Bundle-Activator: org.eclipse.tcf.te.tcf.core.activator.CoreBundleActivator
+Bundle-Vendor: %providerName
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
+ org.eclipse.core.expressions;bundle-version="3.4.400",
+ org.eclipse.tcf;bundle-version="1.1.0",
+ org.eclipse.tcf.core;bundle-version="1.1.0",
+ org.eclipse.tcf.te.runtime;bundle-version="1.1.0",
+ org.eclipse.tcf.te.core;bundle-version="1.1.0",
+ org.eclipse.tcf.te.runtime.persistence;bundle-version="1.1.0",
+ org.eclipse.tcf.te.runtime.services;bundle-version="1.1.0",
+ org.eclipse.tcf.te.runtime.stepper;bundle-version="1.1.0",
+ org.eclipse.tcf.te.runtime.statushandler;bundle-version="1.1.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
+Export-Package: org.eclipse.tcf.te.tcf.core,
+ org.eclipse.tcf.te.tcf.core.activator;x-internal:=true,
+ org.eclipse.tcf.te.tcf.core.async,
+ org.eclipse.tcf.te.tcf.core.concurrent,
+ org.eclipse.tcf.te.tcf.core.help,
+ org.eclipse.tcf.te.tcf.core.interfaces,
+ org.eclipse.tcf.te.tcf.core.interfaces.steps,
+ org.eclipse.tcf.te.tcf.core.interfaces.tracing,
+ org.eclipse.tcf.te.tcf.core.internal;x-internal:=true,
+ org.eclipse.tcf.te.tcf.core.internal.utils;x-internal:=true,
+ org.eclipse.tcf.te.tcf.core.iterators,
+ org.eclipse.tcf.te.tcf.core.jobs,
+ org.eclipse.tcf.te.tcf.core.listeners,
+ org.eclipse.tcf.te.tcf.core.listeners.interfaces,
+ org.eclipse.tcf.te.tcf.core.nls;x-internal:=true,
+ org.eclipse.tcf.te.tcf.core.peers,
+ org.eclipse.tcf.te.tcf.core.steps,
+ org.eclipse.tcf.te.tcf.core.streams,
+ org.eclipse.tcf.te.tcf.core.util,
+ org.eclipse.tcf.te.tcf.core.util.persistence,
+ org.eclipse.tcf.te.tcf.core.va,
+ org.eclipse.tcf.te.tcf.core.va.interfaces,
+ org.eclipse.tcf.te.tcf.core.va.internal;x-internal:=true
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/help/IContextHelpIds.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/help/IContextHelpIds.java
new file mode 100644
index 000000000..e7c4d9766
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/help/IContextHelpIds.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.core.help;
+
+import org.eclipse.tcf.te.tcf.core.activator.CoreBundleActivator;
+
+/**
+ * Context help id definitions.
+ */
+public interface IContextHelpIds {
+
+ /**
+ * Core plug-in common context help id prefix.
+ */
+ public final static String PREFIX = CoreBundleActivator.getUniqueIdentifier() + "."; //$NON-NLS-1$
+
+ /**
+ * Common context help id to signal once a generic job operation failed.
+ */
+ public final static String MESSAGE_OPERATION_FAILED = PREFIX + ".status.operationFailed"; //$NON-NLS-1$
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/jobs/AbstractJob.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/jobs/AbstractJob.java
new file mode 100644
index 000000000..05159b375
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/jobs/AbstractJob.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.core.jobs;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.runtime.callback.Callback;
+import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandler;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandlerConstants;
+import org.eclipse.tcf.te.tcf.core.help.IContextHelpIds;
+import org.eclipse.tcf.te.tcf.core.nls.Messages;
+
+/**
+ * Abstract TCF job implementation.
+ * <p>
+ * The job implementation assures that the job logic is executed within the
+ * TCF event dispatch thread. The job passes on the execution status to a
+ * registered status handler if no parent callback is set.
+ */
+public abstract class AbstractJob extends Job {
+ // The parent callback.
+ /* default */ final ICallback parentCallback;
+
+ /**
+ * Constructor.
+ *
+ * @param name The job name. Must not be <code>null</code>.
+ */
+ public AbstractJob(String name) {
+ this(name, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name The job name. Must not be <code>null</code>.
+ * @param parentCallback The parent callback or <code>null</code>.
+ */
+ public AbstractJob(String name, ICallback parentCallback) {
+ super(name);
+ this.parentCallback = parentCallback;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected final IStatus run(final IProgressMonitor monitor) {
+ // The first runnable is setting the thread which will finish the job at the end
+ Protocol.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ AbstractJob.this.setThread(Thread.currentThread());
+ }
+ });
+
+ final IProgressMonitor finMonitor = monitor;
+
+ // The callback to invoke from the job's logic must be created before scheduling
+ // the job logic asynchronously
+ final ICallback callback = new Callback() {
+ @Override
+ protected void internalDone(final Object caller, final IStatus status) {
+ // If the parent callback is not set, pass on the status to a registered status handler
+ if (parentCallback == null) {
+ // If we have a non-OK or CANCEL status, forward to the status handler
+ if (status != null && status.getSeverity() != IStatus.CANCEL && status.getSeverity() != IStatus.OK) {
+ IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(AbstractJob.this);
+ if (handler.length > 0) {
+ IPropertiesContainer data = new PropertiesContainer();
+ data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, getProperty(IStatusHandlerConstants.PROPERTY_TITLE) != null ? getProperty(IStatusHandlerConstants.PROPERTY_TITLE) : Messages.AbstractJob_error_dialogTitle);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, getProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID) != null ? getProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID) : IContextHelpIds.MESSAGE_OPERATION_FAILED);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, AbstractJob.this);
+
+ handler[0].handleStatus(status, data, null);
+ }
+ }
+ } else {
+ // Pass on the caller and the status to the parent callback
+ // We call the parent callback asynchronously in the TCF
+ // event dispatch thread. The job termination happens in
+ // a separate runnable.
+ Protocol.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ parentCallback.done(caller, status);
+ }
+ });
+ }
+
+ // Job termination must must happen in the TCF event dispatch thread as
+ // this is the thread we've set before as the termination thread.
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ // Mark the job as done
+ IStatus result = finMonitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
+ AbstractJob.this.done(result);
+ }
+ };
+
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeLater(runnable);
+ }
+ };
+
+ // Run the job logic
+ Protocol.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ AbstractJob.this.run(monitor, callback);
+ }
+ });
+
+ return ASYNC_FINISH;
+ }
+
+ /**
+ * Executes the job logic.
+ *
+ * @param monitor The progress monitor. Must not be <code>null</code>.
+ * @param callback The callback to invoke. Must not be <code>null</code>.
+ */
+ public abstract void run(IProgressMonitor monitor, ICallback callback);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java
index 5115bd7f6..44b336951 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.java
@@ -106,4 +106,6 @@ public class Messages extends NLS {
public static String Extension_error_invalidProtocolStateChangeListener;
public static String Extension_error_invalidChannelStateChangeListener;
+
+ public static String AbstractJob_error_dialogTitle;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.properties
index 909a36f8c..9d864b5da 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/nls/Messages.properties
@@ -47,3 +47,5 @@ MonitorTask_TimeoutError=The callback monitor has timed out\!
Extension_error_invalidProtocolStateChangeListener=Failed to instantiate the protocol state change listener from extension point ''{0}''.
Extension_error_invalidChannelStateChangeListener=Failed to instantiate the channel state change listener from extension point ''{0}''.
+
+AbstractJob_error_dialogTitle=Error

Back to the top