org/objectweb/proactive/core/component/adl/vnexportation/ExportedVirtualNodesCompiler.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.vnexportation;
00032 
00033 import java.util.List;
00034 import java.util.Map;
00035 
00036 import org.objectweb.deployment.scheduling.component.api.InstanceProviderTask;
00037 import org.objectweb.deployment.scheduling.component.lib.AbstractConfigurationTask;
00038 import org.objectweb.fractal.adl.ADLException;
00039 import org.objectweb.fractal.adl.Definition;
00040 import org.objectweb.fractal.adl.TaskMap;
00041 import org.objectweb.fractal.adl.components.Component;
00042 import org.objectweb.fractal.adl.components.ComponentContainer;
00043 import org.objectweb.fractal.adl.components.PrimitiveCompiler;
00044 import org.objectweb.fractal.adl.nodes.VirtualNodeContainer;
00045 import org.objectweb.fractal.api.control.BindingController;
00046 import org.objectweb.proactive.core.component.adl.nodes.VirtualNode;
00047 
00048 
00058 public class ExportedVirtualNodesCompiler implements PrimitiveCompiler,
00059     BindingController {
00060     private ExportedVirtualNodesBuilder builder;
00061     public final static String BUILDER_BINDING = "builder";
00062 
00063     public String[] listFc() {
00064         return new String[] { BUILDER_BINDING };
00065     }
00066 
00067     public Object lookupFc(final String itf) {
00068         if (itf.equals(BUILDER_BINDING)) {
00069             return builder;
00070         }
00071         return null;
00072     }
00073 
00074     public void bindFc(final String itf, final Object value) {
00075         if (itf.equals(BUILDER_BINDING)) {
00076             builder = (ExportedVirtualNodesBuilder) value;
00077         }
00078     }
00079 
00080     public void unbindFc(final String itf) {
00081         if (itf.equals(BUILDER_BINDING)) {
00082             builder = null;
00083         }
00084     }
00085 
00086     public void compile(List path, ComponentContainer container, TaskMap tasks,
00087         Map context) throws ADLException {
00088         if (container instanceof ExportedVirtualNodesContainer) {
00089             ExportedVirtualNodes exported_vns = ((ExportedVirtualNodesContainer) container).getExportedVirtualNodes();
00090             if (exported_vns != null) {
00091                 //                InstanceProviderTask c = (InstanceProviderTask) tasks.getTask("create",
00092                 //                        container);
00093                 String component_name = null;
00094                 if (container instanceof Definition) {
00095                     component_name = ((Definition) container).getName();
00096                 } else if (container instanceof Component) {
00097                     component_name = ((Component) container).getName();
00098                 }
00099 
00100                 //                else {
00101                 //                    component_name = ((Definition) container).getName();
00102                 //                }
00103                 VirtualNode current_component_vn = (VirtualNode) ((VirtualNodeContainer) container).getVirtualNode();
00104                 SetExportedVirtualNodesTask t = new SetExportedVirtualNodesTask(component_name,
00105                         builder, exported_vns.getExportedVirtualNodes(),
00106                         current_component_vn);
00107 
00108                 InstanceProviderTask createTask = (InstanceProviderTask) tasks.getTask("create",
00109                         container);
00110 
00111                 // exportations to be known *before* the creation of components.
00112                 createTask.addPreviousTask(t);
00113 
00114                 tasks.addTask("exportedVirtualNodes", container, t);
00115             }
00116         }
00117     }
00118 
00119     static class SetExportedVirtualNodesTask extends AbstractConfigurationTask {
00120         private ExportedVirtualNodesBuilder builder;
00121         private String componentName;
00122         private ExportedVirtualNode[] exported_vns;
00123         private VirtualNode currentComponentVN;
00124 
00125         public SetExportedVirtualNodesTask(String componentName,
00126             ExportedVirtualNodesBuilder builder,
00127             ExportedVirtualNode[] exported_vns, VirtualNode currentComponentVN) {
00128             this.componentName = componentName;
00129             this.builder = builder;
00130             this.exported_vns = exported_vns;
00131             this.currentComponentVN = currentComponentVN;
00132         }
00133 
00134         public void execute(final Object context) throws Exception {
00135             //Object component = getInstanceProviderTask().getResult();
00136             builder.compose(componentName, exported_vns, currentComponentVN);
00137         }
00138 
00139         public Object getResult() {
00140             return null;
00141         }
00142 
00143         public void setResult(Object result) {
00144         }
00145     }
00146 }

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