Author: rob.stryker(a)jboss.com
Date: 2010-12-14 01:36:24 -0500 (Tue, 14 Dec 2010)
New Revision: 27427
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/jobs/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/jobs/ChainedJob.java
Modified:
trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF
Log:
add chained-job to common plugin as possible central location
Modified: trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF 2010-12-14 01:38:52
UTC (rev 27426)
+++ trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF 2010-12-14 06:36:24
UTC (rev 27427)
@@ -12,6 +12,7 @@
org.jboss.tools.common.reporting,
org.jboss.tools.common.text,
org.jboss.tools.common.util,
+ org.jboss.tools.common.jobs,
org.jboss.tools.common.xml,
org.jboss.tools.common.zip
Require-Bundle: org.eclipse.core.runtime,
@@ -26,7 +27,7 @@
org.eclipse.jdt.ui,
org.eclipse.ui.workbench.texteditor,
org.eclipse.jface.text,
- org.apache.commons.httpclient;bundle-version="3.1.0"
+ org.apache.commons.httpclient
Bundle-Version: 3.2.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/jobs/ChainedJob.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/jobs/ChainedJob.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/jobs/ChainedJob.java 2010-12-14
06:36:24 UTC (rev 27427)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2007 IBM Corporation 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:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.common.jobs;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+
+/**
+ * A Job that can start another job upon successful completion.
+ */
+public abstract class ChainedJob extends Job {
+ private Job nextJob;
+ private IJobChangeListener listener;
+ private String family;
+
+ /**
+ * Create a new dependent job.
+ *
+ * @param name the name of the job
+ * @param server the server to publish to
+ */
+ public ChainedJob(String name, String family) {
+ super(name);
+ this.family = family;
+ }
+
+ /**
+ * @see Job#belongsTo(java.lang.Object)
+ */
+ public boolean belongsTo(Object family) {
+ return this.family.equals(family);
+ }
+
+
+ /**
+ * Create a listener for when this job finishes.
+ */
+ protected void createListener() {
+ if (listener != null)
+ return;
+
+ listener = new JobChangeAdapter() {
+ public void done(IJobChangeEvent event) {
+ jobDone(event.getResult());
+ }
+ };
+
+ addJobChangeListener(listener);
+ }
+
+ /**
+ * Called when this job is complete.
+ *
+ * @param status the result of the current job
+ */
+ protected void jobDone(IStatus status) {
+ if (listener == null)
+ return;
+
+ removeJobChangeListener(listener);
+ listener = null;
+
+ if (nextJob != null && status != null && status.getSeverity() !=
IStatus.ERROR
+ && status.getSeverity() != IStatus.CANCEL)
+ nextJob.schedule();
+ }
+
+ /**
+ * Set the next job, which should be scheduled if and only if this job completes
+ * successfully. The next job will be run as long as the result of this job is
+ * not an ERROR or CANCEL status.
+ * This method is not thread-safe. However, the next job can be changed anytime
+ * up until the current job completes.
+ *
+ * @param job the next job that should be scheduled
+ */
+ public void setNextJob(Job job) {
+ nextJob = job;
+ createListener();
+ }
+}