diff options
Diffstat (limited to 'sca-cpp/trunk/modules')
-rw-r--r-- | sca-cpp/trunk/modules/java/eval.hpp | 38 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/java/org/apache/tuscany/UUIDUtil.java | 32 | ||||
-rwxr-xr-x | sca-cpp/trunk/modules/wsgi/wsgi-stop | 2 |
3 files changed, 64 insertions, 8 deletions
diff --git a/sca-cpp/trunk/modules/java/eval.hpp b/sca-cpp/trunk/modules/java/eval.hpp index 7da1f20a38..a1cf6ae576 100644 --- a/sca-cpp/trunk/modules/java/eval.hpp +++ b/sca-cpp/trunk/modules/java/eval.hpp @@ -26,6 +26,7 @@ * Java component implementation evaluation logic. */ #include <jni.h> +#include <apr_uuid.h> #include "list.hpp" #include "value.hpp" @@ -46,6 +47,7 @@ namespace java { * Represent a Java VM runtime. */ jobject JNICALL nativeInvoke(JNIEnv *env, jobject self, jobject proxy, jobject method, jobjectArray args); +jobject JNICALL nativeUUID(JNIEnv *env); class JavaRuntime { public: @@ -133,13 +135,21 @@ public: iterableIsNil = env->GetStaticMethodID(iterableUtilClass, "isNil", "(Ljava/lang/Object;)Z"); iterableCar = env->GetStaticMethodID(iterableUtilClass, "car", "(Ljava/lang/Object;)Ljava/lang/Object;"); iterableCdr = env->GetStaticMethodID(iterableUtilClass, "cdr", "(Ljava/lang/Object;)Ljava/lang/Iterable;"); + uuidClass = env->FindClass("org/apache/tuscany/UUIDUtil"); // Register our native invocation handler function - JNINativeMethod nm; - nm.name = const_cast<char*>("invoke"); - 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); + JNINativeMethod invokenm; + invokenm.name = const_cast<char*>("invoke"); + invokenm.signature = const_cast<char*>("(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;"); + invokenm.fnPtr = (void*)nativeInvoke; + env->RegisterNatives(invokerClass, &invokenm, 1); + + // Register our native UUID function + JNINativeMethod uuidnm; + uuidnm.name = const_cast<char*>("uuid"); + uuidnm.signature = const_cast<char*>("()Ljava/lang/String;"); + uuidnm.fnPtr = (void*)nativeUUID; + env->RegisterNatives(uuidClass, &uuidnm, 1); } JavaVM* jvm; @@ -173,6 +183,7 @@ public: jmethodID iterableCar; jmethodID iterableCdr; jmethodID iterableIsNil; + jclass uuidClass; }; /** @@ -247,8 +258,8 @@ public: }; /** - * Invocation handler invoke method, dispatches to the lambda function wrapped - * in the invocation handler. + * Native implementation of the InvocationHandler.invoke Java method. + * Dispatches the call to the lambda function wrapped in the invocation handler. */ jobject JNICALL nativeInvoke(JNIEnv* env, jobject self, unused jobject proxy, jobject method, jobjectArray args) { @@ -277,6 +288,19 @@ jobject JNICALL nativeInvoke(JNIEnv* env, jobject self, unused jobject proxy, jo } /** + * Native implementation of IterableUtil.uuid. We are providing a native implementation + * of this function as java.util.UUID seems to behave differently with different JDKs. + */ +jobject JNICALL nativeUUID(JNIEnv* env) { + apr_uuid_t uuid; + apr_uuid_get(&uuid); + char buf[APR_UUID_FORMATTED_LENGTH]; + apr_uuid_format(buf, &uuid); + string s(buf, APR_UUID_FORMATTED_LENGTH); + return env->NewStringUTF(c_str(s)); +} + +/** * Convert a lambda function to Java proxy. */ const jobject mkJavaLambda(const JavaRuntime& jr, unused const value& iface, const lambda<value(const list<value>&)>& l) { diff --git a/sca-cpp/trunk/modules/java/org/apache/tuscany/UUIDUtil.java b/sca-cpp/trunk/modules/java/org/apache/tuscany/UUIDUtil.java new file mode 100644 index 0000000000..60076c62ca --- /dev/null +++ b/sca-cpp/trunk/modules/java/org/apache/tuscany/UUIDUtil.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany; + +/** + * A fast and portable UUID generator function. + */ +public class UUIDUtil { + + /** + * Return a UUID. + */ + public static native String uuid(); + +} diff --git a/sca-cpp/trunk/modules/wsgi/wsgi-stop b/sca-cpp/trunk/modules/wsgi/wsgi-stop index fa6f42d643..d1e09185f4 100755 --- a/sca-cpp/trunk/modules/wsgi/wsgi-stop +++ b/sca-cpp/trunk/modules/wsgi/wsgi-stop @@ -24,4 +24,4 @@ port=$1 python_prefix=`cat $here/../python/python.prefix` py="$python_prefix/bin/python composite.py $port" -kill `ps -f | grep -v grep | grep "${py}" | awk '{ print $2 }'` +kill `ps -ef | grep -v grep | grep "${py}" | awk '{ print $2 }'` |