]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 \r
13 package org.simantics.utils.threads.ua;\r
14 \r
15 import java.util.Set;\r
16 import java.util.concurrent.TimeUnit;\r
17 import java.util.concurrent.TimeoutException;\r
18 \r
19 /**\r
20  * \r
21  * \r
22  * @author Toni Kalajainen (toni.kalajainen@vtt.fi)\r
23  */\r
24 public interface IStatefulObject<StateType, ErrorType extends Throwable> {\r
25 \r
26         void addStateListener(StateListener<StateType> listener);\r
27         void removeStateListener(StateListener<StateType> listener);\r
28         StateType getState();\r
29         \r
30         /**\r
31          * Wait until state changes to one of the given states.\r
32          * \r
33          * @param set states that ends waiting  \r
34          * @throws InterruptedException\r
35          * @return the state in the given set that broke the wait \r
36          */\r
37         StateType waitForState(Set<StateType> set) \r
38         throws InterruptedException, ErrorType;\r
39         \r
40         /**\r
41          * Wait until state changes to one of the given states.\r
42          * \r
43          * @param set states that ends waiting  \r
44          * @return the state in the given set that broke the wait \r
45          */\r
46         StateType waitForStateUninterruptibly(Set<StateType> set) \r
47         throws ErrorType;       \r
48         \r
49         \r
50         /**\r
51          * Wait until state changes to one of the given states or until\r
52          * time out occurs. \r
53          * \r
54          * @param set\r
55          * @param timeout\r
56          * @param unit\r
57          * @return state one in set\r
58          * @throws InterruptedException thread was interrupted\r
59          * @throws TimeoutException timeout occured\r
60          */\r
61         StateType waitForState(Set<StateType> set, long timeout, TimeUnit unit) \r
62         throws InterruptedException, TimeoutException, ErrorType;\r
63 \r
64         /**\r
65          * Get error state or null\r
66          * @return error\r
67          */\r
68         ErrorType getError();\r
69         \r
70 }\r