1 31 package org.objectweb.proactive.examples.boundedbuffer; 32 33 public class ActiveDisplay implements ConsumerProducerListener { 34 35 transient private AppletBuffer applet; 36 transient private BoundedBuffer buffer; 37 transient private Consumer consumer; 38 transient private Producer producer; 39 transient private int size; 40 41 42 public ActiveDisplay() { 43 } 44 45 46 public ActiveDisplay(int size, AppletBuffer applet) { 47 this.applet = applet; 49 this.size = size; 50 displayMessage("Active display created"); 51 } 52 53 54 public void start() { 55 displayMessage("ActiveDisplay start : Creating active objects"); 56 57 Object o = org.objectweb.proactive.ProActive.getStubOnThis(); 59 60 try { 62 buffer = (BoundedBuffer)org.objectweb.proactive.ProActive.newActive(BoundedBuffer.class.getName(), new Object []{new Integer (size), o}); 63 } catch (Exception e) { 64 } 65 66 if (buffer == null) { 67 displayMessage("Error while creating active objects"); 68 applet.kill(); 69 } 70 71 displayMessage("Creating producer..."); 73 try { 74 producer = (Producer)org.objectweb.proactive.ProActive.newActive(Producer.class.getName(), new Object []{o, buffer}); 75 } catch (Exception e) { 76 } 77 78 displayMessage("Creating Consumer..."); 80 try { 81 consumer = (Consumer)org.objectweb.proactive.ProActive.newActive(Consumer.class.getName(), new Object []{o, buffer}); 82 } catch (Exception e) { 83 } 84 displayMessage("Remote objects created..."); 85 } 86 87 88 public void done() { 89 producer.done(); 90 consumer.done(); 91 producer = null; 92 consumer = null; 93 buffer = null; 94 } 95 96 97 public void update(int pos, String str) { 98 if (str == null) { 99 applet.setOut(pos, false); 100 } else { 101 applet.setIn(pos, false); 102 } 103 applet.setCell(pos, str); 104 } 105 106 107 public void toggleCons() { 108 applet.receiveMessage("toggle Consumer"); 109 consumer.toggle(); 110 } 111 112 113 public void toggleProd() { 114 displayMessage("toggle Producer"); 115 producer.toggle(); 116 } 117 118 119 public void setOut(int pos) { 120 applet.setOut(pos, true); 121 } 122 123 124 public void setIn(int pos) { 125 applet.setIn(pos, true); 126 } 127 128 129 public void displayMessage(String msg) { 133 applet.receiveMessage(msg); 134 } 135 136 137 public void consumerStartRunning() { 138 applet.consumerStartRunning(); 139 } 140 141 142 public void consumerStopRunning() { 143 applet.consumerStopRunning(); 144 } 145 146 147 public void producerStartRunning() { 148 applet.producerStartRunning(); 149 } 150 151 152 public void producerStopRunning() { 153 applet.producerStopRunning(); 154 } 155 } | Popular Tags |