00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.component.controller;
00032
00033 import java.io.Serializable;
00034
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.fractal.api.Component;
00037 import org.objectweb.fractal.api.Interface;
00038 import org.objectweb.fractal.api.NoSuchInterfaceException;
00039 import org.objectweb.fractal.api.control.ContentController;
00040 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
00041 import org.objectweb.fractal.api.control.LifeCycleController;
00042 import org.objectweb.fractal.api.factory.InstantiationException;
00043 import org.objectweb.fractal.api.type.ComponentType;
00044 import org.objectweb.fractal.api.type.InterfaceType;
00045 import org.objectweb.fractal.api.type.TypeFactory;
00046 import org.objectweb.fractal.util.Fractal;
00047 import org.objectweb.proactive.core.ProActiveRuntimeException;
00048 import org.objectweb.proactive.core.component.Constants;
00049 import org.objectweb.proactive.core.component.Fractive;
00050 import org.objectweb.proactive.core.component.group.ProxyForComponentInterfaceGroup;
00051 import org.objectweb.proactive.core.component.identity.ProActiveComponent;
00052 import org.objectweb.proactive.core.component.type.ProActiveInterfaceType;
00053 import org.objectweb.proactive.core.component.type.ProActiveTypeFactory;
00054 import org.objectweb.proactive.core.component.type.ProActiveTypeFactoryImpl;
00055 import org.objectweb.proactive.core.util.log.Loggers;
00056 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00057
00058
00065 public class ProActiveLifeCycleControllerImpl
00066 extends AbstractProActiveController implements ProActiveLifeCycleController,
00067 Serializable {
00068 static final Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS_CONTROLLERS);
00069 protected String fcState = LifeCycleController.STOPPED;
00070
00071 public ProActiveLifeCycleControllerImpl(Component owner) {
00072 super(owner);
00073 }
00074
00075 protected void setControllerItfType() {
00076 try {
00077 setItfType(ProActiveTypeFactoryImpl.instance()
00078 .createFcItfType(Constants.LIFECYCLE_CONTROLLER,
00079 ProActiveLifeCycleController.class.getName(),
00080 TypeFactory.SERVER, TypeFactory.MANDATORY,
00081 TypeFactory.SINGLE));
00082 } catch (InstantiationException e) {
00083 throw new ProActiveRuntimeException("cannot create controller " +
00084 this.getClass().getName());
00085 }
00086 }
00087
00088
00089
00090
00091 public String getFcState() {
00092 return fcState;
00093
00094
00095 }
00096
00097
00098
00099
00100
00101
00102 public void startFc() {
00103 try {
00104
00105
00106 InterfaceType[] itfTypes = ((ComponentType) getFcItfOwner()
00107 .getFcType()).getFcInterfaceTypes();
00108
00109 for (int i = 0; i < itfTypes.length; i++) {
00110 if (itfTypes[i].isFcClientItf() &&
00111 !itfTypes[i].isFcOptionalItf()) {
00112 if (itfTypes[i].isFcCollectionItf()) {
00113
00114 Object[] itfs = owner.getFcInterfaces();
00115 for (int j = 0; j < itfs.length; j++) {
00116 Interface itf = (Interface) itfs[j];
00117 if (itf.getFcItfName()
00118 .startsWith(itfTypes[i].getFcItfName())) {
00119 if (itf.getFcItfName()
00120 .equals(itfTypes[i].getFcItfName())) {
00121 throw new IllegalLifeCycleException(
00122 "invalid collection interface name at runtime (suffix required)");
00123 }
00124 if (Fractal.getBindingController(owner)
00125 .lookupFc(itf.getFcItfName()) == null) {
00126 throw new IllegalLifeCycleException(
00127 "compulsory collection client interface " +
00128 itfTypes[i].getFcItfName() +
00129 " in component " +
00130 Fractal.getNameController(
00131 getFcItfOwner()).getFcName() +
00132 " is not bound. ");
00133 }
00134 }
00135 }
00136 } else if (((ProActiveInterfaceType) itfTypes[i]).isFcMulticastItf() &&
00137 !!itfTypes[i].isFcOptionalItf()) {
00138 ProxyForComponentInterfaceGroup clientSideProxy = Fractive.getMulticastController(getFcItfOwner())
00139 .lookupFcMulticast(itfTypes[i].getFcItfName());
00140
00141
00142
00143
00144 if (clientSideProxy.getDelegatee().isEmpty()) {
00145 throw new IllegalLifeCycleException(
00146 "compulsory multicast client interface " +
00147 itfTypes[i].getFcItfName() + " in component " +
00148 Fractal.getNameController(getFcItfOwner())
00149 .getFcName() + " is not bound. ");
00150 }
00151 } else if ((((ProActiveInterfaceType) itfTypes[i]).getFcCardinality()
00152 .equals(ProActiveTypeFactory.SINGLETON_CARDINALITY) ||
00153 ((ProActiveInterfaceType) itfTypes[i]).getFcCardinality()
00154 .equals(ProActiveTypeFactory.GATHER_CARDINALITY)) &&
00155 (Fractal.getBindingController(getFcItfOwner())
00156 .lookupFc(itfTypes[i].getFcItfName()) == null)) {
00157 throw new IllegalLifeCycleException(
00158 "compulsory client interface " +
00159 itfTypes[i].getFcItfName() + " in component " +
00160 Fractal.getNameController(getFcItfOwner())
00161 .getFcName() + " is not bound. ");
00162 }
00163
00164
00165
00166 }
00167 }
00168
00169 String hierarchical_type = Fractive.getComponentParametersController((ProActiveComponent) getFcItfOwner())
00170 .getComponentParameters()
00171 .getHierarchicalType();
00172 if (hierarchical_type.equals(Constants.COMPOSITE)) {
00173
00174 Component[] inner_components = Fractal.getContentController(getFcItfOwner())
00175 .getFcSubComponents();
00176 if (inner_components != null) {
00177 for (int i = 0; i < inner_components.length; i++) {
00178 ((LifeCycleController) inner_components[i].getFcInterface(Constants.LIFECYCLE_CONTROLLER)).startFc();
00179 }
00180 }
00181 }
00182
00183
00184 fcState = LifeCycleController.STARTED;
00185 if (logger.isDebugEnabled()) {
00186 logger.debug("started " +
00187 ((ComponentParametersController) getFcItfOwner()
00188 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
00189 .getName());
00190 }
00191 } catch (NoSuchInterfaceException nsie) {
00192 logger.error("interface not found : " + nsie.getMessage());
00193 nsie.printStackTrace();
00194 } catch (IllegalLifeCycleException ilce) {
00195 logger.error("illegal life cycle operation : " + ilce.getMessage());
00196 ilce.printStackTrace();
00197 }
00198 }
00199
00200
00201
00202
00203
00204 public void stopFc() {
00205 try {
00206 String hierarchical_type = ((ComponentParametersController) getFcItfOwner()
00207 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
00208 .getHierarchicalType();
00209 if (hierarchical_type.equals(Constants.COMPOSITE)) {
00210
00211 Component[] inner_components = ((ContentController) getFcItfOwner()
00212 .getFcInterface(Constants.CONTENT_CONTROLLER)).getFcSubComponents();
00213 if (inner_components != null) {
00214 for (int i = 0; i < inner_components.length; i++) {
00215 ((LifeCycleController) inner_components[i].getFcInterface(Constants.LIFECYCLE_CONTROLLER)).stopFc();
00216 }
00217 }
00218 }
00219
00220
00221 fcState = LifeCycleController.STOPPED;
00222 if (logger.isDebugEnabled()) {
00223 logger.debug("stopped" +
00224 ((ComponentParametersController) getFcItfOwner()
00225 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
00226 .getName());
00227 }
00228 } catch (NoSuchInterfaceException nsie) {
00229 logger.error("interface not found : " + nsie.getMessage());
00230 } catch (IllegalLifeCycleException ilce) {
00231 logger.error("illegal life cycle operation : " + ilce.getMessage());
00232 }
00233 }
00234
00235
00236
00237
00238 public String getFcState(short priority) {
00239 return getFcState();
00240 }
00241
00242
00243
00244
00245 public void startFc(short priority) {
00246 startFc();
00247 }
00248
00249
00250
00251
00252 public void stopFc(short priority) {
00253 stopFc();
00254 }
00255 }