Show
Ignore:
Timestamp:
10/02/07 12:49:26 (1 year ago)
Author:
max
Message:
 
Location:
branches/multithread/src/planet
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • branches/multithread/src/planet/generic/commonapi/MultiThreadedNetworkImpl.java

    r20 r28  
    6161     * Containts all nodes to remove from the network. 
    6262     */ 
    63     private Stack toRemove; 
     63    private Stack<NodeHandle> toRemove; 
    6464    /** 
    6565     * NodeFactory implementation which permits build new nodes. 
     
    8080 
    8181    private final int PROCESSORS; 
     82    private final Thread[] threads; 
     83    private final ProcessGroup[] processGroups; 
     84//    private final Boolean[] continues; 
    8285    /** 
    8386     * Initialize the network with no nodes and wihtout simulation steps. 
     
    8588    public MultiThreadedNetworkImpl() { 
    8689        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]; 
    8796        nodes = new HashMap<NodeHandle, Node>();    //to contain all nodes 
    8897        toRemove = new Stack<NodeHandle>(); 
     
    553562     
    554563         
    555         Thread[] threads = new Thread[PROCESSORS]; 
     564         
    556565        Node[] nodes = new Node[this.nodes.size()]; 
    557566        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 
    563569 
    564570         
     
    568574                         
    569575                        int from = i*groupSize; 
     576                         
    570577                        //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                          
    575587                } 
    576588        //start all threads 
     
    595607          aNode = (Node)it.next(); 
    596608          // always process the node 
    597           if (!aNode.isAlive()) { //the node has failed or leaved?? 
     609          if (!aNode.isAlive()) { //the node has failed or left?? 
    598610              toRemove.add(aNode.getLocalHandle()); 
    599611          } 
    600612        } 
    601613        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(); 
    604616                } 
    605617        return toContinue; 
     
    836848        private Node[] nodes = null; 
    837849        private int from,to; 
    838         private Boolean[] continues = null; 
    839         private int nr; 
     850//      private int nr; 
     851        private boolean toContinue; 
    840852        /** 
    841853         *  
     
    846858         * @param nr the positon where to set in  <b>conitues</b> <code>true</code> or <code>false</code> 
    847859         */ 
    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         
    857861 
    858862                public void run() { 
    859863                         
    860                         boolean toContinue = false; 
     864                        toContinue = false; 
    861865                for (int i = from; i < to; i++) { 
    862866                                Node n = nodes[i]; 
    863867                                toContinue |= n.process(totalSteps); 
    864868                        } 
    865                 continues[nr]=toContinue; 
     869                 
    866870                 
    867871        } 
     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                } 
    868884    } 
    869885} 
  • branches/multithread/src/planet/generic/commonapi/behaviours/BehavioursPoolImpl.java

    r2 r28  
    9898     * Auxiliar Vector to use in the onMessage() method. 
    9999     */ 
    100     protected Vector behaviours = null; 
     100//    protected Vector behaviours = null; 
    101101    /** 
    102102     * Auxiliar Iterator to use in the onMessage() method. 
     
    357357                        whichQueue = whichQueue * BEH_MAPPINGS / 2 + (node.isLocalMessage(msg)? TRAFFIC_LOCAL: TRAFFIC_REMOTE); 
    358358                         
    359                         behaviours = beh[whichQueue][msg.getType() * Properties.behavioursNumberOfModes + msg.getMode()]; 
     359                        Vector behaviours = beh[whichQueue][msg.getType() * Properties.behavioursNumberOfModes + msg.getMode()]; 
    360360 
    361361                        if (behaviours.isEmpty()) throw new NoSuchBehaviourException(); 
  • branches/multithread/src/planet/generic/commonapi/factory/RouteMessagePoolImpl.java

    r2 r28  
    6666     * @see planet.commonapi.factory.RouteMessagePool#freeMessage(planet.commonapi.RouteMessage) 
    6767     */ 
    68     public void freeMessage(RouteMessage msg) { 
     68    public synchronized void freeMessage(RouteMessage msg) { 
    6969        if (msg == null) return; 
    7070        messages.push (msg); 
     
    8484     * @see planet.commonapi.factory.RouteMessagePool#getMessage(java.lang.String, planet.commonapi.NodeHandle, planet.commonapi.NodeHandle, int, int) 
    8585     */ 
    86     public RouteMessage getMessage(String key, NodeHandle from, NodeHandle to, 
     86    public synchronized RouteMessage getMessage(String key, NodeHandle from, NodeHandle to, 
    8787            int type, int mode) throws InitializationException { 
    8888        if (messages.size() > 0) { 
     
    117117     * @see planet.commonapi.factory.RouteMessagePool#getMessage(String, NodeHandle, NodeHandle, NodeHandle, int, int, Message, String) 
    118118     */ 
    119     public RouteMessage getMessage(String key, NodeHandle from, NodeHandle to, 
     119    public synchronized RouteMessage getMessage(String key, NodeHandle from, NodeHandle to, 
    120120            NodeHandle nextHop, int type, int mode, Message msg, String appId) 
    121121            throws InitializationException { 
  • branches/multithread/src/planet/simulate/Results.java

    r19 r28  
    2626  
    2727       
    28     public static synchronized void incStabRate() { 
     28    public static void incStabRate() { 
    2929      stabRate++; 
    3030    } 
    3131     
    32         public static synchronized void clearStabRate() { 
     32        public static void clearStabRate() { 
    3333          stabRate=0; 
    3434        } 
    3535         
    36         public static synchronized int getStabRate() { 
     36        public static int getStabRate() { 
    3737                return stabRate; 
    3838        } 
     
    5050        } 
    5151         
    52         public static synchronized int getTraffic() { 
     52        public static int getTraffic() { 
    5353          return traffic; 
    5454        }     
     
    5757         
    5858    //type --> in/out     
    59     public static synchronized void numMessagesTime(Id id, int step, int num, String type) { 
     59    public static void numMessagesTime(Id id, int step, int num, String type) { 
    6060      updateNodeStress(id,num,type); 
    6161          addMaxMessages(id,step,num,type);      
     
    138138        } 
    139139         
    140         public static synchronized void addInsert(String key,String dest) { 
     140        public static void addInsert(String key,String dest) { 
    141141                inserts.put(key,dest); 
    142142        } 
    143143         
    144         public static synchronized String getInsert(String key) { 
     144        public static String getInsert(String key) { 
    145145                return (String) inserts.get(key); 
    146146        } 
    147147 
    148         public static synchronized void resetInserts() { 
     148        public static void resetInserts() { 
    149149                inserts.clear(); 
    150150        } 
    151151         
    152         public static synchronized Hashtable getAllInserts() { 
     152        public static Hashtable getAllInserts() { 
    153153                return (Hashtable) inserts.clone(); 
    154154        } 
    155155         
    156         public static synchronized void addLookup(Id key, Id own) { 
     156        public static void addLookup(Id key, Id own) { 
    157157          lookups.put(key,own); 
    158158    } 
    159159         
    160         public static synchronized Id getLookup(Id key) {          
     160        public static Id getLookup(Id key) {       
    161161          return ((Id) lookups.get(key)); 
    162162    } 
    163163     
    164     public static synchronized void resetLookups(){ 
     164    public static void resetLookups(){ 
    165165      lookups.clear(); 
    166166    } 
    167167     
    168     public static synchronized Hashtable getAllLookups() { 
     168    public static Hashtable getAllLookups() { 
    169169      return (Hashtable) lookups.clone(); 
    170170    } 
    171171     
    172         public static synchronized void print () { 
     172        public static void print () { 
    173173          long total_in_msg = 0; 
    174174          long total_out_msg = 0; 
     
    223223         * print total and average hops 
    224224         */ 
    225         public static synchronized void printhops() { 
     225        public static void printhops() { 
    226226                Collection keys = hops.keySet(); 
    227227                Iterator  it = keys.iterator(); 
     
    255255        } 
    256256 
    257         public static synchronized int getLookup_number() { 
     257        public static int getLookup_number() { 
    258258                return lookup_number; 
    259259        } 
  • branches/multithread/src/planet/test/helloworld/DHTApplication.java

    r2 r28  
    6969         */ 
    7070        public boolean forward(Message message) { 
    71                 System.out.println("[" + appId + "] sobre [" + endPoint.getId() 
    72                                 + "]: Fent forward del missatge..."); 
     71//              System.out.println("[" + appId + "] sobre [" + endPoint.getId() 
     72//                              + "]: Fent forward del missatge..."); 
    7373                return true; 
    7474        } 
  • branches/multithread/src/planet/test/helloworld/DHTPeerTest.java

    r2 r28  
    3737                        long t2 = System.currentTimeMillis(); 
    3838                        System.out.println("Network with ["+network.size()+"] created in ["+GenericApp.timeElapsedInSeconds(t1,t2)+"] seconds and ["+steps1+"] steps\n"); 
    39                         network.prettyPrintNodes(); 
     39//                      network.prettyPrintNodes(); 
    4040                        //register to all nodes the application specified at properties 
    4141                        network.registerApplicationAll(); 
    42                         System.out.println("Application added. Making 15 'Hello World!' from random nodes....\n"); 
     42//                      System.out.println("Application added. Making 15 'Hello World!' from random nodes....\n"); 
    4343                        int steps2 =0; 
    44                         for (int i=0; i< 15; i++) 
     44                        for (int i=0; i< 1; i++) 
    4545                            steps2=sendMessage(); 
    4646                        long t3 = System.currentTimeMillis(); 
  • branches/multithread/src/planet/trivialp2p/behaviours/DataBehaviour.java

    r2 r28  
    1515public class DataBehaviour implements Behaviour { 
    1616    /* Internal atributes. */ 
    17     private TrivialNode trivialNode = null; 
     17    
    1818     
    1919    /** 
     
    4444     */ 
    4545    public void onMessage(RouteMessage msg, Node node) { 
    46         trivialNode = (TrivialNode)node; 
     46        TrivialNode trivialNode = (TrivialNode)node; 
    4747        //it is necessary build a copy; the 'msg' is free at the end of its process 
    4848        trivialNode.dispatchDataMessage(trivialNode.buildMessage(msg),TrivialNode.REQUEST,TrivialNode.REFRESH); 
  • branches/multithread/src/planet/util/KeyGen.java

    r2 r28  
    1515  } 
    1616 
    17   public String generateKey() { 
     17  public synchronized String generateKey() { 
    1818    cnt++; 
    1919    if (cnt>MAX) cnt = ini;