]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/WorkState.java b/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/WorkState.java
new file mode 100644 (file)
index 0000000..08d349c
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+\r
+package org.simantics.utils.threads.ua;\r
+\r
+import java.util.EnumSet;\r
+\r
+/**\r
+ * State of an async execution (=work)\r
+ * \r
+ * Initial states: Ready\r
+ * Final states: Complete, Canceled, Error, Interrupted\r
+ * \r
+ * State transitions:\r
+ *   Ready -> Canceled\r
+ *   Ready -> Working -> Complete\r
+ *   Ready -> Working -> Error \r
+ *   Ready -> Working -> Interrupting -> Error\r
+ *   Ready -> Working -> Interrupting -> Interrupted\r
+ * \r
+ * @see WorkMonitor\r
+ * @see Work\r
+ * @see AsyncRun\r
+ * @author Toni Kalajainen (toni.kalajainen@vtt.fi)\r
+ */\r
+public enum WorkState {\r
+\r
+       Ready,                  // Work has not been started. (Initial State)\r
+       Working,                // The work has started.\r
+       Complete,               // The work has completed. (Final State)\r
+       Interrupting,   // Interrupt signal has been sent.\r
+       Interrupted,    // The work was has ended after interrupt signal. (Final State)\r
+       Error,                  // There was an error during the execution. (Final State)\r
+       Canceled;               // Work was canceled before it was started. (Final State)\r
+       \r
+       public static final EnumSet<WorkState> READY_STATE = EnumSet.of(WorkState.Ready);\r
+       public static final EnumSet<WorkState> WORKING_STATE = EnumSet.of(WorkState.Working);\r
+       public static final EnumSet<WorkState> FINAL_STATES = EnumSet.of(WorkState.Complete, WorkState.Error, WorkState.Canceled, WorkState.Interrupted);\r
+       public static final EnumSet<WorkState> COMPLETE_STATE = EnumSet.of(WorkState.Complete);\r
+       public static final EnumSet<WorkState> ERROR_STATE = EnumSet.of(WorkState.Error);\r
+       public static final EnumSet<WorkState> CANCELED_STATE = EnumSet.of(WorkState.Canceled);\r
+       public static final EnumSet<WorkState> CANCELED_STATES = EnumSet.of(WorkState.Canceled, WorkState.Interrupted, WorkState.Interrupting);\r
+\r
+       public boolean isFinalState()\r
+       {\r
+               return FINAL_STATES.contains(this);\r
+       }\r
+       \r
+       public boolean isInitialState()\r
+       {\r
+               return this == Ready;\r
+       }\r
+       \r
+}\r