001 package cnslab.cnsnetwork; 002 003 import cnslab.cnsmath.*; 004 005 /*********************************************************************** 006 * @version 007 * $Date: 2012-08-04 13:43:22 -0500 (Sat, 04 Aug 2012) $ 008 * $Rev: 104 $ 009 * $Author: croft $ 010 * @author 011 * Yi Dong 012 * @author 013 * David Wallace Croft 014 ***********************************************************************/ 015@Deprecated 016public class PMainBK implements Runnable 017{ 018 019 private Network network; 020 021 private Object lock; 022 023 private double minDelay; 024 025 private volatile boolean stop= false; 026 027 private double freq; 028 029 private double weight; 030 031 private Seed idum; 032 033 034 public PMainBK(Network network, Object lock, double minDelay, double freq, double weight, Seed idum) 035 { 036 this.network = network; 037 this.lock = lock; 038 this.minDelay = minDelay; 039 this.freq=freq; 040 this.weight=weight; 041 this.idum = idum; 042 } 043 044 045 /** 046 * @param fire from FireEvent queue 047 * @return true if the communication thread is allowed to proceed 048 */ 049 public boolean mainAllowed(FireEvent fire) 050 { 051 //other hosts not beyond safe time 052 for( int i=0; i<network.info.numTasks; i++) 053 { 054 if(network.localTime[i]>=network.localTime[network.info.numTasks]) 055 return true; 056 } 057 return false; 058 } 059 060 /** 061 *stop the thread 062 */ 063 public void stopThread() 064 { 065 stop = true; 066 } 067 068 private boolean letGo; 069 /** 070 * set a new value to letGo 071 * @param letGo the new value to be used 072 */ 073 public void setLetGo() { 074 this.letGo=true; 075 } 076 077 /** 078 * @see java.lang.Runnable#run() run 079 */ 080 public void run() { 081 FireEvent firstFire,tmpFire; 082 double tmp_firetime; 083 boolean isFire; 084 letGo=false; 085 while (!stop) 086 { 087 088 synchronized (lock) 089 { 090 // while ( !communicationAllowed(firstFire=( ((tmpFire=network.fireQueue.firstItem())!=null) ? new FireEvent(tmpFire.index, tmpFire.time) : null ))) 091 while ( !mainAllowed(firstFire=network.getFirstFireEvent()) && !letGo ) 092 { 093 try { 094 // System.out.println("Communication wait"); 095 // lock.notify(); 096 lock.wait(); 097 } 098 catch(InterruptedException ex) { 099 //TODO: Add Exception handler here 100 ex.printStackTrace(); 101 } 102 } 103 } 104 letGo=false; 105 //System.out.println("sent"); 106 network.pMainProcess(firstFire,freq,weight,idum); 107 synchronized(lock) 108 { 109 lock.notify(); 110 } 111 } // END: while 112 synchronized (lock) 113 { 114 lock.notify(); 115 } 116 } 117} 118