]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics/src/org/simantics/DatabaseJob.java
SimanticsPlatform.startUp ensures updateness of installed feature groups
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / DatabaseJob.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics;
13
14 import org.eclipse.core.runtime.jobs.IJobManager;
15 import org.eclipse.core.runtime.jobs.Job;
16
17 /**
18  * An Eclipse job that inherently belongs to the
19  * {@link Simantics#DATABASE_JOB_FAMILY} job family.
20  * 
21  * <p>
22  * Use {@link #inProgress()} to check whether there are currently any
23  * {@link DatabaseJob}s running in the platform's job manager. Checks should be
24  * performed if any synchronous database requests must be initiated in the UI
25  * thread but it is not 100% necessary to return an accurate result right at
26  * that moment. Performing too much synchronous requests in the UI thread will
27  * currently inevitably get the UI completely stuck and therefore offloading
28  * database work to database job worker threads is highly recommended.
29  * 
30  * @author Tuukka Lehtonen
31  */
32 public abstract class DatabaseJob extends Job {
33
34     public static final String DATABASE_JOB_FAMILY = "org.simantics.db.inDatabaseJob";
35
36     public DatabaseJob(String name) {
37         super(name);
38     }
39
40     @Override
41     public boolean belongsTo(Object family) {
42         if (DATABASE_JOB_FAMILY.equals(family))
43             return true;
44         return super.belongsTo(family);
45     }
46
47     public static boolean inProgress() {
48         IJobManager manager = Job.getJobManager();
49         Job[] jobs = manager.find(DATABASE_JOB_FAMILY);
50         for (Job job : jobs)
51             if (job.getState() == Job.RUNNING)
52                 return true;
53         return false;
54     }
55
56 }