Mercurial > hg > Members > shoshi > distributedalgorithm
view src/main/java/suikwasha/distributedalgorithm/machines/SimpleMachineBuilder.java @ 0:38a110b13db1
added SimpleDistributedAlgorithmFramework.
added NaiveAlgorithm
added ChangRobertsAlgorithm
added PertersonAlgorithm
author | suikwasha |
---|---|
date | Fri, 19 Oct 2012 00:05:41 +0900 |
parents | |
children | 8e1f63faa2fd |
line wrap: on
line source
package suikwasha.distributedalgorithm.machines; import fj.data.List; import suikwasha.distributedalgorithm.framework.Context; import suikwasha.distributedalgorithm.framework.Algorithm; import suikwasha.distributedalgorithm.framework.Machine; import suikwasha.distributedalgorithm.framework.MachineBuilder; import suikwasha.distributedalgorithm.framework.Port; public class SimpleMachineBuilder implements MachineBuilder { public Machine createMachine(Algorithm _algo) { return new MachineImpl(_algo); } private static class MachineImpl extends Machine { private List<Port> ports; private final Algorithm algo; public MachineImpl(Algorithm _algo) { ports = List.nil(); algo = _algo; } public void addPort(Port _p) { ports = ports.snoc(_p); } public void run() { algo.execute(new ContextImpl(ports)); } } private static class ContextImpl implements Context { public List<Port> ports; public ContextImpl(List<Port> _ports) { ports = _ports; } public Iterable<Port> getPorts() { return ports; } } }