1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class ComponentServerImpl 38 extends org.omg.CORBA.LocalObject 39 implements Servant, org.omg.Components.Deployment.ComponentServerOperations 40 { 41 static private String _class_name = "ComponentServerImpl"; 43 static final private String _type_id = org.omg.Components.Deployment.ComponentServerHelper.id(); 44 private ORBService _orb_service; 45 private POAService _cont_poa_service; 46 private java.util.ArrayList _cont_refs; private org.omg.Components.ConfigValue[] _configuration; 48 private org.omg.Components.Deployment.ServerActivator _sa_ref; 49 50 public 52 ComponentServerImpl() 53 { 54 _orb_service = null; 56 _cont_poa_service = null; 57 _cont_refs = new java.util.ArrayList (); 58 _configuration = new org.omg.Components.ConfigValue[0]; 59 _sa_ref = null; 60 } 61 62 66 static public Servant 67 create_servant() 68 { 69 return new ComponentServerImpl(); 70 } 71 72 76 80 final public void 81 system_configuration_complete(SystemConfiguration cfg) 82 { 83 ServantConfiguration scfg = (ServantConfiguration)cfg; 85 _orb_service = scfg.orb_service(); 86 87 FactoryFinderService ffs = org.objectweb.corba.runtime.Runtime.getFFService(); 89 SystemFactory poafact = ffs.find_service_factory(POAService.SERVICE_ID); 90 91 POAConfiguration poacfg = new POAConfigurationImpl(null, null, _orb_service); 94 _cont_poa_service = (POAService)poafact.create_system_component(poacfg); 95 96 String typeid = org.omg.Components.ConfigValueHelper.id(); 98 org.omg.CORBA.portable.ValueFactory fact = org.objectweb.ccm.runtime.ConfigValueFactoryImpl.create_factory(); 99 _orb_service.register_valuefactory(new ValueFactoryImpl(typeid, fact)); 100 101 } 106 107 final public void 108 destroy() 109 { 110 org.omg.Components.Deployment.Container[] refs = get_containers(); 112 for (int i=0;i<refs.length;i++) { 113 try { 114 refs[i].remove(); 116 117 byte[] cid = _cont_poa_service.get_id_from_ref(refs[i]); 119 _cont_poa_service.deactivate_servant(cid); 120 } catch (org.omg.Components.RemoveFailure ex) { 121 final String opname = "destroy"; 123 TheLogger.debug(_class_name, opname, "IGNORE", ex); 124 return ; 125 } 126 } 127 128 _cont_refs.clear(); 130 131 _cont_poa_service.destroy(); 133 } 134 135 139 final public String 140 type_id() 141 { 142 return _type_id; 143 } 144 145 final public org.omg.PortableServer.Servant 146 as_native_servant() 147 { 148 return new org.omg.Components.Deployment.ComponentServerPOATie(this); 149 } 150 151 155 final public org.omg.Components.ConfigValue[] 156 configuration() 157 { 158 return _configuration; 159 } 160 161 final public org.omg.Components.Deployment.ServerActivator 162 get_server_activator() 163 { 164 return _sa_ref; 165 } 166 167 final public org.omg.Components.Deployment.Container 168 create_container(org.omg.Components.ConfigValue[] config) 169 throws org.omg.Components.CreateFailure, 170 org.omg.Components.Deployment.InvalidConfiguration 171 { 172 176 ContainerImpl cont = new ContainerImpl(); 178 179 ServantConfiguration scfg = new ServantConfigurationImpl(_orb_service, _cont_poa_service); 181 cont.system_configuration_complete(scfg); 182 183 byte[] oid = Double.toString(Math.random()).getBytes(); 186 org.omg.CORBA.Object ref = _cont_poa_service.create_ref_with_id(oid, cont.type_id()); 187 _cont_poa_service.activate_servant_with_id(cont, oid); 188 189 org.omg.Components.Deployment.Container cref = org.omg.Components.Deployment.ContainerHelper.narrow(ref); 191 _cont_refs.add(cref); 192 193 return cref; 194 } 195 196 final public void 197 remove_container(org.omg.Components.Deployment.Container cref) 198 throws org.omg.Components.RemoveFailure 199 { 200 org.omg.Components.Deployment.Container[] refs = get_containers(); 202 int i=0; 203 for (;i<refs.length;i++) { 204 if (cref._is_equivalent(refs[i])) { 205 _cont_refs.remove(i); 206 207 cref.remove(); 209 210 byte[] cid = _cont_poa_service.get_id_from_ref(cref); 212 _cont_poa_service.deactivate_servant(cid); 213 214 break; 215 } 216 } 217 218 if (i==refs.length) { 220 throw new org.omg.Components.RemoveFailure(); 221 } 222 } 223 224 final public org.omg.Components.Deployment.Container[] 225 get_containers() 226 { 227 return (org.omg.Components.Deployment.Container[])_cont_refs.toArray(new org.omg.Components.Deployment.Container[0]); 228 } 229 230 final public void 231 remove() 232 throws org.omg.Components.RemoveFailure 233 { 234 destroy(); 236 } 237 } 238 239 | Popular Tags |