]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/IStatefulObject.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / ua / IStatefulObject.java
diff --git a/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/IStatefulObject.java b/bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/IStatefulObject.java
new file mode 100644 (file)
index 0000000..c05c064
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************\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.Set;\r
+import java.util.concurrent.TimeUnit;\r
+import java.util.concurrent.TimeoutException;\r
+\r
+/**\r
+ * \r
+ * \r
+ * @author Toni Kalajainen (toni.kalajainen@vtt.fi)\r
+ */\r
+public interface IStatefulObject<StateType, ErrorType extends Throwable> {\r
+\r
+       void addStateListener(StateListener<StateType> listener);\r
+       void removeStateListener(StateListener<StateType> listener);\r
+       StateType getState();\r
+       \r
+       /**\r
+        * Wait until state changes to one of the given states.\r
+        * \r
+        * @param set states that ends waiting  \r
+        * @throws InterruptedException\r
+        * @return the state in the given set that broke the wait \r
+        */\r
+       StateType waitForState(Set<StateType> set) \r
+       throws InterruptedException, ErrorType;\r
+       \r
+       /**\r
+        * Wait until state changes to one of the given states.\r
+        * \r
+        * @param set states that ends waiting  \r
+        * @return the state in the given set that broke the wait \r
+        */\r
+       StateType waitForStateUninterruptibly(Set<StateType> set) \r
+       throws ErrorType;       \r
+       \r
+       \r
+       /**\r
+        * Wait until state changes to one of the given states or until\r
+        * time out occurs. \r
+        * \r
+        * @param set\r
+        * @param timeout\r
+        * @param unit\r
+        * @return state one in set\r
+        * @throws InterruptedException thread was interrupted\r
+        * @throws TimeoutException timeout occured\r
+        */\r
+       StateType waitForState(Set<StateType> set, long timeout, TimeUnit unit) \r
+       throws InterruptedException, TimeoutException, ErrorType;\r
+\r
+       /**\r
+        * Get error state or null\r
+        * @return error\r
+        */\r
+       ErrorType getError();\r
+       \r
+}\r