1 31 package org.objectweb.proactive.examples.cruisecontrol; 32 33 34 public class RoadModel implements org.objectweb.proactive.RunActive { 35 36 final static int ACTIVE = 1; 38 final static int INACTIVE = 0; 39 40 private int state = INACTIVE; 41 42 private int time = 15000; 43 44 private double alpha = 0; 45 46 Interface father; 47 48 50 51 public RoadModel() { 52 53 } 54 55 56 57 public RoadModel(Interface m_father) { 58 this.father = m_father; 59 } 60 61 62 65 public void engineOn() { 66 this.state = ACTIVE; 67 } 68 69 71 public void engineOff() { 72 this.state = INACTIVE; 73 } 74 75 76 77 78 80 private void calculateAlpha() { 81 82 time = 45000 + (int)(30000 * Math.random()); 84 father.setAlpha(alpha); 85 } 87 88 89 92 public void incAlpha() { 93 if (alpha < 0.6) 94 alpha += 0.09; 95 father.setAlpha(alpha); 96 } 99 100 101 104 public void decAlpha() { 105 if (alpha > -0.6) 106 alpha -= 0.09; 107 father.setAlpha(alpha); 108 } 111 112 113 115 116 public void runActivity(org.objectweb.proactive.Body body) { 117 org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body); 118 while (body.isActive()) { 120 try { 121 Thread.sleep(1000); 122 if (this.state == ACTIVE) 123 this.calculateAlpha(); 124 service.serveOldest(); 125 } catch (InterruptedException e) { 126 } 127 } 128 129 } 130 131 132 133 public void initialize() { 134 135 } 136 137 138 } 140 | Popular Tags |