1 23 24 package org.objectweb.fractal.julia.control.lifecycle; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.NoSuchInterfaceException; 28 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 29 30 import org.objectweb.fractal.julia.control.content.Util; 31 32 import java.util.ArrayList ; 33 import java.util.List ; 34 35 46 47 public abstract class BasicLifeCycleCoordinatorMixin 48 implements LifeCycleCoordinator 49 { 50 51 55 private BasicLifeCycleCoordinatorMixin () { 56 } 57 58 62 65 66 public List fcActive; 67 68 77 78 public void setFcState (final boolean started) 79 throws IllegalLifeCycleException 80 { 81 Component thisComponent; 83 try { 84 thisComponent = (Component)_this_weaveableC.getFcInterface("component"); 85 } catch (NoSuchInterfaceException e) { 86 throw new ChainedIllegalLifeCycleException( 87 e, _this_weaveableC, "Cannot set the lifecycle state"); 88 } 89 List allSubComponents = Util.getAllSubComponents(thisComponent); 90 91 for (int i = 0; i < allSubComponents.size(); ++i) { 93 Component c = (Component)allSubComponents.get(i); 94 LifeCycleCoordinator lc; 95 try { 96 lc = (LifeCycleCoordinator)c.getFcInterface("lifecycle-controller"); 97 } catch (Exception e) { 98 try { 99 lc = (LifeCycleCoordinator)c.getFcInterface("/lifecycle-coordinator"); 100 } catch (NoSuchInterfaceException f) { 101 continue; 102 } 103 } 104 if (started) { 105 lc.setFcStarted(); 106 } else { 107 lc.setFcStopped(); 108 } 109 } 110 } 111 112 public boolean fcActivated (final LifeCycleCoordinator component) { 113 synchronized (fcActive) { 114 if (fcActive.size() > 0) { 116 if (!fcActive.contains(component)) { 117 fcActive.add(component); 118 } 119 return true; 120 } 121 return false; 122 } 123 } 124 125 public void fcInactivated (final LifeCycleCoordinator component) { 126 synchronized (fcActive) { 127 fcActive.remove(component); 128 fcActive.notifyAll(); 130 } 131 } 132 133 145 146 public void stopFc (final LifeCycleCoordinator[] components) 147 throws IllegalLifeCycleException 148 { 149 fcActive = new ArrayList (); 151 for (int i = 0; i < components.length; ++i) { 152 if (components[i].getFcState().equals(STARTED)) { 153 fcActive.add(components[i]); 154 } 155 } 156 LifeCycleCoordinator c; 158 try { 159 c = (LifeCycleCoordinator)_this_weaveableC. 160 getFcInterface("lifecycle-controller"); 161 } catch (Exception e) { 162 try { 163 c = (LifeCycleCoordinator)_this_weaveableC. 164 getFcInterface("/lifecycle-coordinator"); 165 } catch (NoSuchInterfaceException f) { 166 throw new ChainedIllegalLifeCycleException( 167 f, _this_weaveableC, "Cannot stop components"); 168 } 169 } 170 for (int i = 0; i < components.length; ++i) { 171 if (components[i].getFcState().equals(STARTED)) { 172 components[i].setFcStopping(c); 173 } 174 } 175 synchronized (fcActive) { 177 while (fcActive.size() > 0) { 178 try { 179 fcActive.wait(); 180 } catch (InterruptedException e) { 181 } 182 } 183 } 184 for (int i = 0; i < components.length; ++i) { 186 if (components[i].getFcState().equals(STARTED)) { 187 components[i].setFcStopped(); 188 } 189 } 190 fcActive = null; 191 } 192 193 197 202 203 public Component _this_weaveableC; 204 } 205 | Popular Tags |