01: package dalma.spi;
02:
03: import dalma.Condition;
04: import dalma.Fiber;
05: import dalma.impl.FiberImpl;
06: import dalma.impl.OrCondition;
07:
08: import java.util.ArrayList;
09: import java.util.List;
10:
11: /**
12: * @author Kohsuke Kawaguchi
13: */
14: public abstract class FiberSPI<T extends Runnable> extends Fiber<T> {
15: /**
16: * Suspends the conversation.
17: *
18: * @param condition
19: * The condition to which this conversation is parked.
20: * Must not be null. This condition is resonpsible for
21: * resuming this conversation.
22: * @return
23: * This method returns when the conversation is resumed.
24: * the parameter given to {@link Condition#activate(Object)} will be
25: * returned.
26: */
27: public abstract <T> T suspend(Condition<T> condition);
28:
29: public final <T> T suspend(
30: List<? extends Condition<? extends T>> conditions) {
31: return suspend(
32: new OrCondition<T>(
33: new ArrayList<Condition<? extends T>>(
34: conditions))).getReturnValue();
35: }
36:
37: public final <T> T suspend(Condition<? extends T>... conditions) {
38: if (conditions == null)
39: throw new IllegalArgumentException("condition list is null");
40: return suspend(new OrCondition<T>(conditions)).getReturnValue();
41: }
42:
43: public abstract ConversationSPI getOwner();
44:
45: /**
46: * Returns the {@link FiberSPI} that the current thread is executing.
47: */
48: public static FiberSPI<?> currentFiber(boolean mustReturnNonNull) {
49: return FiberImpl.currentFiber(mustReturnNonNull);
50: }
51: }
|