1 2 package SOFA.Component.DCUP; 3 4 import SOFA.Component.ComponentLifecycleException; 5 import SOFA.SOFAnode.Run.Deployment.DeploymentDescriptor; 6 7 11 public class DCUPComponentManagerImpl extends SOFA.Component.ComponentManagerImpl implements DCUPComponentManager { 12 13 14 ComponentBuilder builder; 15 16 17 18 public DCUPComponentManagerImpl(DeploymentDescriptor _dd, String _node, String _dockName, SOFA.SOFAnode.Run.Deployment.DeplDock _depldock, String _id) throws ComponentLifecycleException { 19 super(_dd, _node, _dockName, _depldock, _id); 20 System.out.println("Component manager"); 21 builder = null; 22 try { 23 Class builderClass = loadComponentClass(dd.getImplementationClass("builder")); 24 builder = instantiateBuilder(builderClass); 25 } catch (ClassNotFoundException 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 sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) { 42 try { 43 String sname = (String ) 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 sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) { 53 try { 54 String sname = (String ) 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 (!builder.isStopped()) { 63 builder.onLeaving(stateStore); 64 for (java.util.Enumeration sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) { 65 try { 66 String sname = (String ) 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 sub = subcomponents.getAllNames(); sub.hasMoreElements(); ) { 76 try { 77 String sname = (String ) 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 ((SOFA.Component.ThreadIDRegistryImpl)thrRegistry).setInUpdate(true); 102 String id = dd.getInstanceId(); 103 String 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 builder = null; 111 try { 112 Class builderClass = loadComponentClass(dd.getImplementationClass("builder")); 113 builder = instantiateBuilder(builderClass); 114 } catch (ClassNotFoundException 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 125 protected ComponentBuilder instantiateBuilder(Class builderClass) throws ComponentLifecycleException { 126 try { 127 ComponentBuilder ret = (ComponentBuilder) builderClass.newInstance(); 128 ret.initialize(this, dd); 129 return ret; 130 } catch (InstantiationException e) { 131 throw new ComponentLifecycleException("Builder instantiate error: "+e.getMessage()); 132 } catch (IllegalAccessException 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 |