replace Callback with Callable/Pausable
[org.ibex.util.git] / src / org / ibex / util / Pausable.java
diff --git a/src/org/ibex/util/Pausable.java b/src/org/ibex/util/Pausable.java
new file mode 100644 (file)
index 0000000..b61ccfa
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
+package org.ibex.util;
+
+/** Provides a generic interface for an object that can be both called
+ *  with a given argument and paused. */
+public interface Pausable extends Callable {
+    /** Executes or unpauses the task. */
+    public Object run(Object o) throws Exception, AlreadyRunningException;
+
+    /** Pauses the running task at its convienience. */
+    public void pause() throws NotPausableException;
+
+    public static class NotPausableException extends IllegalStateException {
+        public NotPausableException() {}
+        public NotPausableException(String msg) { super(msg); }
+    }
+    public static class AlreadyRunningException extends IllegalStateException {
+        public AlreadyRunningException() {}
+        public AlreadyRunningException(String msg) { super(msg); }
+    }
+}