- Timestamp:
- 10/02/07 12:49:26 (1 year ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/multithread/src/planet/generic/commonapi/MultiThreadedNetworkImpl.java
r20 r28 61 61 * Containts all nodes to remove from the network. 62 62 */ 63 private Stack toRemove;63 private Stack<NodeHandle> toRemove; 64 64 /** 65 65 * NodeFactory implementation which permits build new nodes. … … 80 80 81 81 private final int PROCESSORS; 82 private final Thread[] threads; 83 private final ProcessGroup[] processGroups; 84 // private final Boolean[] continues; 82 85 /** 83 86 * Initialize the network with no nodes and wihtout simulation steps. … … 85 88 public MultiThreadedNetworkImpl() { 86 89 PROCESSORS = Properties.simulatorProcessors; 90 threads = new Thread[PROCESSORS]; 91 processGroups = new ProcessGroup[PROCESSORS]; 92 for (int i = 0; i < processGroups.length; i++) { 93 processGroups[i] = new ProcessGroup(); 94 } 95 // continues = new Boolean[PROCESSORS]; 87 96 nodes = new HashMap<NodeHandle, Node>(); //to contain all nodes 88 97 toRemove = new Stack<NodeHandle>(); … … 553 562 554 563 555 Thread[] threads = new Thread[PROCESSORS];564 556 565 Node[] nodes = new Node[this.nodes.size()]; 557 566 nodes = this.nodes.values().toArray(nodes); 558 Boolean[] continues = new Boolean[PROCESSORS]; 559 //init continues 560 for (int i = 0; i < continues.length; i++) { 561 continues[i] = false; 562 } 567 568 563 569 564 570 … … 568 574 569 575 int from = i*groupSize; 576 570 577 //if it is the last thread it gets all remaining nodes, i.e. 7 nodes and two processors groupA {0..2} and groupB {3..6} 571 int to = i==threads.length-1 ? nodes.length : from+groupSize; 572 ProcessGroup group = new ProcessGroup(nodes,from,to,continues,i); 573 Thread thread = new Thread(group); 574 threads[i] = thread; 578 int to = i==threads.length-1 ? nodes.length : from+groupSize; 579 580 //ProcessGroup group = new ProcessGroup(nodes,from,to,continues,i); 581 processGroups[i].setFrom(from); 582 processGroups[i].setTo(to); 583 processGroups[i].setNodes(nodes); 584 threads[i] = new Thread(processGroups[i]); 585 586 575 587 } 576 588 //start all threads … … 595 607 aNode = (Node)it.next(); 596 608 // always process the node 597 if (!aNode.isAlive()) { //the node has failed or le aved??609 if (!aNode.isAlive()) { //the node has failed or left?? 598 610 toRemove.add(aNode.getLocalHandle()); 599 611 } 600 612 } 601 613 boolean toContinue = false; 602 for ( Boolean b : continues) {603 toContinue |= b;614 for (int i = 0; i < processGroups.length; i++) { 615 toContinue |= processGroups[i].isToContinue(); 604 616 } 605 617 return toContinue; … … 836 848 private Node[] nodes = null; 837 849 private int from,to; 838 private Boolean[] continues = null;839 private int nr;850 // private int nr; 851 private boolean toContinue; 840 852 /** 841 853 * … … 846 858 * @param nr the positon where to set in <b>conitues</b> <code>true</code> or <code>false</code> 847 859 */ 848 public ProcessGroup(Node[] nodes, int from, int to, 849 Boolean[] continues, int nr) { 850 super(); 851 this.nodes = nodes; 852 this.from = from; 853 this.to = to; 854 this.continues = continues; 855 this.nr = nr; 856 } 860 857 861 858 862 public void run() { 859 863 860 booleantoContinue = false;864 toContinue = false; 861 865 for (int i = from; i < to; i++) { 862 866 Node n = nodes[i]; 863 867 toContinue |= n.process(totalSteps); 864 868 } 865 continues[nr]=toContinue;869 866 870 867 871 } 872 public void setNodes(Node[] nodes) { 873 this.nodes = nodes; 874 } 875 public void setFrom(int from) { 876 this.from = from; 877 } 878 public void setTo(int to) { 879 this.to = to; 880 } 881 public boolean isToContinue() { 882 return toContinue; 883 } 868 884 } 869 885 }
