00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.component.adl;
00032
00033 import java.util.HashMap;
00034 import java.util.Map;
00035
00036 import org.objectweb.fractal.adl.Factory;
00037 import org.objectweb.fractal.adl.FactoryFactory;
00038 import org.objectweb.fractal.api.Component;
00039 import org.objectweb.fractal.api.NoSuchInterfaceException;
00040 import org.objectweb.fractal.api.control.LifeCycleController;
00041 import org.objectweb.fractal.util.Fractal;
00042 import org.objectweb.proactive.ProActive;
00043 import org.objectweb.proactive.core.ProActiveException;
00044 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00045
00046
00056 public class Launcher {
00057 static ProActiveDescriptor deploymentDescriptor;
00058
00059 private Launcher() {
00060 }
00061
00062 public static void main(final String[] args) throws Exception {
00063 String[] pargs = parseArgs(args);
00064 Object comp = createComponent(pargs);
00065
00066 if (comp instanceof Component) {
00067 LifeCycleController lc = null;
00068 try {
00069 lc = Fractal.getLifeCycleController((Component) comp);
00070 } catch (NoSuchInterfaceException ignored) {
00071 }
00072 if (lc != null) {
00073 lc.startFc();
00074 }
00075 Runnable r = null;
00076 try {
00077 r = (Runnable) ((Component) comp).getFcInterface(pargs[2]);
00078 } catch (NoSuchInterfaceException ignored) {
00079 }
00080 if (r != null) {
00081 r.run();
00082 }
00083 } else {
00084 if (comp instanceof LifeCycleController) {
00085 ((LifeCycleController) comp).startFc();
00086 }
00087 if (comp instanceof Runnable) {
00088 ((Runnable) comp).run();
00089 }
00090 }
00091 }
00092
00093 public static Object createComponent(String[] pargs)
00094 throws Exception {
00095 if (pargs[0].equals("-java")) {
00096 Factory f = FactoryFactory.getFactory(FactoryFactory.JAVA_BACKEND);
00097 return ((Map) f.newComponent(pargs[1], new HashMap())).get(pargs[2]);
00098 } else {
00099 Factory f;
00100 if ("org.objectweb.proactive.core.component.Fractive".equals(
00101 System.getProperty("fractal.provider"))) {
00102
00103
00104 f = org.objectweb.proactive.core.component.adl.FactoryFactory.getFactory();
00105 } else {
00106 f = FactoryFactory.getFactory(FactoryFactory.FRACTAL_BACKEND);
00107 }
00108
00109
00110 if (pargs[3] != null) {
00111 deploymentDescriptor = ProActive.getProactiveDescriptor(pargs[3]);
00112 HashMap context = new HashMap(1);
00113 context.put("deployment-descriptor", deploymentDescriptor);
00114 return f.newComponent(pargs[1], context);
00115 } else {
00116 try {
00117 return f.newComponent(pargs[1], new HashMap());
00118 } catch (ClassCastException e) {
00119 if (e.getMessage().indexOf("attribute_controller_representative") != (-1)) {
00120 System.out.println(
00121 "Error while parsing the ADL. This could be due to the setting of attributes without implementing AttributeController. ");
00122 throw e;
00123 } else {
00124 e.printStackTrace();
00125 return null;
00126 }
00127 }
00128 }
00129 }
00130 }
00131
00132 private static String[] parseArgs(final String[] args) {
00133 if ((args.length < 1) || (args.length > 4)) {
00134 parseError();
00135 }
00136
00137
00138 String[] result = new String[4];
00139 if (args[0].equals("-java") || args[0].equals("-fractal")) {
00140 if (args.length < 2) {
00141 parseError();
00142 }
00143 result[0] = args[0];
00144 result[1] = args[1];
00145 result[2] = (args.length == 3 || args.length == 4) ? args[2] : "run";
00146 result[3] = (args.length == 4) ? args[3] : null;
00147 } else {
00148 result[0] = "-java";
00149 result[1] = args[0];
00150 result[2] = (args.length >= 2) ? args[1] : "run";
00151 }
00152 return result;
00153 }
00154
00155 private static void parseError() {
00156 System.out.println(
00157 "Usage: Launcher [-java|-fractal] <definition> [ <itf> ] [deployment-descriptor]");
00158 System.out.print(
00159 "where <definition> is the name of the component to be ");
00160 System.out.print("instantiated and started,\n <itf> is the name of ");
00161 System.out.println("its Runnable interface, if it has one,");
00162 System.out.println(
00163 "\nand [deployment-descriptor] is the deployment descriptor that should be used for ProActive");
00164 System.exit(1);
00165 }
00166
00167 public static void killNodes(boolean softly) throws ProActiveException {
00168 deploymentDescriptor.killall(softly);
00169 }
00170 }