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