KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Helloworld > HelloWorld


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  *******************************************************************************
20  * BASED ON :
21  * Fractal ADL Parser
22  * Copyright (C) 2002-2004 France Telecom R&D
23  *
24  * This library is free software; you can redistribute it and/or
25  * modify it under the terms of the GNU Lesser General Public
26  * License as published by the Free Software Foundation; either
27  * version 2 of the License, or (at your option) any later version.
28  *
29  * This library is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32  * Lesser General Public License for more details.
33  *
34  * You should have received a copy of the GNU Lesser General Public
35  * License along with this library; if not, write to the Free Software
36  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37  *
38  * Contact: Eric.Bruneton@rd.francetelecom.com
39  *
40  * Author: Eric Bruneton
41  *******************************************************************************
42  *
43  * Contact: dream@objectweb.org
44  */

45
46 import java.util.HashMap JavaDoc;
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 /**
54  * Entry point
55  */

56 public class Helloworld
57 {
58
59   public static void main(String JavaDoc[] args) throws Exception JavaDoc
60   {
61     Component hw = (Component) FactoryFactory.getFactory().newComponent(
62         "HelloWorld", new HashMap JavaDoc());
63     Fractal.getLifeCycleController(hw).startFc();
64     System.out.println("Call Run method");
65     new Thread JavaDoc(new HWTheread((Runnable JavaDoc) 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 JavaDoc());
73     System.out.println("Restart component");
74     Fractal.getLifeCycleController(hw).startFc();
75   }
76
77   static class HWTheread implements Runnable JavaDoc
78   {
79
80     Runnable JavaDoc runItf;
81
82     HWTheread(Runnable JavaDoc 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 JavaDoc e)
98         {
99           e.printStackTrace();
100         }
101       }
102     }
103   }
104 }
Popular Tags