org/objectweb/proactive/core/component/body/ComponentBodyImpl.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.component.body;
00032 
00033 import java.util.HashMap;
00034 import java.util.Map;
00035 
00036 import org.apache.log4j.Logger;
00037 import org.objectweb.fractal.api.NoSuchInterfaceException;
00038 import org.objectweb.fractal.api.control.LifeCycleController;
00039 import org.objectweb.fractal.util.Fractal;
00040 import org.objectweb.proactive.Active;
00041 import org.objectweb.proactive.core.body.MetaObjectFactory;
00042 import org.objectweb.proactive.core.body.ProActiveMetaObjectFactory;
00043 import org.objectweb.proactive.core.body.migration.MigratableBody;
00044 import org.objectweb.proactive.core.component.ComponentParameters;
00045 import org.objectweb.proactive.core.component.identity.ProActiveComponent;
00046 import org.objectweb.proactive.core.component.identity.ProActiveComponentImpl;
00047 import org.objectweb.proactive.core.component.request.Shortcut;
00048 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException;
00049 import org.objectweb.proactive.core.util.log.Loggers;
00050 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00051 
00052 
00057 public class ComponentBodyImpl extends MigratableBody implements ComponentBody {
00058     private ProActiveComponent componentIdentity = null;
00059     private Map<String, Shortcut> shortcutsOnThis = null; // key = functionalItfName, value = shortcut
00060     private static Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS);
00061 
00062     private boolean insideFunctionalActivity = false;
00063 
00064     public ComponentBodyImpl() {
00065         super();
00066     }
00067 
00080     public ComponentBodyImpl(Object reifiedObject, String nodeURL,
00081         Active activity, MetaObjectFactory factory, String jobID)
00082         throws java.lang.reflect.InvocationTargetException, 
00083             ConstructorCallExecutionFailedException {
00084         super(reifiedObject, nodeURL, factory, jobID);
00085         //        filterOnNFRequests = new RequestFilterOnPrioritizedNFRequests();
00086         // create the component metaobject if necessary
00087         // --> check the value of the "parameters" field
00088         Map factory_parameters = factory.getParameters();
00089         if ((null != factory_parameters)) {
00090             if (null != factory_parameters.get(
00091                         ProActiveMetaObjectFactory.COMPONENT_PARAMETERS_KEY)) {
00092                 if (factory_parameters.get(
00093                             ProActiveMetaObjectFactory.COMPONENT_PARAMETERS_KEY) instanceof ComponentParameters) {
00094                     if (logger.isDebugEnabled()) {
00095                         logger.debug("creating metaobject component identity");
00096                     }
00097                     componentIdentity = factory.newComponentFactory()
00098                                                .newProActiveComponent(this);
00099 
00100                     // change activity into a component activity
00101                     // activity = new ComponentActivity(activity, reifiedObject);
00102                 } else {
00103                     logger.error(
00104                         "component parameters for the components factory are not of type ComponentParameters");
00105                 }
00106             }
00107         }
00108     }
00109 
00114     public ProActiveComponentImpl getProActiveComponentImpl() {
00115         return (ProActiveComponentImpl)componentIdentity;
00116     }
00117     
00118     
00119     
00120 
00130     public boolean isActive() {
00131         if (insideFunctionalActivity) {
00132             try {
00133                 return LifeCycleController.STARTED.equals(Fractal.getLifeCycleController(
00134                         getProActiveComponentImpl()).getFcState());
00135             } catch (NoSuchInterfaceException e) {
00136                 logger.error(
00137                     "could not find the life cycle controller of this component");
00138                 return false;
00139             }
00140         } else {
00141             return super.isActive();
00142         }
00143     }
00144 
00145     /*
00146      * @see org.objectweb.proactive.core.component.body.ComponentBody#isComponent()
00147      */
00148     public boolean isComponent() {
00149         return (getProActiveComponentImpl() != null);
00150     }
00151 
00152     /*
00153      * @see org.objectweb.proactive.core.component.body.ComponentBody#finishedFunctionalActivity()
00154      */
00155     public void finishedFunctionalActivity() {
00156         insideFunctionalActivity = false;
00157     }
00158 
00159     /*
00160      * @see org.objectweb.proactive.core.component.body.ComponentBody#startingFunctionalActivity()
00161      */
00162     public void startingFunctionalActivity() {
00163         insideFunctionalActivity = true;
00164     }
00165 
00166     public void keepShortcut(Shortcut shortcut) {
00167         if (shortcutsOnThis == null) {
00168             shortcutsOnThis = new HashMap<String, Shortcut>();
00169         }
00170         shortcutsOnThis.put(shortcut.getFcFunctionalInterfaceName(), shortcut);
00171     }
00172 
00173 
00174 }

Generated on Mon Jan 22 15:16:06 2007 for ProActive by  doxygen 1.5.1