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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
13 package org.simantics.utils.threads.ua;
\r
15 import java.util.EnumSet;
\r
18 * State of an async execution (=work)
\r
20 * Initial states: Ready
\r
21 * Final states: Complete, Canceled, Error, Interrupted
\r
23 * State transitions:
\r
25 * Ready -> Working -> Complete
\r
26 * Ready -> Working -> Error
\r
27 * Ready -> Working -> Interrupting -> Error
\r
28 * Ready -> Working -> Interrupting -> Interrupted
\r
33 * @author Toni Kalajainen (toni.kalajainen@vtt.fi)
\r
35 public enum WorkState {
\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
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
53 public boolean isFinalState()
\r
55 return FINAL_STATES.contains(this);
\r
58 public boolean isInitialState()
\r
60 return this == Ready;
\r