summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/java
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-02-07 00:36:25 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-02-07 00:36:25 +0000
commitbb4b895471e3165c71bdfd1fdae5e1ffde8f1696 (patch)
tree57bec175bb5dbf43303f7334162b9b2b4bda03c6 /sca-cpp/trunk/modules/java
parent00f9947613624b251551ba709824f97f1b6c2fb1 (diff)
Moved server configuration to HTTPD postConfig phase, to avoid running configuration commands twice and added a way for runtime modules and components to handle start/restart/stop events. Improved build scripts a little, to not depend on external environment variables.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@907352 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/java/Makefile.am9
-rw-r--r--sca-cpp/trunk/modules/java/driver.hpp1
-rw-r--r--sca-cpp/trunk/modules/java/eval.hpp13
-rw-r--r--sca-cpp/trunk/modules/java/java-test.cpp4
-rw-r--r--sca-cpp/trunk/modules/java/mod-java.cpp29
-rw-r--r--sca-cpp/trunk/modules/java/mod-java.hpp20
-rwxr-xr-xsca-cpp/trunk/modules/java/server-test7
-rwxr-xr-xsca-cpp/trunk/modules/java/wiring-test7
8 files changed, 67 insertions, 23 deletions
diff --git a/sca-cpp/trunk/modules/java/Makefile.am b/sca-cpp/trunk/modules/java/Makefile.am
index 5ef145c6e3..5402ab495e 100644
--- a/sca-cpp/trunk/modules/java/Makefile.am
+++ b/sca-cpp/trunk/modules/java/Makefile.am
@@ -15,9 +15,8 @@
# specific language governing permissions and limitations
# under the License.
-datadir=$(prefix)/modules/java
JAVAROOT = $(top_builddir)/modules/java
-libdir=$(prefix)/lib
+libdir = $(prefix)/lib
if WANT_JAVA
@@ -50,6 +49,12 @@ CLEANFILES = ${jarfile} org/apache/tuscany/*.class test/*.class
client_test_SOURCES = client-test.cpp
client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+prefixdir = $(top_builddir)/modules/java
+prefix_DATA = java.prefix
+
+java.prefix: $(top_builddir)/config.status
+ echo ${JAVA_PREFIX} >java.prefix
+
TESTS = java-test server-test
endif
diff --git a/sca-cpp/trunk/modules/java/driver.hpp b/sca-cpp/trunk/modules/java/driver.hpp
index 5f117b8e68..ddfc057940 100644
--- a/sca-cpp/trunk/modules/java/driver.hpp
+++ b/sca-cpp/trunk/modules/java/driver.hpp
@@ -48,6 +48,7 @@ const value evalDriverLoop(const JavaRuntime& jr, const JavaClass jc, istream& i
const bool evalDriverRun(const char* name, istream& in, ostream& out) {
scheme::setupDisplay(out);
+ JavaRuntime javaRuntime;
const failable<JavaClass> jc = readClass(javaRuntime, ".", name);
if (!hasContent(jc))
return true;
diff --git a/sca-cpp/trunk/modules/java/eval.hpp b/sca-cpp/trunk/modules/java/eval.hpp
index 4272543506..e10ec29a0b 100644
--- a/sca-cpp/trunk/modules/java/eval.hpp
+++ b/sca-cpp/trunk/modules/java/eval.hpp
@@ -161,7 +161,7 @@ public:
jmethodID iterableCdr;
jmethodID iterableIsNil;
-} javaRuntime;
+};
/**
* Return the last exception that occurred in a JVM.
@@ -210,6 +210,8 @@ public:
}
const value operator()(const list<value>& expr) const {
+ if (isNil(expr))
+ return func(expr);
const value& op(car(expr));
if (op == "equals")
return value(cadr(expr) == this);
@@ -495,8 +497,15 @@ const failable<value> evalClass(const JavaRuntime& jr, const value& expr, const
// Lookup the Java function named as the expression operand
const list<value> func = assoc<value>(car<value>(expr), jc.m);
- if (isNil(func))
+ if (isNil(func)) {
+
+ // The start, stop, and restart functions are optional
+ const value fn = car<value>(expr);
+ if (fn == "start" || fn == "stop" || fn == "restart")
+ return value(false);
+
return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastException(jr));
+ }
const jmethodID fid = (jmethodID)(long)(double)cadr(func);
// Convert args to Java jvalues
diff --git a/sca-cpp/trunk/modules/java/java-test.cpp b/sca-cpp/trunk/modules/java/java-test.cpp
index d050180be8..f811a4f58d 100644
--- a/sca-cpp/trunk/modules/java/java-test.cpp
+++ b/sca-cpp/trunk/modules/java/java-test.cpp
@@ -33,6 +33,7 @@ namespace java {
bool testEvalExpr() {
gc_scoped_pool pool;
+ JavaRuntime javaRuntime;
{
const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl");
assert(hasContent(obj));
@@ -77,6 +78,7 @@ const value add(const list<value>& args) {
bool testEvalLambda() {
gc_scoped_pool pool;
+ JavaRuntime javaRuntime;
{
const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl");
assert(hasContent(obj));
@@ -98,6 +100,7 @@ bool testEvalLambda() {
bool testClassLoader() {
gc_scoped_pool pool;
+ JavaRuntime javaRuntime;
const failable<JavaClass> obj = readClass(javaRuntime, ".", "org.apache.tuscany.ClassLoader$Test");
assert(hasContent(obj));
const value exp = mklist<value>("testClassLoader");
@@ -109,6 +112,7 @@ bool testClassLoader() {
bool testIterableUtil() {
gc_scoped_pool pool;
+ JavaRuntime javaRuntime;
const failable<JavaClass> obj = readClass(javaRuntime, ".", "org.apache.tuscany.IterableUtil$Test");
assert(hasContent(obj));
const value exp = mklist<value>("testList");
diff --git a/sca-cpp/trunk/modules/java/mod-java.cpp b/sca-cpp/trunk/modules/java/mod-java.cpp
index a5dc48679d..b8ac642c0e 100644
--- a/sca-cpp/trunk/modules/java/mod-java.cpp
+++ b/sca-cpp/trunk/modules/java/mod-java.cpp
@@ -37,15 +37,38 @@ namespace server {
namespace modeval {
/**
+ * Start the module.
+ */
+const failable<bool> start(unused ServerConf& sc) {
+ // Start a Java runtime
+ sc.moduleConf = new (gc_new<java::JavaRuntime>()) java::JavaRuntime();
+ return true;
+}
+
+/**
+ * Stop the module.
+ */
+const failable<bool> stop(unused ServerConf& sc) {
+ return true;
+}
+
+/**
+ * Restart the module.
+ */
+const failable<bool> restart(unused ServerConf& sc) {
+ return true;
+}
+
+/**
* Evaluate a Java component implementation and convert it to an applicable
* lambda function.
*/
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px) {
+const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, modeval::ServerConf& sc) {
const string itype(elementName(impl));
if (contains(itype, ".java"))
- return modjava::evalImplementation(path, impl, px);
+ return modjava::evalImplementation(path, impl, px, sc);
if (contains(itype, ".cpp"))
- return modcpp::evalImplementation(path, impl, px);
+ return modcpp::evalImplementation(path, impl, px, sc);
return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype);
}
diff --git a/sca-cpp/trunk/modules/java/mod-java.hpp b/sca-cpp/trunk/modules/java/mod-java.hpp
index a2235fc17f..ccb6d9262b 100644
--- a/sca-cpp/trunk/modules/java/mod-java.hpp
+++ b/sca-cpp/trunk/modules/java/mod-java.hpp
@@ -34,24 +34,32 @@
#include "value.hpp"
#include "monad.hpp"
#include "eval.hpp"
-#include "../http/httpd.hpp"
+#include "../server/mod-eval.hpp"
namespace tuscany {
namespace server {
namespace modjava {
/**
+ * Return the Java runtime configured in a server.
+ */
+java::JavaRuntime& javaRuntime(modeval::ServerConf sc) {
+ return *(java::JavaRuntime*)sc.moduleConf;
+}
+
+/**
* Apply a Java component implementation function.
*/
struct applyImplementation {
java::JavaClass impl;
const list<value> px;
- applyImplementation(const java::JavaClass& impl, const list<value>& px) : impl(impl), px(px) {
+ java::JavaRuntime& jr;
+ applyImplementation(const java::JavaClass& impl, const list<value>& px, java::JavaRuntime& jr) : impl(impl), px(px), jr(jr) {
}
const value operator()(const list<value>& params) const {
const value expr = append<value>(params, px);
debug(expr, "modeval::java::applyImplementation::input");
- const failable<value> val = java::evalClass(java::javaRuntime, expr, impl);
+ const failable<value> val = java::evalClass(jr, expr, impl);
debug(val, "modeval::java::applyImplementation::result");
if (!hasContent(val))
return mklist<value>(value(), reason(val));
@@ -63,12 +71,12 @@ struct applyImplementation {
* Evaluate a Java component implementation and convert it to an applicable
* lambda function.
*/
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px) {
+const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, modeval::ServerConf& sc) {
const string cn(attributeValue("class", impl));
- const failable<java::JavaClass> jc = java::readClass(java::javaRuntime, path, cn);
+ const failable<java::JavaClass> jc = java::readClass(javaRuntime(sc), path, cn);
if (!hasContent(jc))
return mkfailure<lambda<value(const list<value>&)> >(reason(jc));
- return lambda<value(const list<value>&)>(applyImplementation(content(jc), px));
+ return lambda<value(const list<value>&)>(applyImplementation(content(jc), px, javaRuntime(sc)));
}
}
diff --git a/sca-cpp/trunk/modules/java/server-test b/sca-cpp/trunk/modules/java/server-test
index 45c5efafb2..fbd12e5542 100755
--- a/sca-cpp/trunk/modules/java/server-test
+++ b/sca-cpp/trunk/modules/java/server-test
@@ -22,16 +22,13 @@
../server/server-conf tmp
./java-conf tmp
cat >>tmp/conf/httpd.conf <<EOF
-
-<Location />
SCAContribution `pwd`/
SCAComposite domain-test.composite
-</Location>
EOF
export CLASSPATH="`pwd`/libmod-tuscany-java-1.0.jar:`pwd`"
-apachectl -k start -d `pwd`/tmp
+../http/httpd-start tmp
sleep 2
# Test
@@ -39,6 +36,6 @@ sleep 2
rc=$?
# Cleanup
-apachectl -k stop -d `pwd`/tmp
+../http/httpd-stop tmp
sleep 2
return $rc
diff --git a/sca-cpp/trunk/modules/java/wiring-test b/sca-cpp/trunk/modules/java/wiring-test
index 7b47787b28..c0b6cbfd62 100755
--- a/sca-cpp/trunk/modules/java/wiring-test
+++ b/sca-cpp/trunk/modules/java/wiring-test
@@ -24,16 +24,13 @@ echo "Testing..."
../server/server-conf tmp
./java-conf tmp
cat >>tmp/conf/httpd.conf <<EOF
-
-<Location />
SCAContribution `pwd`/
SCAComposite domain-test.composite
-</Location>
EOF
export CLASSPATH="`pwd`/libmod-tuscany-java-1.0.jar:`pwd`"
-apachectl -k start -d `pwd`/tmp
+../http/httpd-start tmp
sleep 2
# Test HTTP GET
@@ -73,7 +70,7 @@ if [ "$rc" = "0" ]; then
fi
# Cleanup
-apachectl -k stop -d `pwd`/tmp
+../http/httpd-stop tmp
sleep 2
if [ "$rc" = "0" ]; then
echo "OK"