package org.mikeneck.jcsp; import org.jcsp.lang.*; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author : mike * @since : 12/07/07 */ public class JcspTest { private static Logger logger = LoggerFactory.getLogger(JcspTest.class); @Test public void test () { One2OneChannel channel = Channel.one2one(); Parallel parallel = new Parallel(new CSProcess[]{ new Send(channel.out()), new Read(channel.in())}); parallel.run(); } class Send implements CSProcess { private ChannelOutput output; Send (ChannelOutput output) { this.output = output; } @Override public void run() { for (int i = 0; i < 10; i += 1) { logger.info("Sending value {}", String.valueOf(i)); output.write(i); try { Thread.sleep(200L); } catch (InterruptedException e) { } } } } class Read implements CSProcess { private ChannelInput input; Read (ChannelInput input) { this.input = input; } @Override public void run() { int read = 0; while (read < 10 -1) { read = input.read(); logger.info("Receiving value {}", String.valueOf(read)); try { Thread.sleep(500L); } catch (InterruptedException e) { } } } } }