KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > deploy > ServerDeploy


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
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 * CLIF $Name: $
20 *
21 * Contact: clif@objectweb.org
22 */

23
24 package org.objectweb.clif.deploy;
25
26
27 import org.objectweb.fractal.api.Component;
28 import org.objectweb.fractal.api.type.ComponentType;
29 import org.objectweb.fractal.adl.Factory;
30 import org.objectweb.fractal.adl.FactoryFactory;
31 import org.objectweb.fractal.util.Fractal;
32
33 import java.util.Map JavaDoc;
34 import java.util.HashMap JavaDoc;
35
36
37 /**
38  * Asynchronously and remotely creates a CLIF server (includes the creation of a Storage Proxy
39  * component and a Collector component).
40  * @author Bruno Dillenseger
41  */

42 public class ServerDeploy extends Thread JavaDoc
43 {
44     protected Component bootstrap;
45     protected Component clifserver = null;
46     protected boolean terminated = false;
47     static private Factory factory = null;
48
49     static
50     {
51         try
52         {
53             factory = FactoryFactory.getFactory(FactoryFactory.FRACTAL_BACKEND);
54         }
55         catch (Exception JavaDoc ex)
56         {
57             throw new Error JavaDoc("Could not get Fractal backend FactoryFactory", ex);
58         }
59     }
60
61     /**
62      * Defines a new CLIF server deployment.
63      * @param bootstrap The bootstrap component to use for creating the CLIF server.
64      */

65     public ServerDeploy(Component bootstrap)
66     {
67         super("CLIF server deployment on " + bootstrap);
68         this.bootstrap = bootstrap;
69     }
70
71
72     /**
73      * Actually performs the CLIF server deployment.
74      */

75     public synchronized void run()
76     {
77         try
78         {
79             Map JavaDoc hints = new HashMap JavaDoc();
80             hints.put("bootstrap", bootstrap);
81             clifserver = Fractal.getGenericFactory(bootstrap).newFcInstance(
82                 (ComponentType) factory.newComponentType(
83                     "org.objectweb.clif.server.api.ClifServerType",
84                     hints),
85                 "primitive",
86                 "org.objectweb.clif.server.lib.ClifServerImpl");
87         }
88         catch (Exception JavaDoc ex)
89         {
90             ex.printStackTrace(System.err);
91         }
92         terminated = true;
93         notify();
94     }
95
96
97     /**
98      * Gets the Clif server component (the call is blocked waiting for the Clif server to be
99      * actually deployed)
100      * @return the CLIF server component reference
101      */

102     public synchronized Component get()
103     {
104         while (! terminated)
105         {
106             try
107             {
108                 wait();
109             }
110             catch (InterruptedException JavaDoc ex)
111             {
112                 System.err.println(ex);
113             }
114         }
115         return clifserver;
116     }
117 }
118
Popular Tags