01: package org.obe.runtime.strategy;
02:
03: import java.security.Principal;
04: import org.obe.spi.WorkflowContext;
05: import org.wfmc.wapi.WMWorkflowException;
06:
07: /**
08: * Assigns work items on a random basis.
09: *
10: * @author Adrian Price
11: */
12: public class RandomAssignmentStrategy extends
13: AbstractAssignmentStrategy {
14: public RandomAssignmentStrategy() {
15: }
16:
17: public Principal[] apply(Principal[] candidates,
18: boolean expandGroups, WorkflowContext ctx)
19: throws WMWorkflowException {
20:
21: if (candidates.length == 0)
22: return candidates;
23:
24: if (expandGroups)
25: candidates = expandGroups(candidates);
26:
27: // TODO: randomize only when the first work item is created.
28:
29: // Select one of the candidates at random.
30: int index = (int) (Math.random() * candidates.length);
31: if (index == candidates.length)
32: index--;
33:
34: return new Principal[] { candidates[index] };
35: }
36: }
|