Mercurial > hg > Members > shoshi > distributedalgorithm
comparison src/main/java/suikwasha/distributedalgorithm/simulator/SyncMachineBuilder.java @ 0:38a110b13db1
added SimpleDistributedAlgorithmFramework.
added NaiveAlgorithm
added ChangRobertsAlgorithm
added PertersonAlgorithm
author | suikwasha |
---|---|
date | Fri, 19 Oct 2012 00:05:41 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:38a110b13db1 |
---|---|
1 package suikwasha.distributedalgorithm.simulator; | |
2 | |
3 import suikwasha.distributedalgorithm.framework.Algorithm; | |
4 import suikwasha.distributedalgorithm.framework.Machine; | |
5 import suikwasha.distributedalgorithm.framework.MachineBuilder; | |
6 import suikwasha.distributedalgorithm.framework.Port; | |
7 | |
8 public class SyncMachineBuilder implements MachineBuilder | |
9 { | |
10 private final MachineBuilder builder; | |
11 private final Synchronizer synchronizer; | |
12 | |
13 public SyncMachineBuilder(MachineBuilder _builder) | |
14 { | |
15 builder = _builder; | |
16 synchronizer = new Synchronizer(); | |
17 } | |
18 | |
19 public Machine createMachine(Algorithm _algo) | |
20 { | |
21 Machine newMachine = builder.createMachine(_algo); | |
22 synchronizer.countup(); | |
23 return new SyncMachine(synchronizer,newMachine); | |
24 } | |
25 | |
26 public Synchronizer getSynchronizer() | |
27 { | |
28 return synchronizer; | |
29 } | |
30 | |
31 private static class SyncMachine extends Machine | |
32 { | |
33 private final Synchronizer synchronizer; | |
34 private final Machine machine; | |
35 | |
36 public SyncMachine(Synchronizer _synchronizer,Machine _machine) | |
37 { | |
38 synchronizer = _synchronizer; | |
39 machine = _machine; | |
40 } | |
41 | |
42 public void addPort(Port _p) | |
43 { | |
44 machine.addPort(_p); | |
45 } | |
46 | |
47 public void run() | |
48 { | |
49 machine.run(); | |
50 synchronizer.countdown(); | |
51 } | |
52 } | |
53 } |