1 31 package org.objectweb.proactive.core.component.representative; 32 33 import org.apache.log4j.Logger; 34 35 import org.objectweb.fractal.api.Component; 36 import org.objectweb.fractal.api.Interface; 37 import org.objectweb.fractal.api.NoSuchInterfaceException; 38 import org.objectweb.fractal.api.Type; 39 import org.objectweb.fractal.api.control.BindingController; 40 import org.objectweb.fractal.api.control.ContentController; 41 import org.objectweb.fractal.api.control.LifeCycleController; 42 import org.objectweb.fractal.api.type.ComponentType; 43 import org.objectweb.fractal.api.type.InterfaceType; 44 45 import org.objectweb.proactive.core.ProActiveRuntimeException; 46 import org.objectweb.proactive.core.UniqueID; 47 import org.objectweb.proactive.core.body.proxy.UniversalBodyProxy; 48 import org.objectweb.proactive.core.component.ComponentParameters; 49 import org.objectweb.proactive.core.component.Constants; 50 import org.objectweb.proactive.core.component.asmgen.RepresentativeInterfaceClassGenerator; 51 import org.objectweb.proactive.core.component.controller.ComponentParametersController; 52 import org.objectweb.proactive.core.component.identity.ProActiveComponent; 53 import org.objectweb.proactive.core.component.request.ComponentRequestQueue; 54 import org.objectweb.proactive.core.mop.MethodCall; 55 import org.objectweb.proactive.core.mop.Proxy; 56 import org.objectweb.proactive.core.mop.StubObject; 57 58 import java.io.Serializable ; 59 60 61 public class ProActiveComponentRepresentativeImpl 62 implements ProActiveComponentRepresentative, BindingController, 63 LifeCycleController, ContentController, ComponentParametersController, 64 Interface, Serializable { 65 protected static Logger logger = Logger.getLogger(ProActiveComponentRepresentativeImpl.class.getName()); 66 private Interface[] interfaceReferences; 67 private Proxy proxy; 68 private ComponentType componentType = null; private Object stubOnBaseObject = null; 72 public ProActiveComponentRepresentativeImpl( 76 ComponentParameters componentParameters, Proxy proxy) { 77 this.proxy = proxy; 79 80 componentType = componentParameters.getComponentType(); 81 stubOnBaseObject = componentParameters.getStubOnReifiedObject(); 82 83 interfaceReferences = new Interface[1 + 90 (componentParameters.getClientInterfaceTypes().length + 91 componentParameters.getServerInterfaceTypes().length)]; 92 93 int i = 0; 94 95 interfaceReferences[i] = (Interface) this; 97 i++; 98 99 InterfaceType[] interface_types = componentParameters.getComponentType() 103 .getFcInterfaceTypes(); 104 try { 105 for (int j = 0; j < interface_types.length; j++) { 106 Interface interface_reference = RepresentativeInterfaceClassGenerator.instance() 107 .generateInterface(interface_types[j].getFcItfName(), 108 this, interface_types[j], false); 109 110 ((StubObject) interface_reference).setProxy(proxy); 111 112 interfaceReferences[i] = interface_reference; 114 i++; 115 } 116 } catch (Exception e) { 117 e.printStackTrace(); 118 throw new RuntimeException ("cannot create interface references : " + 119 e.getMessage()); 120 } 121 } 122 123 126 public Object lookupFc(String clientItfName) { 127 return (Interface) reifyCall(BindingController.class.getName(), 128 "lookupFc", new Class [] { String .class }, 129 new Object [] { clientItfName }); 130 } 131 132 135 public void bindFc(String clientItfName, Object serverItf) { 136 reifyCall(BindingController.class.getName(), "bindFc", 137 new Class [] { String .class, Object .class }, 138 new Object [] { clientItfName, serverItf }); 139 } 140 141 144 public void unbindFc(String clientItfName) { 145 reifyCall(BindingController.class.getName(), "unbindFc", 146 new Class [] { String .class }, new Object [] { clientItfName }); 147 } 148 149 152 public String getFcState() { 153 return (String ) reifyCall(LifeCycleController.class.getName(), 154 "getFcState", new Class [] { }, new Object [] { }); 155 } 156 157 160 public void startFc() { 161 reifyCall(LifeCycleController.class.getName(), "startFc", 162 new Class [] { }, new Object [] { }); 163 } 164 165 168 public void stopFc() { 169 reifyCall(LifeCycleController.class.getName(), "stopFc", 170 new Class [] { }, new Object [] { }); 171 } 172 173 176 public Object [] getFcInternalInterfaces() { 177 return (Object []) reifyCall(ContentController.class.getName(), 178 "getFcInternalInterfaces", new Class [] { }, new Object [] { }); 179 } 180 181 185 public Object getFcInternalInterface(String interfaceName) 186 throws NoSuchInterfaceException { 187 return getFcInterface(interfaceName); 188 } 189 190 193 public Component[] getFcSubComponents() { 194 return (Component[]) reifyCall(ContentController.class.getName(), 195 "getFcSubComponents", new Class [] { }, new Object [] { }); 196 } 197 198 201 public void addFcSubComponent(Component subComponent) { 202 reifyCall(ContentController.class.getName(), "addFcSubComponent", 203 new Class [] { Component.class }, new Object [] { subComponent }); 204 } 205 206 209 public void removeFcSubComponent(Component subComponent) { 210 reifyCall(ContentController.class.getName(), "removeFcSubComponent", 211 new Class [] { Component.class }, new Object [] { subComponent }); 212 } 213 214 217 public Component getFcItfOwner() { 218 return (Component) reifyCall(Interface.class.getName(), 219 "getFcItfOwner", new Class [] { }, new Object [] { }); 220 } 221 222 225 public String getFcItfName() { 226 return null; 229 } 230 231 234 public Type getFcItfType() { 235 return getFcType(); 236 } 237 238 241 public boolean isFcInternalItf() { 242 return false; 243 } 244 245 private Object reifyCall(String className, String methodName, 246 Class [] parameterTypes, Object [] effectiveParameters) { 247 try { 248 return proxy.reify((MethodCall) MethodCall.getComponentMethodCall( 249 Class.forName(className).getDeclaredMethod(methodName, 250 parameterTypes), effectiveParameters, null)); 251 252 } catch (NoSuchMethodException e) { 254 throw new ProActiveRuntimeException(e.toString()); 255 } catch (ClassNotFoundException e) { 256 throw new ProActiveRuntimeException(e.toString()); 257 } catch (Throwable e) { 258 e.printStackTrace(); 259 throw new ProActiveRuntimeException(e.toString()); 260 } 261 } 262 263 266 public Object getFcInterface(String interfaceName) 267 throws NoSuchInterfaceException { 268 if (interfaceName.equals(Constants.BINDING_CONTROLLER) || 269 interfaceName.equals(Constants.CONTENT_CONTROLLER) || 270 interfaceName.equals(Constants.LIFECYCLE_CONTROLLER) || 271 interfaceName.equals(Constants.COMPONENT_PARAMETERS_CONTROLLER)) { 272 return this; 273 } else { 274 for (int i = 0; i < interfaceReferences.length; i++) { 275 if (interfaceReferences[i].getFcItfName() != null) { 276 if (interfaceReferences[i].getFcItfName().equals(interfaceName)) { 277 return interfaceReferences[i]; 278 } 279 } 280 } 281 throw new NoSuchInterfaceException(interfaceName); 282 } 283 } 284 285 288 public Object [] getFcInterfaces() { 289 throw new ProActiveRuntimeException("not yet implemented"); 291 } 292 293 296 public Type getFcType() { 297 return componentType; 298 } 299 300 303 public Proxy getProxy() { 304 return proxy; 305 } 306 307 310 public void setProxy(Proxy proxy) { 311 this.proxy = proxy; 312 } 313 314 318 public boolean equals(Object component) { 319 if (!(component instanceof ProActiveComponent)) { 320 logger.error( 321 "can only compare proactive components to proactive components "); 322 return false; 323 } 324 return getID().equals(((ProActiveComponent) component).getID()); 325 } 326 327 public int hashCode() { 328 return ((UniversalBodyProxy) getProxy()).getBodyID().hashCode(); 330 } 331 332 public UniqueID getID() { 333 return ((UniversalBodyProxy) getProxy()).getBodyID(); 334 } 335 336 339 public void setComponentParameters(ComponentParameters componentParameters) { 340 logger.error("only available in the meta-objects"); 341 } 342 343 346 public ComponentParameters getComponentParameters() { 347 return (ComponentParameters) reifyCall(ComponentParametersController.class.getName(), 348 "getComponentParameters", new Class [] { }, new Object [] { }); 349 } 350 351 354 public String [] listFc() { 355 return null; 356 } 357 358 361 public void setComponentName(String componentName) { 362 reifyCall(ComponentParametersController.class.getName(), 363 "setComponentName", new Class [] {String .class}, new Object [] {componentName}); 364 365 } 366 367 370 public Object getReferenceOnBaseObject() { 371 return null; 372 } 373 374 377 public ComponentRequestQueue getRequestQueue() { 378 logger.error("only available in the meta-objects"); 379 return null; 380 } 381 382 } 383 | Popular Tags |