1 31 package org.objectweb.proactive.examples.readers; 32 33 public class ReaderDisplay implements org.objectweb.proactive.InitActive { 34 35 private AppletReader applet; 36 private ReaderWriter rw; 37 private Reader readers[]; 38 private Writer writers[]; 39 40 41 public ReaderDisplay() { 42 } 43 44 45 public ReaderDisplay(AppletReader applet) { 46 this.applet = applet; 47 } 48 49 50 public void initActivity(org.objectweb.proactive.Body body) { 51 readers = new Reader[3]; 52 writers = new Writer[3]; 53 54 Object param[] = new Object [] { 55 org.objectweb.proactive.ProActive.getStubOnThis(), 56 new Integer (ReaderWriter.DEFAULT_POLICY) 57 }; 58 try { 59 rw = (ReaderWriter)org.objectweb.proactive.ProActive.newActive(ReaderWriter.class.getName(), param); 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 64 param = new Object [3]; 65 param[0] = org.objectweb.proactive.ProActive.getStubOnThis(); 66 param[1] = rw; 67 for (int i = 0; i < 3; i++) { 68 param[2] = new Integer (i); 69 try { 70 readers[i] = (Reader)org.objectweb.proactive.ProActive.newActive(Reader.class.getName(), param); 72 writers[i] = (Writer)org.objectweb.proactive.ProActive.newActive(Writer.class.getName(), param); 74 } catch (Exception e) { 75 e.printStackTrace(); 76 } 77 } 78 } 79 80 81 public void setRead(int id, boolean state) { 82 applet.readerPanel.setRead(id, state); 83 } 84 85 86 public void setWait(int id, boolean isReader) { 87 applet.readerPanel.setWait(id, isReader); 88 } 89 90 91 public void setWrite(int id, boolean state) { 92 applet.readerPanel.setWrite(id, state); 93 } 94 95 96 public void setPolicy(int policy) { 97 if (policy < 3 && policy > -1) 98 rw.setPolicy(policy); 99 } 100 } | Popular Tags |