]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/WorkState.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / ua / WorkState.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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
13 package org.simantics.utils.threads.ua;
14
15 import java.util.EnumSet;
16
17 /**
18  * State of an async execution (=work)
19  * 
20  * Initial states: Ready
21  * Final states: Complete, Canceled, Error, Interrupted
22  * 
23  * State transitions:
24  *   Ready -> Canceled
25  *   Ready -> Working -> Complete
26  *   Ready -> Working -> Error 
27  *   Ready -> Working -> Interrupting -> Error
28  *   Ready -> Working -> Interrupting -> Interrupted
29  * 
30  * @see WorkMonitor
31  * @see Work
32  * @see AsyncRun
33  * @author Toni Kalajainen (toni.kalajainen@vtt.fi)
34  */
35 public enum WorkState {
36
37         Ready,                  // Work has not been started. (Initial State)
38         Working,                // The work has started.
39         Complete,               // The work has completed. (Final State)
40         Interrupting,   // Interrupt signal has been sent.
41         Interrupted,    // The work was has ended after interrupt signal. (Final State)
42         Error,                  // There was an error during the execution. (Final State)
43         Canceled;               // Work was canceled before it was started. (Final State)
44         
45         public static final EnumSet<WorkState> READY_STATE = EnumSet.of(WorkState.Ready);
46         public static final EnumSet<WorkState> WORKING_STATE = EnumSet.of(WorkState.Working);
47         public static final EnumSet<WorkState> FINAL_STATES = EnumSet.of(WorkState.Complete, WorkState.Error, WorkState.Canceled, WorkState.Interrupted);
48         public static final EnumSet<WorkState> COMPLETE_STATE = EnumSet.of(WorkState.Complete);
49         public static final EnumSet<WorkState> ERROR_STATE = EnumSet.of(WorkState.Error);
50         public static final EnumSet<WorkState> CANCELED_STATE = EnumSet.of(WorkState.Canceled);
51         public static final EnumSet<WorkState> CANCELED_STATES = EnumSet.of(WorkState.Canceled, WorkState.Interrupted, WorkState.Interrupting);
52
53         public boolean isFinalState()
54         {
55                 return FINAL_STATES.contains(this);
56         }
57         
58         public boolean isInitialState()
59         {
60                 return this == Ready;
61         }
62         
63 }