org/objectweb/proactive/core/runtime/http/messages/RuntimeRequest.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.runtime.http.messages;
00032 
00033 import java.io.Serializable;
00034 import java.lang.reflect.InvocationTargetException;
00035 import java.lang.reflect.Method;
00036 import java.util.ArrayList;
00037 import java.util.HashMap;
00038 
00039 import org.objectweb.proactive.core.body.http.util.messages.ReflectRequest;
00040 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
00041 
00042 
00049 public class RuntimeRequest extends ReflectRequest implements Serializable {
00050     private String methodName;
00051     private ArrayList<Object> parameters = new ArrayList<Object>();
00052     private static HashMap hMapMethods;
00053     private static ProActiveRuntimeImpl runtime;
00054 
00055     static {
00056         // init the hashmap, that contains all the methods of  ProActiveRuntimeImpl 
00057         // in 'Object' (value) and the name of funtions in key 
00058         // (Warning two functions can t have the same name (for now)) 
00059         runtime = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00060         hMapMethods = getHashMapReflect(runtime.getClass());
00061     }
00062 
00063     public RuntimeRequest(String newmethodName, String url) {
00064         super(url);
00065         this.methodName = newmethodName;
00066     }
00067 
00068     public Object getReturnedObject() throws Exception {
00069         if (this.returnedObject instanceof Exception) {
00070             throw (Exception) this.returnedObject;
00071         }
00072         return this.returnedObject;
00073     }
00074 
00075     public RuntimeRequest(String newmethodName, ArrayList<Object> newparameters,
00076         String url) {
00077         this(newmethodName, url);
00078         this.parameters = newparameters;
00079     }
00080 
00081     public RuntimeRequest(String newmethodName, ArrayList<Object> newparameters,
00082         ArrayList newparamsTypes, String url) {
00083         this(newmethodName, newparameters, url);
00084     }
00085 
00086     public Object processMessage() throws Exception {
00087         Object[] params = parameters.toArray();
00088         Object result = null;
00089 
00090         Method m = getProActiveRuntimeMethod(methodName, parameters,
00091                 hMapMethods.get(methodName));
00092         try {
00093             result = m.invoke(runtime, parameters.toArray());
00094         } catch (IllegalArgumentException e) {
00095             //throw new HTTPRemoteException("Error during reflexion", e);
00096             //e.printStackTrace();
00097             //esult =e;
00098             throw e;
00099         } catch (IllegalAccessException e) {
00100             //throw new HTTPRemoteException("Error during reflexion", e);
00101             //.e.printStackTrace();
00102             //result = e;
00103             throw e;
00104         } catch (InvocationTargetException e) {
00105             //throw (Exception) e.getCause();   
00106             //throw new HTTPRemoteException("Error during reflexion", e);
00107             //                                      e.printStackTrace();
00108             //                                      result = e;
00109             throw (Exception) e.getCause();
00110         } catch (Exception e) {
00111             //                                      result = e;
00112             throw e;
00113         }
00114         return result;
00115     }
00116 
00117     public String getMethodName() {
00118         return this.methodName;
00119     }
00120 
00121     public ArrayList getParameters() {
00122         return this.parameters;
00123     }
00124 
00125     public String toString() {
00126         return "[ " + methodName + " ( " + parameters + " )" + " ]";
00127     }
00128 }

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