org/objectweb/proactive/core/component/adl/implementations/ProActiveImplementationBuilderImpl.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.adl.implementations;
00032 
00033 import java.util.Map;
00034 
00035 import org.apache.log4j.Logger;
00036 import org.objectweb.fractal.adl.ADLException;
00037 import org.objectweb.fractal.api.Component;
00038 import org.objectweb.fractal.api.control.BindingController;
00039 import org.objectweb.fractal.api.type.ComponentType;
00040 import org.objectweb.fractal.util.Fractal;
00041 import org.objectweb.proactive.core.component.Constants;
00042 import org.objectweb.proactive.core.component.ContentDescription;
00043 import org.objectweb.proactive.core.component.ControllerDescription;
00044 import org.objectweb.proactive.core.component.adl.RegistryManager;
00045 import org.objectweb.proactive.core.component.adl.nodes.VirtualNode;
00046 import org.objectweb.proactive.core.component.adl.vnexportation.ExportedVirtualNodesList;
00047 import org.objectweb.proactive.core.component.adl.vnexportation.LinkedVirtualNode;
00048 import org.objectweb.proactive.core.component.factory.ProActiveGenericFactory;
00049 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00050 import org.objectweb.proactive.core.group.Group;
00051 import org.objectweb.proactive.core.util.log.Loggers;
00052 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00053 
00054 
00058 public class ProActiveImplementationBuilderImpl
00059     implements ProActiveImplementationBuilder, BindingController {
00060     public final static String REGISTRY_BINDING = "registry";
00061     public RegistryManager registry;
00062     private static Logger logger = ProActiveLogger.getLogger(Loggers.COMPONENTS_ADL);
00063 
00064     // --------------------------------------------------------------------------
00065     // Implementation of the BindingController interface
00066     // --------------------------------------------------------------------------
00067     public String[] listFc() {
00068         return new String[] { REGISTRY_BINDING };
00069     }
00070 
00071     public Object lookupFc(final String itf) {
00072         if (itf.equals(REGISTRY_BINDING)) {
00073             return registry;
00074         }
00075         return null;
00076     }
00077 
00078     public void bindFc(final String itf, final Object value) {
00079         if (itf.equals(REGISTRY_BINDING)) {
00080             registry = (RegistryManager) value;
00081         }
00082     }
00083 
00084     public void unbindFc(final String itf) {
00085         if (itf.equals(REGISTRY_BINDING)) {
00086             registry = null;
00087         }
00088     }
00089 
00090     //  --------------------------------------------------------------------------
00091     // Implementation of the Implementation Builder and ProActiveImplementationBuilder interfaces
00092     // --------------------------------------------------------------------------
00093     public Object createComponent(Object arg0, String arg1, String arg2,
00094         Object arg3, Object arg4, Object arg5) throws Exception {
00095         return null;
00096     }
00097 
00098     public Object createComponent(Object type, String name, String definition,
00099         ControllerDescription controllerDesc, ContentDescription contentDesc,
00100         VirtualNode adlVN, Map context) throws Exception {
00101         org.objectweb.proactive.core.descriptor.data.VirtualNode deploymentVN = null;
00102         Component bootstrap = null;
00103         if (context != null) {
00104             bootstrap = (Component) ((Map) context).get("bootstrap");
00105         }
00106         if (bootstrap == null) {
00107             bootstrap = Fractal.getBootstrapComponent();
00108         }
00109 
00110         if (adlVN != null) {
00111             // consider exported virtual nodes
00112             LinkedVirtualNode exported = ExportedVirtualNodesList.instance()
00113                                                                  .getNode(name,
00114                     adlVN.getName(), false);
00115             if (exported != null) {
00116                 adlVN.setName(exported.getExportedVirtualNodeNameAfterComposition());
00117                 adlVN.setCardinality(exported.isMultiple()
00118                     ? VirtualNode.MULTIPLE : VirtualNode.SINGLE);
00119             } else {
00120                 //      TODO add self exported virtual node ?
00121                 // for the moment, just add a leaf to the linked vns
00122                 ExportedVirtualNodesList.instance().addLeafVirtualNode(name,
00123                     adlVN.getName(), adlVN.getCardinality()); // TODO_M check this
00124             }
00125             if (context.get("deployment-descriptor") != null) {
00126                 deploymentVN =
00127                     ((ProActiveDescriptor) context.get("deployment-descriptor")).getVirtualNode(adlVN.getName());
00128                 if (deploymentVN == null) {
00129                     if (adlVN.getName().equals("null")) {
00130                         logger.info(name +
00131                             " will be instantiated in the current virtual machine (\"null\" was specified as the virtual node name)");
00132                     } else {
00133                         throw new ADLException("Could not find virtual node  " +
00134                             adlVN.getName() + " in the deployment descriptor",
00135                             null);
00136                     }
00137                 } else {
00138                     if (deploymentVN.isMultiple() &&
00139                             (adlVN.getCardinality().equals(VirtualNode.SINGLE))) {
00140                         // there will be only one instance of the component, on one node of the virtual node 
00141                         contentDesc.forceSingleInstance();
00142                     } else if (!(deploymentVN.isMultiple()) &&
00143                             (adlVN.getCardinality().equals(VirtualNode.MULTIPLE))) {
00144                         throw new ADLException(
00145                             "Cannot deploy on a single virtual node when the cardinality of this virtual node named " +
00146                             adlVN.getName() + " in the ADL is set to multiple",
00147                             null);
00148                     }
00149                 }
00150             }
00151         }
00152         Component result;
00153         
00154         // FIXME : exhaustively specify the behaviour
00155         if (deploymentVN!=null && VirtualNode.MULTIPLE.equals(adlVN.getCardinality()) && controllerDesc.getHierarchicalType().equals(Constants.PRIMITIVE) && !contentDesc.uniqueInstance()) {
00156             result = (Component)((Group)((ProActiveGenericFactory)Fractal.getGenericFactory(bootstrap)).newFcInstanceAsList((ComponentType) type,
00157                     controllerDesc, contentDesc, deploymentVN)).getGroupByType();
00158         } else {
00159             result = ((ProActiveGenericFactory)Fractal.getGenericFactory(bootstrap)).newFcInstance((ComponentType) type,
00160                     controllerDesc, contentDesc, deploymentVN);
00161         }
00162 //        registry.addComponent(result); // the registry can handle groups
00163 
00164         return result;
00165     }
00166 }

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