@Test
public void testDataflowVariable() throws Throwable {
final List<String> logMessages = new ArrayList<String>();
final DefaultPGroup group = new DefaultPGroup(10);
// variable can be assigned once only, read allowed multiple times
final DataflowVariable<Integer> a = new DataflowVariable<Integer>();
// group.task will use thread from pool and uses it to execute value bind
group.task(new Runnable() {
public void run() {
// first thread binding value succeeds, other attempts would fail with IllegalStateException
logMessages.add("Value bound");
a.bind(10);
}
});
// group.task will use thread from pool and uses it to execute call method
final Promise<?> result = group.task(new Callable() {
public Object call() throws Exception {
// getVal will wait for the value to be assigned
final int result = a.getVal() + 10;
logMessages.add("Value calculated");
return result;