1 31 package org.objectweb.proactive.core.component.controller; 32 33 import org.objectweb.fractal.api.Component; 34 import org.objectweb.fractal.api.Interface; 35 import org.objectweb.fractal.api.NoSuchInterfaceException; 36 import org.objectweb.fractal.api.Type; 37 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 38 import org.objectweb.fractal.api.control.LifeCycleController; 39 import org.objectweb.fractal.api.factory.InstantiationException; 40 import org.objectweb.fractal.api.type.InterfaceType; 41 import org.objectweb.fractal.api.type.TypeFactory; 42 43 import org.objectweb.proactive.core.ProActiveRuntimeException; 44 import org.objectweb.proactive.core.component.Constants; 45 import org.objectweb.proactive.core.component.type.ProActiveTypeFactory; 46 47 import java.io.Serializable ; 48 49 50 56 public abstract class ProActiveController implements Interface, Serializable { 57 private Component owner; 58 private boolean isInternal = true; 59 private InterfaceType interfaceType; 60 private String controllerName; 61 62 68 public ProActiveController(Component owner, String controllerName) { 69 this.owner = owner; 70 this.controllerName = controllerName; 72 try { 73 if (controllerName.equals(Constants.CONTENT_CONTROLLER)) { 74 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.CONTENT_CONTROLLER, 75 ProActiveContentController.class.getName(), 76 TypeFactory.SERVER, TypeFactory.MANDATORY, 77 TypeFactory.SINGLE); 78 } else if (controllerName.equals(Constants.BINDING_CONTROLLER)) { 79 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.BINDING_CONTROLLER, 80 ProActiveBindingController.class.getName(), 81 TypeFactory.SERVER, TypeFactory.MANDATORY, 82 TypeFactory.SINGLE); 83 } else if (controllerName.equals(Constants.LIFECYCLE_CONTROLLER)) { 84 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.LIFECYCLE_CONTROLLER, 85 ProActiveLifeCycleController.class.getName(), 86 TypeFactory.SERVER, TypeFactory.MANDATORY, 87 TypeFactory.SINGLE); 88 } else if (controllerName.equals( 89 Constants.COMPONENT_PARAMETERS_CONTROLLER)) { 90 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.COMPONENT_PARAMETERS_CONTROLLER, 91 ProActiveComponentParametersController.class.getName(), 92 TypeFactory.SERVER, TypeFactory.MANDATORY, 93 TypeFactory.SINGLE); 94 } else { 95 throw new ProActiveRuntimeException("unknown controller"); 96 } 97 } catch (InstantiationException e) { 98 throw new ProActiveRuntimeException("cannot create component or interface type", 99 e); 100 } 101 } 102 103 106 public Component getFcItfOwner() { 107 return owner; 108 } 109 110 113 public boolean isFcInternalItf() { 114 return isInternal; 115 } 116 117 120 public String getFcItfName() { 121 return controllerName; 122 } 123 124 127 public Type getFcItfType() { 128 return interfaceType; 129 } 130 131 134 protected void checkLifeCycleIsStopped() throws IllegalLifeCycleException { 135 try { 136 if (!((LifeCycleController) getFcItfOwner().getFcInterface(Constants.LIFECYCLE_CONTROLLER)).getFcState() 137 .equals(LifeCycleController.STOPPED)) { 138 throw new IllegalLifeCycleException( 139 "this control operation should be performed while the component is stopped"); 140 } 141 } catch (NoSuchInterfaceException nsie) { 142 throw new ProActiveRuntimeException( 143 "life cycle controller interface not found"); 144 } 145 } 146 147 } 159 | Popular Tags |