Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2003-10-17 17:35:44 +0000
committerJean Michel-Lemieux2003-10-17 17:35:44 +0000
commit6f3377d07a77b6d577530899ae927437c84ec193 (patch)
tree46b1447d8364d533867ec7dd3186a7b9d3ace413
parent52ac78bc92594e8dc26cb432d777134df237f89a (diff)
downloadeclipse.platform.team-6f3377d07a77b6d577530899ae927437c84ec193.tar.gz
eclipse.platform.team-6f3377d07a77b6d577530899ae927437c84ec193.tar.xz
eclipse.platform.team-6f3377d07a77b6d577530899ae927437c84ec193.zip
*** empty log message ***
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java102
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java42
2 files changed, 96 insertions, 48 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java
index 6b75d583a..ac83bb70d 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java
@@ -10,12 +10,17 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.jobs;
+import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.team.core.subscribers.ITeamResourceChangeListener;
-import org.eclipse.team.core.subscribers.TeamDelta;
+import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.TeamSubscriber;
import org.eclipse.team.internal.ui.Policy;
+import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.sync.sets.SubscriberInput;
/**
@@ -23,63 +28,90 @@ import org.eclipse.team.internal.ui.sync.sets.SubscriberInput;
*
* There can be several refresh jobs created but they will be serialized.
*/
-public class RefreshSubscriberInputJob extends RefreshSubscriberJob implements ITeamResourceChangeListener {
+public class RefreshSubscriberInputJob extends RefreshSubscriberJob {
/**
* The subscribers and roots to refresh. If these are changed when the job
* is running the job is cancelled.
*/
- private SubscriberInput input;
+ private List inputs = new ArrayList(3);
public RefreshSubscriberInputJob(String name) {
super(name, null, null);
}
- public void teamResourceChanged(TeamDelta[] deltas) {
- for (int i = 0; i < deltas.length; i++) {
- TeamDelta delta = deltas[i];
- if(delta.getFlags() == TeamDelta.SUBSCRIBER_DELETED) {
- // cancel current refresh just to make sure that the subscriber being deleted can
- // be properly shutdown
- cancel();
- setSubscriberInput(null);
- }
- }
+ public synchronized void addSubscriberInput(SubscriberInput input) {
+ stop();
+ inputs.add(input);
+ start();
+ }
+
+ public synchronized void removeSubscriberInput(SubscriberInput input) {
+ stop();
+ inputs.remove(input);
+ start();
}
- public void setSubscriberInput(SubscriberInput input) {
+ private void stop() {
int state = getState();
if(state == Job.RUNNING) {
cancel();
- }
- this.input = input;
-
- if(state == Job.NONE && input != null) {
- if(shouldReschedule()) {
- schedule(getScheduleDelay());
+ try {
+ join();
+ } catch (InterruptedException e) {
+ // continue
}
}
}
-
- protected IResource[] getResources() {
- if(input != null) {
- return input.workingSetRoots();
- }
- return null;
- }
- protected TeamSubscriber getSubscriber() {
- if(input != null) {
- return input.getSubscriber();
+ /**
+ * This is run by the job scheduler. A list of subscribers will be refreshed, errors will not stop the job
+ * and it will continue to refresh the other subscribers.
+ */
+ public IStatus runInWorkspace(IProgressMonitor monitor) {
+ // Synchronized to ensure only one refresh job is running at a particular time
+ synchronized (getFamily()) {
+ MultiStatus status = new MultiStatus(TeamUIPlugin.ID, TeamException.UNABLE, Policy.bind("RefreshSubscriberJob.0"), null); //$NON-NLS-1$
+
+ // if there are no resources to refresh, just return
+ if(inputs.isEmpty()) {
+ return Status.OK_STATUS;
+ }
+
+ monitor.beginTask(getTaskName(), 100);
+ try {
+ // Only allow one refresh job at a time
+ // NOTE: It would be cleaner if this was done by a scheduling
+ // rule but at the time of writting, it is not possible due to
+ // the scheduling rule containment rules.
+ lastTimeRun = System.currentTimeMillis();
+ if(monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ try {
+ for (Iterator it = inputs.iterator(); it.hasNext();) {
+ SubscriberInput input = (SubscriberInput) it.next();
+ TeamSubscriber subscriber = input.getSubscriber();
+ monitor.setTaskName(subscriber.getName());
+ subscriber.refresh(input.workingSetRoots(), IResource.DEPTH_INFINITE, Policy.subMonitorFor(monitor, 100));
+ }
+ } catch(TeamException e) {
+ status.merge(e.getStatus());
+ }
+ } catch(OperationCanceledException e2) {
+ return Status.CANCEL_STATUS;
+ } finally {
+ monitor.done();
+ }
+ return status.isOK() ? Status.OK_STATUS : (IStatus) status;
}
- return null;
}
+
/* (non-Javadoc)
* @see org.eclipse.team.internal.ui.jobs.RefreshSubscriberJob#getTaskName(org.eclipse.team.core.subscribers.TeamSubscriber, org.eclipse.core.resources.IResource[])
*/
- protected String getTaskName(TeamSubscriber subscriber, IResource[] roots) {
+ protected String getTaskName() {
// Return a meaningfull task nam since the job name will be generic
- return Policy.bind("RefreshSubscriberJob.1", String.valueOf(roots.length), subscriber.getName()); //$NON-NLS-1$
+ return Policy.bind("RefreshSubscriberJob.1", String.valueOf(inputs.size()), "all"); //$NON-NLS-1$
}
-
} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java
index 3b25c04f2..385b56d2d 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java
@@ -39,7 +39,7 @@ public class RefreshSubscriberJob extends WorkspaceJob {
* Uniquely identifies this type of job. This is used for cancellation.
*/
private final static Object FAMILY_ID = new Object();
-
+
/**
* If true this job will be restarted when it completes
*/
@@ -49,7 +49,7 @@ public class RefreshSubscriberJob extends WorkspaceJob {
* If true a rescheduled refresh job should be retarted when cancelled
*/
/* internal use only */ boolean restartOnCancel = true;
-
+
/**
* The schedule delay used when rescheduling a completed job
*/
@@ -58,7 +58,7 @@ public class RefreshSubscriberJob extends WorkspaceJob {
/**
* Time the job was run last in milliseconds.
*/
- private long lastTimeRun = 0;
+ protected long lastTimeRun = 0;
/**
* The subscribers and roots to refresh. If these are changed when the job
@@ -87,15 +87,15 @@ public class RefreshSubscriberJob extends WorkspaceJob {
}
});
}
-
+
public boolean shouldRun() {
return getSubscriber() != null;
}
-
+
public boolean belongsTo(Object family) {
return family == getFamily();
}
-
+
public static Object getFamily() {
return FAMILY_ID;
}
@@ -115,7 +115,7 @@ public class RefreshSubscriberJob extends WorkspaceJob {
if(subscriber == null || roots == null) {
return Status.OK_STATUS;
}
-
+
monitor.beginTask(getTaskName(subscriber, roots), 100);
try {
// Only allow one refresh job at a time
@@ -140,16 +140,16 @@ public class RefreshSubscriberJob extends WorkspaceJob {
return status.isOK() ? Status.OK_STATUS : (IStatus) status;
}
}
-
+
protected String getTaskName(TeamSubscriber subscriber, IResource[] roots) {
// Don't return a task name as the job name contains the subscriber and resource count
return null;
}
-
+
protected IResource[] getResources() {
return resources;
}
-
+
protected TeamSubscriber getSubscriber() {
return subscriber;
}
@@ -157,15 +157,31 @@ public class RefreshSubscriberJob extends WorkspaceJob {
protected long getScheduleDelay() {
return scheduleDelay;
}
-
+
+ protected void start() {
+ if(getState() == Job.NONE) {
+ if(shouldReschedule()) {
+ schedule(getScheduleDelay());
+ }
+ }
+ }
+
/**
* Specify the interval in seconds at which this job is scheduled.
* @param seconds delay specified in seconds
*/
public void setRefreshInterval(long seconds) {
+ boolean restart = false;
+ if(getState() == Job.SLEEPING) {
+ restart = true;
+ cancel();
+ }
scheduleDelay = seconds * 1000;
+ if(restart) {
+ start();
+ }
}
-
+
/**
* Returns the interval of this job in seconds.
* @return
@@ -173,7 +189,7 @@ public class RefreshSubscriberJob extends WorkspaceJob {
public long getRefreshInterval() {
return scheduleDelay / 1000;
}
-
+
public void setRestartOnCancel(boolean restartOnCancel) {
this.restartOnCancel = restartOnCancel;
}

Back to the top