]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/WorkState.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / ua / WorkState.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 \r
13 package org.simantics.utils.threads.ua;\r
14 \r
15 import java.util.EnumSet;\r
16 \r
17 /**\r
18  * State of an async execution (=work)\r
19  * \r
20  * Initial states: Ready\r
21  * Final states: Complete, Canceled, Error, Interrupted\r
22  * \r
23  * State transitions:\r
24  *   Ready -> Canceled\r
25  *   Ready -> Working -> Complete\r
26  *   Ready -> Working -> Error \r
27  *   Ready -> Working -> Interrupting -> Error\r
28  *   Ready -> Working -> Interrupting -> Interrupted\r
29  * \r
30  * @see WorkMonitor\r
31  * @see Work\r
32  * @see AsyncRun\r
33  * @author Toni Kalajainen (toni.kalajainen@vtt.fi)\r
34  */\r
35 public enum WorkState {\r
36 \r
37         Ready,                  // Work has not been started. (Initial State)\r
38         Working,                // The work has started.\r
39         Complete,               // The work has completed. (Final State)\r
40         Interrupting,   // Interrupt signal has been sent.\r
41         Interrupted,    // The work was has ended after interrupt signal. (Final State)\r
42         Error,                  // There was an error during the execution. (Final State)\r
43         Canceled;               // Work was canceled before it was started. (Final State)\r
44         \r
45         public static final EnumSet<WorkState> READY_STATE = EnumSet.of(WorkState.Ready);\r
46         public static final EnumSet<WorkState> WORKING_STATE = EnumSet.of(WorkState.Working);\r
47         public static final EnumSet<WorkState> FINAL_STATES = EnumSet.of(WorkState.Complete, WorkState.Error, WorkState.Canceled, WorkState.Interrupted);\r
48         public static final EnumSet<WorkState> COMPLETE_STATE = EnumSet.of(WorkState.Complete);\r
49         public static final EnumSet<WorkState> ERROR_STATE = EnumSet.of(WorkState.Error);\r
50         public static final EnumSet<WorkState> CANCELED_STATE = EnumSet.of(WorkState.Canceled);\r
51         public static final EnumSet<WorkState> CANCELED_STATES = EnumSet.of(WorkState.Canceled, WorkState.Interrupted, WorkState.Interrupting);\r
52 \r
53         public boolean isFinalState()\r
54         {\r
55                 return FINAL_STATES.contains(this);\r
56         }\r
57         \r
58         public boolean isInitialState()\r
59         {\r
60                 return this == Ready;\r
61         }\r
62         \r
63 }\r