标签:
问题来源 非常感谢@doctorwho的问题:1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class StepFirstWorker extends AbstractWorker { public StepFirstWorker() throws RemoteException { super("first"); } @Override protected Warehouse doWork(Work work) throws RemoteException { System.out.println(String.format("%s 构建底盘完成.", work.getInputWarehouse().get("carType"))); Warehouse outputWarehouse = work.getInputWarehouse(); outputWarehouse.put("baseInfo", "something about baseInfo"); return outputWarehouse; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public abstract class StepThirdWorker extends AbstractWorker { public StepThirdWorker() throws RemoteException { super("third"); } protected boolean acceptMyWork(Work work) { String workClass = work.getInputWarehouse().get("class"); if (workClass != null) { return true; } return false; } protected Warehouse doMyWork(Work work) throws RemoteException { System.out.println(String.format("Base:%s ", work.getInputWarehouse().get("baseInfo"))); System.out.println(String.format("%s is Ok", work.getInputWarehouse().get("class"))); return work.getInputWarehouse(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public class StepSecondEngineWorker extends StepSecondWorker { public static final String ENGINE = "engine"; public StepSecondEngineWorker() throws RemoteException { super(); } public boolean acceptWork(Work work) { return acceptMyWork(work); } protected Warehouse doWork(Work work) throws RemoteException { return super.doMyWork(work); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public class StepSecondSeatWorker extends StepSecondWorker { public static final String SEAT = "seat"; public StepSecondSeatWorker() throws RemoteException { super(); } public boolean acceptWork(Work work) { return acceptMyWork(work); } protected Warehouse doWork(Work work) throws RemoteException { return super.doMyWork(work); } } <div> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class StepSecondTyreWorker extends StepSecondWorker { public static final String TYRE = "tyre"; public StepSecondTyreWorker() throws RemoteException { super(); } public boolean acceptWork(Work work) { return acceptMyWork(work); } protected Warehouse doWork(Work work) throws RemoteException { return super.doMyWork(work); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public abstract class StepThirdWorker extends AbstractWorker { public StepThirdWorker() throws RemoteException { super("third"); } protected boolean acceptMyWork(Work work) { String workClass = work.getInputWarehouse().get("class"); if (workClass != null) { return true; } return false; } protected Warehouse doMyWork(Work work) throws RemoteException { System.out.println(String.format("Base:%s ", work.getInputWarehouse().get("baseInfo"))); System.out.println(String.format("%s is Ok", work.getInputWarehouse().get("class"))); return work.getInputWarehouse(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class StepThirdDoorWorker extends StepThirdWorker { public static final String DOOR = "door"; public StepThirdDoorWorker() throws RemoteException { super(); } public boolean acceptWork(Work work) { return acceptMyWork(work); } @Override protected Warehouse doWork(Work work) throws RemoteException { return super.doMyWork(work); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public class StepThirdRoofWorker extends StepThirdWorker { public static final String ROOF = "roof"; public StepThirdRoofWorker() throws RemoteException { super(); } public boolean acceptWork(Work work) { return acceptMyWork(work); } protected Warehouse doWork(Work work) throws RemoteException { return super.doMyWork(work); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public class SecondWorkSplitter implements WorkSplitter { public List<Warehouse> split(Work work, List<Worker> workers) throws RemoteException { List<Warehouse> list = new ArrayList<Warehouse>(); list.add(getWareHouse(work.getInputWarehouse(), "engine")); list.add(getWareHouse(work.getInputWarehouse(), "seat")); list.add(getWareHouse(work.getInputWarehouse(), "seat")); list.add(getWareHouse(work.getInputWarehouse(), "seat")); list.add(getWareHouse(work.getInputWarehouse(), "seat")); list.add(getWareHouse(work.getInputWarehouse(), "tyre")); list.add(getWareHouse(work.getInputWarehouse(), "tyre")); list.add(getWareHouse(work.getInputWarehouse(), "tyre")); list.add(getWareHouse(work.getInputWarehouse(), "tyre")); return list; } private Warehouse getWareHouse(Warehouse inputWarehouse, String stepClass) { Warehouse warehouse = new WarehouseDefault(); warehouse.put("class", stepClass); warehouse.putSubWarehouse(inputWarehouse); return warehouse; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class ThirdWorkSplitter implements WorkSplitter { public List<Warehouse> split(Work work, List<Worker> workers) throws RemoteException { List<Warehouse> list = new ArrayList<Warehouse>(); list.add(getWareHouse(work.getInputWarehouse(), "door")); list.add(getWareHouse(work.getInputWarehouse(), "door")); list.add(getWareHouse(work.getInputWarehouse(), "door")); list.add(getWareHouse(work.getInputWarehouse(), "door")); list.add(getWareHouse(work.getInputWarehouse(), "roof")); return list; } private Warehouse getWareHouse(Warehouse inputWarehouse, String stepClass) { Warehouse warehouse = new WarehouseDefault(); warehouse.put("class", stepClass); warehouse.putSubWarehouse(inputWarehouse); return warehouse; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
public class Test { public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { JobCenter jobCenter = new JobCenterLocal(); for (int i = 0; i < 5; i++) { jobCenter.registerWorker(new StepFirstWorker()); } for (int i = 0; i < 5; i++) { jobCenter.registerWorker(new StepSecondTyreWorker()); } for (int i = 0; i < 5; i++) { jobCenter.registerWorker(new StepSecondSeatWorker()); } for (int i = 0; i < 5; i++) { jobCenter.registerWorker(new StepSecondEngineWorker()); } for (int i = 0; i < 5; i++) { jobCenter.registerWorker(new StepThirdDoorWorker()); } for (int i = 0; i < 5; i++) { jobCenter.registerWorker(new StepThirdRoofWorker()); } jobCenter.registerForeman(new ForemanSelectOneWorker("first")); <span></span> <span></span>jobCenter.registerForeman(new ForemanSelectAllWorker("second", new SecondWorkSplitter())); jobCenter.registerForeman(new ForemanSelectAllWorker("third",new ThirdWorkSplitter())); Warehouse inputWarehouse = new WarehouseDefault(); inputWarehouse.put("class", "car"); inputWarehouse.put("carType", "普桑"); WorkDefault work = new WorkDefault("first", inputWarehouse); work.setForemanType("first"); WorkDefault work2 = new WorkDefault("second"); work2.setForemanType("second"); WorkDefault work3 = new WorkDefault("third"); work3.setForemanType("third"); work.setNextWork(work2).setNextWork(work3); Warehouse warehouse = jobCenter.doWork(work); jobCenter.stop(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
普桑 构建底盘完成. -234 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:4af96b81d14a4954a6b649308d444e4c,type:second>运行开始,线程数9... -234 [id:4af96b81d14a4954a6b649308d444e4c,type:second-a763f156ffd74b5db285198d2498edcf] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-a763f156ffd74b5db285198d2498edcf>运行开始... -234 [id:4af96b81d14a4954a6b649308d444e4c,type:second-c2d2fb38ef6c4509b3a39b3e7d5c1d61] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-c2d2fb38ef6c4509b3a39b3e7d5c1d61>运行开始... -234 [id:4af96b81d14a4954a6b649308d444e4c,type:second-d624ea0a6df3409c80df6b97ab3c813b] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-d624ea0a6df3409c80df6b97ab3c813b>运行开始... -235 [id:4af96b81d14a4954a6b649308d444e4c,type:second-abdb57f0641a4727a9efa744d07cf2d1] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-abdb57f0641a4727a9efa744d07cf2d1>运行开始... -236 [id:4af96b81d14a4954a6b649308d444e4c,type:second-d6f7074f6c4a4b12bd37ec5f5c11aff8] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-d6f7074f6c4a4b12bd37ec5f5c11aff8>运行开始... -237 [id:4af96b81d14a4954a6b649308d444e4c,type:second-04db3f945b804500a2bbe2b9aabdce3b] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-04db3f945b804500a2bbe2b9aabdce3b>运行开始... Base:something about baseInfo engine is Ok Base:something about baseInfo seat is Ok -245 [id:4af96b81d14a4954a6b649308d444e4c,type:second-a763f156ffd74b5db285198d2498edcf] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-a763f156ffd74b5db285198d2498edcf>运行结束 -246 [id:4af96b81d14a4954a6b649308d444e4c,type:second-f3efba2dc7804c6cbcd5a25f42fdc177] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-f3efba2dc7804c6cbcd5a25f42fdc177>运行开始... -246 [id:4af96b81d14a4954a6b649308d444e4c,type:second-abdb57f0641a4727a9efa744d07cf2d1] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-abdb57f0641a4727a9efa744d07cf2d1>运行结束 Base:something about baseInfo seat is Ok -248 [id:4af96b81d14a4954a6b649308d444e4c,type:second-8c3b9359bcfa4de7b6e0492daab0d73a] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-8c3b9359bcfa4de7b6e0492daab0d73a>运行开始... Base:something about baseInfo tyre is Ok -250 [id:4af96b81d14a4954a6b649308d444e4c,type:second-f3efba2dc7804c6cbcd5a25f42fdc177] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-f3efba2dc7804c6cbcd5a25f42fdc177>运行结束 -250 [id:4af96b81d14a4954a6b649308d444e4c,type:second-c2d2fb38ef6c4509b3a39b3e7d5c1d61] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-c2d2fb38ef6c4509b3a39b3e7d5c1d61>运行结束 Base:something about baseInfo seat is Ok -252 [id:4af96b81d14a4954a6b649308d444e4c,type:second-869b573e226046aca8ad30765f1f300c] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-869b573e226046aca8ad30765f1f300c>运行开始... -253 [id:4af96b81d14a4954a6b649308d444e4c,type:second-8c3b9359bcfa4de7b6e0492daab0d73a] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-8c3b9359bcfa4de7b6e0492daab0d73a>运行结束 Base:something about baseInfo seat is Ok Base:something about baseInfo tyre is Ok -257 [id:4af96b81d14a4954a6b649308d444e4c,type:second-d624ea0a6df3409c80df6b97ab3c813b] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-d624ea0a6df3409c80df6b97ab3c813b>运行结束 -258 [id:4af96b81d14a4954a6b649308d444e4c,type:second-04db3f945b804500a2bbe2b9aabdce3b] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-04db3f945b804500a2bbe2b9aabdce3b>运行结束 Base:something about baseInfo tyre is Ok Base:something about baseInfo tyre is Ok -262 [id:4af96b81d14a4954a6b649308d444e4c,type:second-869b573e226046aca8ad30765f1f300c] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-869b573e226046aca8ad30765f1f300c>运行结束 -264 [id:4af96b81d14a4954a6b649308d444e4c,type:second-d6f7074f6c4a4b12bd37ec5f5c11aff8] INFO - 线程<id:4af96b81d14a4954a6b649308d444e4c,type:second-d6f7074f6c4a4b12bd37ec5f5c11aff8>运行结束 -264 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:4af96b81d14a4954a6b649308d444e4c,type:second>运行结束, 用时:30ms -333 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third>运行开始,线程数5... -334 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-ca58e9b733514c668a224875417c9d26] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-ca58e9b733514c668a224875417c9d26>运行开始... -334 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-17debef817e34c49996a2c38840f3de2] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-17debef817e34c49996a2c38840f3de2>运行开始... -334 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-af0e914cce89480987c6184a885770d5] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-af0e914cce89480987c6184a885770d5>运行开始... -334 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-3f7707cb2a224d3d8844a09271b24a07] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-3f7707cb2a224d3d8844a09271b24a07>运行开始... Base:something about baseInfo door is Ok Base:something about baseInfo door is Ok Base:something about baseInfo -338 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-ca58e9b733514c668a224875417c9d26] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-ca58e9b733514c668a224875417c9d26>运行结束 door is Ok -339 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-cfccfb37ebda4279b7552f7e060b2ddb] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-cfccfb37ebda4279b7552f7e060b2ddb>运行开始... -338 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-17debef817e34c49996a2c38840f3de2] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-17debef817e34c49996a2c38840f3de2>运行结束 Base:something about baseInfo door is Ok Base:something about baseInfo -340 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-3f7707cb2a224d3d8844a09271b24a07] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-3f7707cb2a224d3d8844a09271b24a07>运行结束 roof is Ok -340 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-af0e914cce89480987c6184a885770d5] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-af0e914cce89480987c6184a885770d5>运行结束 -342 [id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-cfccfb37ebda4279b7552f7e060b2ddb] INFO - 线程<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third-cfccfb37ebda4279b7552f7e060b2ddb>运行结束 -343 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third>运行结束, 用时:10ms |
1 2 3 |
-234 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:4af96b81d14a4954a6b649308d444e4c,type:second>运行开始,线程数9... ... -264 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:4af96b81d14a4954a6b649308d444e4c,type:second>运行结束, 用时:30ms |
1 2 3 |
-333 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third>运行开始,线程数5... ... -343 [RMI TCP Connection(1)-192.168.84.73] INFO - 线程组<id:9b0de678632d4fb8b87ae9db4b6436f8,type:third>运行结束, 用时:10ms |
标签:
原文地址:http://blog.csdn.net/j2eetop/article/details/46427779