From: crawshaw Date: Thu, 6 Jan 2005 16:06:42 +0000 (+0000) Subject: replace Callback with Callable/Pausable X-Git-Url: http://git.megacz.com/?p=org.ibex.util.git;a=commitdiff_plain;h=669021b9300969b21a7736c050b09a4f11b86afb replace Callback with Callable/Pausable darcs-hash:20050106160642-2eb37-0dae051a22bfeb22e0bad6140c735797a05e18b2.gz --- diff --git a/src/org/ibex/util/Callable.java b/src/org/ibex/util/Callable.java new file mode 100644 index 0000000..3281433 --- /dev/null +++ b/src/org/ibex/util/Callable.java @@ -0,0 +1,21 @@ +// 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 with which to call an object with a + * given argument. + * + * NOTE: State restrictions and concurrent access are implementation + * specific. All the Callable interface specifies is that an + * object is callable, not the conditions under which a call may be + * made. + * + * @see org.ibex.util.Pausable + * + */ +public interface Callable { + /** Calls the object with a given argument. */ + public Object run(Object o) throws Exception; +} diff --git a/src/org/ibex/util/Callback.java b/src/org/ibex/util/Callback.java deleted file mode 100644 index c56bb77..0000000 --- a/src/org/ibex/util/Callback.java +++ /dev/null @@ -1,12 +0,0 @@ -// 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; - -/** a simple interface for callbacks*/ -public interface Callback { - - public abstract Object call(Object arg); - -} diff --git a/src/org/ibex/util/Pausable.java b/src/org/ibex/util/Pausable.java new file mode 100644 index 0000000..b61ccfa --- /dev/null +++ b/src/org/ibex/util/Pausable.java @@ -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); } + } +}