1 31 package org.objectweb.proactive.core.component.controller; 32 33 import org.apache.log4j.Logger; 34 35 import org.objectweb.fractal.api.Component; 36 import org.objectweb.fractal.api.NoSuchInterfaceException; 37 import org.objectweb.fractal.api.control.ContentController; 38 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 39 import org.objectweb.fractal.api.control.LifeCycleController; 40 41 import org.objectweb.proactive.core.component.Constants; 42 import org.objectweb.proactive.core.component.identity.ProActiveComponent; 43 import org.objectweb.proactive.core.component.request.ComponentRequestQueue; 44 45 import java.io.Serializable ; 46 47 48 55 public class ProActiveLifeCycleController extends ProActiveController 56 implements LifeCycleController, Serializable { 57 protected static Logger logger = Logger.getLogger(ProActiveLifeCycleController.class.getName()); 58 59 public ProActiveLifeCycleController(Component owner) { 60 super(owner, Constants.LIFECYCLE_CONTROLLER); 61 } 62 63 66 public String getFcState() { 67 return getRequestQueue().isStarted() ? LifeCycleController.STARTED 68 : LifeCycleController.STOPPED; 69 } 70 71 76 public void startFc() { 77 try { 78 String hierarchical_type = ((ComponentParametersController) getFcItfOwner() 79 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters() 80 .getHierarchicalType(); 81 if (hierarchical_type.equals(Constants.COMPOSITE) || 82 hierarchical_type.equals(Constants.PARALLEL)) { 83 Component[] inner_components = ((ContentController) getFcItfOwner() 85 .getFcInterface(Constants.CONTENT_CONTROLLER)).getFcSubComponents(); 86 if (inner_components != null) { 87 for (int i = 0; i < inner_components.length; i++) { 88 ((LifeCycleController) inner_components[i].getFcInterface(Constants.LIFECYCLE_CONTROLLER)).startFc(); 89 } 90 } 91 } 92 getRequestQueue().start(); 93 if (logger.isDebugEnabled()) { 94 logger.debug("started " + 95 ((ComponentParametersController) getFcItfOwner() 96 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters() 97 .getName()); 98 } 99 } catch (NoSuchInterfaceException nsie) { 100 logger.error("interface not found : " + nsie.getMessage()); 101 nsie.printStackTrace(); 102 } catch (IllegalLifeCycleException ilce) { 103 logger.error("illegal life cycle operation : " + ilce.getMessage()); 104 ilce.printStackTrace(); 105 } 106 } 107 108 112 public void stopFc() { 113 try { 114 String hierarchical_type = ((ComponentParametersController) getFcItfOwner() 115 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters() 116 .getHierarchicalType(); 117 if (hierarchical_type.equals(Constants.COMPOSITE) || 118 hierarchical_type.equals(Constants.PARALLEL)) { 119 Component[] inner_components = ((ContentController) getFcItfOwner() 121 .getFcInterface(Constants.CONTENT_CONTROLLER)).getFcSubComponents(); 122 if (inner_components != null) { 123 for (int i = 0; i < inner_components.length; i++) { 124 ((LifeCycleController) inner_components[i].getFcInterface(Constants.LIFECYCLE_CONTROLLER)).stopFc(); 125 } 126 } 127 } 128 getRequestQueue().stop(); 129 if (logger.isDebugEnabled()) { 130 logger.debug("stopped" + 131 ((ComponentParametersController) getFcItfOwner() 132 .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters() 133 .getName()); 134 } 135 } catch (NoSuchInterfaceException nsie) { 136 logger.error("interface not found : " + nsie.getMessage()); 137 nsie.printStackTrace(); 138 } catch (IllegalLifeCycleException ilce) { 139 logger.error("illegal life cycle operation : " + ilce.getMessage()); 140 ilce.printStackTrace(); 141 } 142 } 143 144 private ComponentRequestQueue getRequestQueue() { 145 return ((ProActiveComponent) getFcItfOwner()).getRequestQueue(); 146 } 147 } 148 | Popular Tags |