1 45 46 import java.util.HashMap ; 47 48 import org.objectweb.dream.adl.FactoryFactory; 49 import org.objectweb.dream.adl.ReconfigurationFactory; 50 import org.objectweb.fractal.api.Component; 51 import org.objectweb.fractal.util.Fractal; 52 53 56 public class Helloworld 57 { 58 59 public static void main(String [] args) throws Exception 60 { 61 Component hw = (Component) FactoryFactory.getFactory().newComponent( 62 "HelloWorld", new HashMap ()); 63 Fractal.getLifeCycleController(hw).startFc(); 64 System.out.println("Call Run method"); 65 new Thread (new HWTheread((Runnable ) hw.getFcInterface("r"))).start(); 66 Thread.sleep(2000); 67 68 System.out.println("Stop component"); 69 Fractal.getLifeCycleController(hw).stopFc(); 70 System.out.println("Reconfigure component"); 71 ReconfigurationFactory.getReconfiguration().addComponents(hw, 72 "ReconfHelloWorld", new HashMap ()); 73 System.out.println("Restart component"); 74 Fractal.getLifeCycleController(hw).startFc(); 75 } 76 77 static class HWTheread implements Runnable 78 { 79 80 Runnable runItf; 81 82 HWTheread(Runnable runItf) 83 { 84 this.runItf = runItf; 85 } 86 87 public void run() 88 { 89 while (true) 90 { 91 runItf.run(); 92 System.out.println(); 93 try 94 { 95 Thread.sleep(1000); 96 } 97 catch (InterruptedException e) 98 { 99 e.printStackTrace(); 100 } 101 } 102 } 103 } 104 } | Popular Tags |