org/objectweb/proactive/core/component/controller/AbstractProActiveController.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.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.Type;
00040 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
00041 import org.objectweb.fractal.api.control.LifeCycleController;
00042 import org.objectweb.fractal.api.type.InterfaceType;
00043 import org.objectweb.proactive.core.ProActiveRuntimeException;
00044 import org.objectweb.proactive.core.body.migration.MigrationException;
00045 import org.objectweb.proactive.core.component.Constants;
00046 import org.objectweb.proactive.core.component.identity.ProActiveComponent;
00047 import org.objectweb.proactive.core.node.Node;
00048 import org.objectweb.proactive.core.util.log.Loggers;
00049 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00050 
00051 
00058 public abstract class AbstractProActiveController extends AbstractRequestHandler
00059     implements Interface, Serializable, ProActiveController {
00060     private boolean isInternal = true;
00061     private InterfaceType interfaceType;
00062     protected static Logger controllerLogger = ProActiveLogger.getLogger(Loggers.COMPONENTS_CONTROLLERS);
00063 
00069     public AbstractProActiveController(Component owner) {
00070         this.owner = (ProActiveComponent)owner;
00071         setControllerItfType();
00072     }
00073 
00074     /*
00075      * @see org.objectweb.proactive.core.component.controller.ProActiveController#init()
00076      */
00077     public void init() {
00078         // controllers requiring initialization *after* all controllers are instantiated should override this method
00079     }
00080 
00081     /*
00082      * see {@link org.objectweb.fractal.api.Interface#isFcInternalItf()}
00083      */
00084 
00085     /*
00086      * @see org.objectweb.proactive.core.component.controller.ProActiveController#isFcInternalItf()
00087      */
00088     public boolean isFcInternalItf() {
00089         return isInternal;
00090     }
00091 
00092     /*
00093      * see {@link org.objectweb.fractal.api.Interface#getFcItfName()}
00094      */
00095 
00096     /*
00097      * @see org.objectweb.proactive.core.component.controller.ProActiveController#getFcItfName()
00098      */
00099     public String getFcItfName() {
00100         return interfaceType.getFcItfName();
00101     }
00102 
00103     /*
00104      * see {@link org.objectweb.fractal.api.Interface#getFcItfType()}
00105      */
00106 
00107     /*
00108      * @see org.objectweb.proactive.core.component.controller.ProActiveController#getFcItfType()
00109      */
00110     public Type getFcItfType() {
00111         return interfaceType;
00112     }
00113 
00114     /*
00115      * some control operations are to be performed while the component is stopped
00116      */
00117     protected void checkLifeCycleIsStopped() throws IllegalLifeCycleException {
00118         try {
00119             if (!((LifeCycleController) getFcItfOwner()
00120                       .getFcInterface(Constants.LIFECYCLE_CONTROLLER)).getFcState()
00121                       .equals(LifeCycleController.STOPPED)) {
00122                 throw new IllegalLifeCycleException(
00123                     "this control operation should be performed while the component is stopped");
00124             }
00125         } catch (NoSuchInterfaceException nsie) {
00126             throw new ProActiveRuntimeException(
00127                 "life cycle controller interface not found");
00128         }
00129     }
00130 
00131     protected void setItfType(InterfaceType itfType) {
00132         this.interfaceType = itfType;
00133     }
00134 
00135     protected abstract void setControllerItfType();
00136     
00143     public void migrateDependentActiveObjectsTo(Node node) throws MigrationException {
00144         // nothing by default
00145     }
00146 }

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