You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/02/07 21:19:23 UTC
svn commit: r907470 - in /tuscany/sca-cpp/trunk/modules: java/eval.hpp
java/io.hpp java/mod-java.cpp
java/org/apache/tuscany/InvocationHandler.java python/eval.hpp
python/io.hpp python/mod-python.cpp server/client-test.hpp
server/mod-eval.hpp
Author: jsdelfino
Date: Sun Feb 7 20:19:23 2010
New Revision: 907470
URL: http://svn.apache.org/viewvc?rev=907470&view=rev
Log:
Support HTTPD graceful restarts for non-stop operation. Simplified Python and Java error capture and recovery.
Removed:
tuscany/sca-cpp/trunk/modules/java/io.hpp
tuscany/sca-cpp/trunk/modules/python/io.hpp
Modified:
tuscany/sca-cpp/trunk/modules/java/eval.hpp
tuscany/sca-cpp/trunk/modules/java/mod-java.cpp
tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/InvocationHandler.java
tuscany/sca-cpp/trunk/modules/python/eval.hpp
tuscany/sca-cpp/trunk/modules/python/mod-python.cpp
tuscany/sca-cpp/trunk/modules/server/client-test.hpp
tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
Modified: tuscany/sca-cpp/trunk/modules/java/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/eval.hpp?rev=907470&r1=907469&r2=907470&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/eval.hpp Sun Feb 7 20:19:23 2010
@@ -29,13 +29,12 @@
#include "list.hpp"
#include "value.hpp"
-#include "io.hpp"
namespace tuscany {
namespace java {
/**
- * Initialize a JVM.
+ * Represent a Java VM runtime.
*/
jobject JNICALL nativeInvoke(JNIEnv *env, jobject self, jobject proxy, jobject method, jobjectArray args);
@@ -87,9 +86,6 @@
jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
}
- // Capture JVM standard IO
- setupIO();
-
// Lookup System classes and methods
classClass = env->FindClass("java/lang/Class");
methodClass = env->FindClass("java/lang/reflect/Method");
@@ -114,6 +110,7 @@
loaderForName = env->GetStaticMethodID(loaderClass, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
invokerClass = env->FindClass("org/apache/tuscany/InvocationHandler");
invokerValueOf = env->GetStaticMethodID(invokerClass, "valueOf", "(Ljava/lang/Class;J)Ljava/lang/Object;");
+ invokerStackTrace = env->GetStaticMethodID(invokerClass, "stackTrace", "(Ljava/lang/Throwable;)Ljava/lang/String;");
invokerLambda = env->GetFieldID(invokerClass, "lambda", "J");
iterableUtilClass = env->FindClass("org/apache/tuscany/IterableUtil");
iterableValueOf = env->GetStaticMethodID(iterableUtilClass, "list", "([Ljava/lang/Object;)Ljava/lang/Iterable;");
@@ -127,7 +124,6 @@
nm.signature = const_cast<char*>("(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");
nm.fnPtr = (void*)nativeInvoke;
env->RegisterNatives(invokerClass, &nm, 1);
-
}
JavaVM* jvm;
@@ -154,13 +150,13 @@
jmethodID loaderForName;
jclass invokerClass;
jmethodID invokerValueOf;
+ jmethodID invokerStackTrace;
jfieldID invokerLambda;
jclass iterableUtilClass;
jmethodID iterableValueOf;
jmethodID iterableCar;
jmethodID iterableCdr;
jmethodID iterableIsNil;
-
};
/**
@@ -169,9 +165,13 @@
string lastException(const JavaRuntime& jr) {
if (!jr.env->ExceptionCheck())
return "No Exception";
- jr.env->ExceptionDescribe();
+ const jthrowable ex = jr.env->ExceptionOccurred();
+ const jstring trace = (jstring)jr.env->CallStaticObjectMethod(jr.invokerClass, jr.invokerStackTrace, ex);
+ const char* c = jr.env->GetStringUTFChars(trace, NULL);
+ const string msg(c);
+ jr.env->ReleaseStringUTFChars(trace, c);
jr.env->ExceptionClear();
- return "UnknownException";
+ return msg;
}
/**
Modified: tuscany/sca-cpp/trunk/modules/java/mod-java.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/mod-java.cpp?rev=907470&r1=907469&r2=907470&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/mod-java.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/mod-java.cpp Sun Feb 7 20:19:23 2010
@@ -55,7 +55,9 @@
/**
* Restart the module.
*/
-const failable<bool> restart(unused ServerConf& sc) {
+const failable<bool> restart(ServerConf& sc) {
+ // Start a Java runtime
+ sc.moduleConf = new (gc_new<java::JavaRuntime>()) java::JavaRuntime();
return true;
}
Modified: tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/InvocationHandler.java
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/InvocationHandler.java?rev=907470&r1=907469&r2=907470&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/InvocationHandler.java (original)
+++ tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/InvocationHandler.java Sun Feb 7 20:19:23 2010
@@ -19,6 +19,8 @@
package org.apache.tuscany;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -40,7 +42,19 @@
return Proxy.newProxyInstance(iface.getClassLoader(), new Class[]{iface}, new InvocationHandler(lambda));
}
+ /**
+ * Proxy invocation of a C++ function.
+ */
@Override
public native Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable;
+ /**
+ * Return the stack trace of an exception.
+ */
+ static String stackTrace(final Throwable e) {
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ e.printStackTrace(pw);
+ return sw.toString();
+ }
}
Modified: tuscany/sca-cpp/trunk/modules/python/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/eval.hpp?rev=907470&r1=907469&r2=907470&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/eval.hpp Sun Feb 7 20:19:23 2010
@@ -29,33 +29,52 @@
#include "list.hpp"
#include "value.hpp"
-#include "io.hpp"
namespace tuscany {
namespace python {
/**
- * Initialize the Python runtime.
+ * Represent a Python runtime.
*/
class PythonRuntime {
public:
- PythonRuntime() : owner(true) {
+ PythonRuntime() {
+ if (Py_IsInitialized())
+ return;
Py_InitializeEx(0);
- setupIO();
- }
-
- PythonRuntime(unused const PythonRuntime& r) : owner(false) {
}
+};
- ~PythonRuntime() {
- if (!owner)
- return;
- //Py_Finalize();
+/**
+ * Return the last python error.
+ */
+const string lastError() {
+ if(PyErr_Occurred()) {
+ PyObject* type;
+ PyObject* val;
+ PyObject* trace;
+ PyErr_Fetch(&type, &val, &trace);
+ if (type != NULL && val != NULL) {
+ PyObject* stype = PyObject_Str(type);
+ PyObject* sval = PyObject_Str(val);
+ string msg = string() + PyString_AsString(stype) + " : " + PyString_AsString(sval);
+ Py_DECREF(stype);
+ Py_DECREF(sval);
+ Py_DECREF(type);
+ Py_DECREF(val);
+ Py_XDECREF(trace);
+ PyErr_Print();
+ return msg;
+ }
+ PyErr_Print();
+ Py_XDECREF(type);
+ Py_XDECREF(val);
+ Py_XDECREF(trace);
+ PyErr_Print();
+ return "Unknown Python error";
}
-
-private:
- const bool owner;
-};
+ return "";
+}
/**
* Declare conversion functions.
@@ -222,8 +241,10 @@
// The start, stop, and restart functions are optional
const value fn = car<value>(expr);
- if (fn == "start" || fn == "stop" || fn == "restart")
+ if (fn == "start" || fn == "stop" || fn == "restart") {
+ PyErr_Clear();
return value(false);
+ }
return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastError());
}
Modified: tuscany/sca-cpp/trunk/modules/python/mod-python.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/mod-python.cpp?rev=907470&r1=907469&r2=907470&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/mod-python.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/mod-python.cpp Sun Feb 7 20:19:23 2010
@@ -56,6 +56,8 @@
* Restart the module.
*/
const failable<bool> restart(unused ServerConf& sc) {
+ // Start a Python runtime
+ sc.moduleConf = new (gc_new<python::PythonRuntime>()) python::PythonRuntime();
return true;
}
Modified: tuscany/sca-cpp/trunk/modules/server/client-test.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/client-test.hpp?rev=907470&r1=907469&r2=907470&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/client-test.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/client-test.hpp Sun Feb 7 20:19:23 2010
@@ -312,7 +312,7 @@
+ (list<value>() + "price" + string("$2.99"));
const list<value> a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
http::CURLSession ch;
- value rc = content(http::put(a, testURI, ch));
+ value rc = content(http::put(a, testURI + "/111", ch));
assert(rc == value(true));
return true;
}
@@ -320,7 +320,7 @@
const bool testDel() {
gc_scoped_pool pool;
http::CURLSession ch;
- value rc = content(http::del(testURI, ch));
+ value rc = content(http::del(testURI + "/111", ch));
assert(rc == value(true));
return true;
}
Modified: tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp?rev=907470&r1=907469&r2=907470&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp Sun Feb 7 20:19:23 2010
@@ -395,7 +395,7 @@
debug(sc.implementations, "modeval::confComponents::implementations");
// Start or restart the component implementations
- return applyLifecycleExpr(impls, mklist<value>(lifecycle));
+ return applyLifecycleExpr(impls, mklist<value>(c_str(lifecycle)));
}
/**