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