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