KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Component > DCUP > DCUPComponentManagerImpl


1 /* $Id: DCUPComponentManagerImpl.java,v 1.4 2004/05/20 14:23:50 bures Exp $ */
2 package SOFA.Component.DCUP;
3
4 import SOFA.Component.ComponentLifecycleException;
5 import SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor;
6
7 /** Implementation of DCUP component manager.
8   *
9   * @author Petr Hnetynka
10   */

11 public class DCUPComponentManagerImpl extends SOFA.Component.ComponentManagerImpl implements DCUPComponentManager {
12   
13   /** Component builder */
14   ComponentBuilder builder;
15
16
17   /** Constructor */
18   public DCUPComponentManagerImpl(DeploymentDescriptor _dd, String JavaDoc _node, String JavaDoc _dockName, SOFA.SOFAnode.Run.Deployment.DeplDock _depldock, String JavaDoc _id) throws ComponentLifecycleException {
19     super(_dd, _node, _dockName, _depldock, _id);
20     System.out.println("Component manager");
21     builder = null;
22     try {
23       Class JavaDoc builderClass = loadComponentClass(dd.getImplementationClass("builder"));
24       builder = instantiateBuilder(builderClass);
25     } catch (ClassNotFoundException JavaDoc e) {
26       throw new ComponentLifecycleException("ClassNotFoundException in creation of component: "+e.getMessage(), e );
27     }
28   }
29   
30   
31   public void createComponent(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {
32
33     builder.onArrival(stateStore);
34     System.out.println("createComponent");
35   }
36
37   
38   public void destroyComponent(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {
39     if (dd.isSystem()) {
40       builder.onLeaving(stateStore);
41       for (java.util.Enumeration JavaDoc sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) {
42         try {
43           String JavaDoc sname = (String JavaDoc) sub.nextElement();
44           DCUPComponentManager scm = (DCUPComponentManager) subcomponents.getElementNamed(sname);
45           scm.destroyComponent(stateStore);
46         } catch (SOFA.Component.NamingException e) {
47           throw new ComponentLifecycleException("Error in the subcomponents", e);
48         }
49       }
50       ((ComponentBuilderImpl) builder).stopped = true;
51       builder.onLeaving(stateStore);
52       for (java.util.Enumeration JavaDoc sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) {
53         try {
54           String JavaDoc sname = (String JavaDoc) sub.nextElement();
55           DCUPComponentManager scm = (DCUPComponentManager) subcomponents.getElementNamed(sname);
56           scm.destroyComponent(stateStore);
57         } catch (SOFA.Component.NamingException e) {
58           throw new ComponentLifecycleException("Error in the subcomponents", e);
59         }
60       }
61     } else { // if it isn't system component
62
if (!builder.isStopped()) {
63         builder.onLeaving(stateStore);
64         for (java.util.Enumeration JavaDoc sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) {
65           try {
66             String JavaDoc sname = (String JavaDoc) sub.nextElement();
67             DCUPComponentManager scm = (DCUPComponentManager) subcomponents.getElementNamed(sname);
68             scm.destroyComponent(stateStore);
69           } catch (SOFA.Component.NamingException e) {
70             throw new ComponentLifecycleException("Error in the subcomponents", e);
71           }
72         }
73         ((ComponentBuilderImpl) builder).stopped = true;
74       } else {
75         for (java.util.Enumeration JavaDoc sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) {
76           try {
77             String JavaDoc sname = (String JavaDoc) sub.nextElement();
78             DCUPComponentManager scm = (DCUPComponentManager) subcomponents.getElementNamed(sname);
79             scm.destroyComponent(stateStore);
80           } catch (SOFA.Component.NamingException e) {
81             throw new ComponentLifecycleException("Error in the subcomponents", e);
82           }
83         }
84         builder.onLeaving(stateStore);
85       }
86     }
87      
88     System.out.println("destroyComponent");
89   }
90
91   
92   public void storeComponent(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {}
93   public void restoreComponent(SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {}
94
95   public void updateComponent(SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor newDeploymentDescriptor, SOFA.SOFAnode.Run.Storage stateStore) throws SOFA.Component.ComponentLifecycleException {
96     if (!builder.isUpdatable())
97       throw new SOFA.Component.ComponentLifecycleException("This component can't be updated.");
98     if (dd.getArchitectureAbsNameWithVersion().compareTo(newDeploymentDescriptor.getArchitectureAbsNameWithVersion())!=0)
99       throw new SOFA.Component.ComponentLifecycleException("Incompatible components.");
100   // destroyComponent(stateStore);
101
((SOFA.Component.ThreadIDRegistryImpl)thrRegistry).setInUpdate(true);
102     String JavaDoc id = dd.getInstanceId();
103     String JavaDoc iName = dd.getInstanceName();
104     dd = newDeploymentDescriptor;
105     ((SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl)dd).setInstanceId(id);
106     ((SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl)dd).setInstanceName(iName);
107     releaseVersion = dd.getReleaseVersion();
108  // bcl = SOFA.SOFAnode.Run.SOFABaseClassLoader.getBaseClassLoader(icl, dd.getArchitectureAbsName(), releaseVersion);
109
// ((SOFA.SOFAnode.Run.SOFABaseClassLoader) cl).setVersion(releaseVersion);
110
builder = null;
111     try {
112       Class JavaDoc builderClass = loadComponentClass(dd.getImplementationClass("builder"));
113       builder = instantiateBuilder(builderClass);
114     } catch (ClassNotFoundException JavaDoc e) {
115       throw new ComponentLifecycleException("ClassNotFoundException in creation of component: "+e.getMessage(), e );
116     }
117     createComponent(stateStore);
118     fullName = dd.getArchitectureAbsName()+"["+dd.getReleaseVersion()+"]";
119     ((SOFA.Component.ThreadIDRegistryImpl)thrRegistry).setInUpdate(false);
120   }
121
122
123   
124   /** Instantiate component builder from its class. */
125   protected ComponentBuilder instantiateBuilder(Class JavaDoc builderClass) throws ComponentLifecycleException {
126     try {
127       ComponentBuilder ret = (ComponentBuilder) builderClass.newInstance();
128       ret.initialize(this, dd);
129       return ret;
130     } catch (InstantiationException JavaDoc e) {
131       throw new ComponentLifecycleException("Builder instantiate error: "+e.getMessage());
132     } catch (IllegalAccessException JavaDoc e) {
133       throw new ComponentLifecycleException("Builder instantiate error: "+e.getMessage());
134     }
135   }
136
137   public boolean isStopped() {
138     return builder.isStopped();
139   }
140
141   public boolean isUpdatable() {
142     return builder.isUpdatable();
143   }
144
145 }
146
Popular Tags