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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
13 package org.simantics.utils.threads.ua;
\r
15 import java.util.Set;
\r
16 import java.util.concurrent.TimeUnit;
\r
17 import java.util.concurrent.TimeoutException;
\r
22 * @author Toni Kalajainen (toni.kalajainen@vtt.fi)
\r
24 public interface IStatefulObject<StateType, ErrorType extends Throwable> {
\r
26 void addStateListener(StateListener<StateType> listener);
\r
27 void removeStateListener(StateListener<StateType> listener);
\r
28 StateType getState();
\r
31 * Wait until state changes to one of the given states.
\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
37 StateType waitForState(Set<StateType> set)
\r
38 throws InterruptedException, ErrorType;
\r
41 * Wait until state changes to one of the given states.
\r
43 * @param set states that ends waiting
\r
44 * @return the state in the given set that broke the wait
\r
46 StateType waitForStateUninterruptibly(Set<StateType> set)
\r
51 * Wait until state changes to one of the given states or until
\r
57 * @return state one in set
\r
58 * @throws InterruptedException thread was interrupted
\r
59 * @throws TimeoutException timeout occured
\r
61 StateType waitForState(Set<StateType> set, long timeout, TimeUnit unit)
\r
62 throws InterruptedException, TimeoutException, ErrorType;
\r
65 * Get error state or null
\r
68 ErrorType getError();
\r