1 31 package org.objectweb.proactive.examples.doctor; 32 33 import org.apache.log4j.Logger; 34 35 public class Office { 36 37 static Logger logger = Logger.getLogger(Office.class.getName()); 38 39 public static final int NB_PAT = 15; 41 42 public static final int NB_DOC = 5; 44 45 public static final int MEAN_PAT = 10000; 47 public static final int SIGM_PAT = 3000; 48 49 public static final int MEAN_DOC = 13000; 51 public static final int SIGM_DOC = 4000; 52 53 public static final int MAX_PAT = 50; 55 public static final int MAX_DOC = 20; 56 57 public static final int DOC_UNDEF = -1; 59 public static final int PAT_WELL = -2; 60 public static final int PAT_SICK = -1; 61 java.util.Vector patients; 62 java.util.Vector doctors; 63 Office me; 64 Receptionnist recept; 65 DisplayPanel display; 66 RandomTime rand; 67 OfficeWindow win; 68 69 70 public Office() { 71 } 72 73 74 public Office(Integer useLess) { 75 patients = new java.util.Vector (); 77 doctors = new java.util.Vector (); 78 79 81 win = new OfficeWindow(); 82 win.pack(); 83 win.setTitle("The Salishan problems (3)"); 84 win.show(); 85 86 display = win.getDisplay(); 87 } 88 89 90 public void init(Office _me, Receptionnist _recept) { 91 me = _me; 92 recept = _recept; 93 createPeople(); 94 } 95 96 97 public synchronized void createPeople() { 98 int i; 99 try { 100 101 rand = (RandomTime)org.objectweb.proactive.ProActive.newActive(RandomTime.class.getName(), null); 102 103 for (i = 1; i <= NB_DOC; i++) 104 addDoctor(i, MEAN_DOC, SIGM_DOC); 105 106 for (i = 1; i <= NB_PAT; i++) 107 addPatient(i, MEAN_PAT, SIGM_PAT); 108 } catch (Exception e) { 109 e.printStackTrace(); 110 } 111 } 112 113 114 public void addDoctor(int id, long meanTime, long sigmaTime) { 115 116 try { 117 Object params[] = {new Integer (id), new Long (meanTime), new Long (sigmaTime),me,rand}; 118 119 Doctor newDoc = (Doctor)org.objectweb.proactive.ProActive.newActive(Doctor.class.getName(), params); 120 doctors.insertElementAt(newDoc, id - 1); 121 recept.addDoctor(id); 122 display.addDoctor(id); 123 } catch (Exception e) { 124 e.printStackTrace(); 125 } 126 } 127 128 129 public void addPatient(int id, long meanTime, long sigmaTime) { 130 try { 131 Object params[] = {new Integer (id), new Long (meanTime), new Long (sigmaTime),me,rand}; 132 133 Patient newPat = (Patient)org.objectweb.proactive.ProActive.newActive(Patient.class.getName(), params); 134 patients.insertElementAt(newPat, id - 1); 135 display.addPatient(id); 136 Thread.yield(); 137 newPat.init(); 138 } catch (Exception e) { 139 e.printStackTrace(); 140 } 141 } 142 143 144 public synchronized void doctorCureFound(int doctor, int patient, Cure _cure) { 145 display.setPatState(patient, PAT_WELL); 146 display.setDocFinished(doctor, patient); 147 148 Patient pat = (Patient)patients.elementAt(patient - 1); 149 pat.receiveCure(_cure); 150 recept.addDoctor(doctor); 151 } 152 153 154 public synchronized void patientSick(int patient) { 155 display.setPatState(patient, PAT_SICK); 156 recept.addPatient(patient); 157 } 158 159 160 public synchronized void doctorWithPatient(int doctor, int patient) { 161 display.setPatState(patient, doctor); 162 163 Patient pat = (Patient)patients.elementAt(patient - 1); 164 Doctor doc = (Doctor)doctors.elementAt(doctor - 1); 165 166 pat.hasDoctor(doctor); 167 doc.curePatient(patient); 168 } 169 170 171 public static void main(String argv[]) { 172 logger.info("The Salishan problems : Problem 3 - The Doctor's Office"); 173 try { 174 Office off = (Office)org.objectweb.proactive.ProActive.newActive(Office.class.getName(), new Object []{new Integer (0)}); 175 Receptionnist recept = (Receptionnist)org.objectweb.proactive.ProActive.newActive(Receptionnist.class.getName(), new Object []{off}); 176 off.init(off, recept); 177 } catch (Exception e) { 178 e.printStackTrace(); 179 } 180 } 181 } 182 | Popular Tags |