]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/Worker.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / ua / Worker.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 package org.simantics.utils.threads.ua;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 /**\r
17  * Worker executes tasks. \r
18  * <p>\r
19  * Hint! To execute work synchronously use: <BR>\r
20  *  Worker.asyncExec(runnable, null).waitForState(WorkState.FINAL_STATES);\r
21  * <p>\r
22  * To cancel all work get the work with getQueuedWork() and invoke cancel() to each.\r
23  * \r
24  * @see SynchronizedWorker\r
25  * @see ThreadPool\r
26  * @author Toni Kalajainen (toni.kalajainen@vtt.fi)\r
27  */\r
28 public interface Worker extends StatefulExecutor {\r
29         \r
30         /**\r
31          * Execute work (async).\r
32          * \r
33          * @param runnable\r
34          * @param initialListener listener initially set on monitor object or null\r
35          * @return async work monitor object\r
36          */\r
37         WorkMonitor asyncExec(Runnable runnable, StateListener<WorkState> initialListener)\r
38         throws WorkerClosedException;\r
39 \r
40         /**\r
41          * Get a list of all queued work.\r
42          * @param result queued work.\r
43          */\r
44         void getQueuedWork(Collection<WorkMonitor> result);\r
45 \r
46 }\r