1 package org.simantics.structural.synchronization;
3 import java.util.concurrent.ConcurrentMap;
5 import org.eclipse.core.runtime.IProgressMonitor;
6 import org.eclipse.core.runtime.IStatus;
7 import org.eclipse.core.runtime.Status;
8 import org.eclipse.core.runtime.jobs.Job;
9 import org.simantics.DatabaseJob;
10 import org.simantics.Simantics;
11 import org.simantics.simulation.experiment.ExperimentState;
12 import org.simantics.simulation.experiment.IExperiment;
14 public class ContinuousSynchronizationJob extends DatabaseJob {
16 public static final String FAMILY = "ContinuousSynchronizationJob";
18 final private ConcurrentMap<IExperiment, Job> currentSyncJobs;
20 IExperiment experiment;
22 public ContinuousSynchronizationJob(IExperiment experiment, ConcurrentMap<IExperiment, Job> currentSyncJobs) {
23 super("Synchronization");
24 this.experiment = experiment;
25 this.currentSyncJobs = currentSyncJobs;
31 public boolean belongsTo(Object family) {
32 if (FAMILY == family) return true;
33 return super.belongsTo(family);
37 public boolean shouldRun() {
38 return currentSyncJobs.remove(experiment, this);
42 protected IStatus run(IProgressMonitor monitor) {
44 //System.out.println("SYNC #" + (++syncCounter));
45 monitor.beginTask("", IProgressMonitor.UNKNOWN);
46 if (experiment.getState() != ExperimentState.DISPOSED)
47 experiment.refresh(Simantics.getSession());
48 return Status.OK_STATUS;
49 } catch (Throwable t) {
50 return new Status(IStatus.ERROR, "org.simantics.structural.synchronization.client", "Failed to refresh experiment "
51 + experiment + " with ID " + experiment.getIdentifier(), t);