1 31 package org.objectweb.proactive.examples.penguin; 32 33 import org.objectweb.proactive.Body; 34 import org.objectweb.proactive.ProActive; 35 import org.objectweb.proactive.core.config.ProActiveConfiguration; 36 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 37 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 38 import org.objectweb.proactive.core.util.CircularArrayList; 39 import org.objectweb.proactive.ext.migration.MigrationStrategyManagerImpl; 40 41 42 public class PenguinControler implements org.objectweb.proactive.RunActive, PenguinMessageReceiver, java.io.Serializable { 43 44 private transient PenguinApplet display; 46 protected CircularArrayList penguinList; 47 String [] args; 48 private MigrationStrategyManagerImpl myStrategyManager; 49 50 51 public PenguinControler() { 52 } 53 54 55 public PenguinControler(String [] args) { 56 this.penguinList = new CircularArrayList(20); 57 this.args = args; 58 try { 59 ProActive.turnActive(this); 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 } 64 65 66 public void rebuild() { 67 this.display = new PenguinApplet((PenguinControler) ProActive.getStubOnThis(), penguinList); 68 } 69 70 71 public void clean() { 72 if (display != null) { 73 display.dispose(); 74 display = null; 75 } 76 } 77 78 79 public void receiveMessage(String s) { 80 display.receiveMessage(s); 81 } 82 83 84 public void receiveMessage(String s, java.awt.Color c) { 85 display.receiveMessage(s, c); 86 } 87 88 public Penguin createPenguin(int n) { 89 try { 90 Penguin newPenguin = (Penguin) org.objectweb.proactive.ProActive.newActive(Penguin.class.getName(), new Object [] { new Integer (n) }); 91 newPenguin.initialize(args); 92 newPenguin.setControler((PenguinControler) ProActive.getStubOnThis()); 93 return newPenguin; 94 } catch (Exception e) { 95 e.printStackTrace(); 96 return null; 97 } 98 } 99 100 public void runActivity(Body b) { 101 org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(b); 102 myStrategyManager = new MigrationStrategyManagerImpl((org.objectweb.proactive.core.body.migration.Migratable) b); 103 myStrategyManager.onDeparture("clean"); 104 rebuild(); 105 service.fifoServing(); 106 clean(); 107 } 108 109 110 public static void main(String args[]) { 112 ProActiveConfiguration.load(); 113 121 ProActiveDescriptor proActiveDescriptor=null; 123 try{ 124 proActiveDescriptor=ProActive.getProactiveDescriptor("file:"+args[0]); 125 proActiveDescriptor.activateMappings(); 126 VirtualNode vn1 = proActiveDescriptor.getVirtualNode("penguinNode"); 127 String [] nodes = vn1.getNodesURL(); 129 new PenguinControler(nodes); 130 }catch(Exception e){ 131 e.printStackTrace(); 132 } 133 134 } 135 136 } 162 | Popular Tags |