diff options
Diffstat (limited to 'jrt_test/src/java')
-rw-r--r-- | jrt_test/src/java/.gitignore | 3 | ||||
-rw-r--r-- | jrt_test/src/java/CMakeLists.txt | 8 | ||||
-rw-r--r-- | jrt_test/src/java/DummySlobrokService.java | 40 | ||||
-rw-r--r-- | jrt_test/src/java/HelloWorld.java | 8 | ||||
-rw-r--r-- | jrt_test/src/java/PollRPCServer.java | 35 | ||||
-rw-r--r-- | jrt_test/src/java/SimpleServer.java | 50 | ||||
-rw-r--r-- | jrt_test/src/java/build.xml | 62 |
7 files changed, 206 insertions, 0 deletions
diff --git a/jrt_test/src/java/.gitignore b/jrt_test/src/java/.gitignore new file mode 100644 index 00000000000..c7d02fa8c22 --- /dev/null +++ b/jrt_test/src/java/.gitignore @@ -0,0 +1,3 @@ +build.inc +classes +jrt-test.jar diff --git a/jrt_test/src/java/CMakeLists.txt b/jrt_test/src/java/CMakeLists.txt new file mode 100644 index 00000000000..60ebc1b930b --- /dev/null +++ b/jrt_test/src/java/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +file(MAKE_DIRECTORY classes) +add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/java_code_compiled + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../binref/compilejava -d classes *.java + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/java_code_compiled + DEPENDS DummySlobrokService.java HelloWorld.java PollRPCServer.java SimpleServer.java + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +add_custom_target(jrt_test_java ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/java_code_compiled) diff --git a/jrt_test/src/java/DummySlobrokService.java b/jrt_test/src/java/DummySlobrokService.java new file mode 100644 index 00000000000..3fcc51dcb39 --- /dev/null +++ b/jrt_test/src/java/DummySlobrokService.java @@ -0,0 +1,40 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.jrt.*; +import com.yahoo.jrt.slobrok.api.*; + +public class DummySlobrokService { + public static void main(String args[]) { + if (args.length < 3) { + System.err.println("Usage: DummySlobrokService <myspec> " + + "<slobrokspec> <service> [service] ..."); + System.exit(1); + } + Spec mySpec = new Spec(args[0]); + String[] slobroks = new String[1]; + slobroks[0] = args[1]; + SlobrokList slist = new SlobrokList(); + slist.setup(slobroks); + int serviceCnt = args.length - 2; + String[] serviceList = new String[serviceCnt]; + for (int i = 0; i < serviceCnt; i++) { + serviceList[i] = args[i + 2]; + } + Supervisor orb = new Supervisor(new Transport()); + Spec listenSpec = new Spec(mySpec.port()); + try { + Acceptor acceptor = orb.listen(listenSpec); + System.out.println("Listening at " + listenSpec); + Register reg = new Register(orb, slist, + mySpec.host(), mySpec.port()); + for (int i = 0; i < serviceList.length; i++) { + System.out.println("trying to register " + serviceList[i]); + reg.registerName(serviceList[i]); + } + orb.transport().join(); + acceptor.shutdown().join(); + } catch (ListenFailedException e) { + System.err.println("Could not listen at " + listenSpec); + orb.transport().shutdown().join(); + } + } +} diff --git a/jrt_test/src/java/HelloWorld.java b/jrt_test/src/java/HelloWorld.java new file mode 100644 index 00000000000..d9f0e934d18 --- /dev/null +++ b/jrt_test/src/java/HelloWorld.java @@ -0,0 +1,8 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +public class HelloWorld +{ + public static void main(String[] args) + { + System.out.println("Hello World!"); + } +} diff --git a/jrt_test/src/java/PollRPCServer.java b/jrt_test/src/java/PollRPCServer.java new file mode 100644 index 00000000000..bf47762e139 --- /dev/null +++ b/jrt_test/src/java/PollRPCServer.java @@ -0,0 +1,35 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +import com.yahoo.jrt.*; + +public class PollRPCServer { + + public static void main(String[] args) { + if (args.length != 1) { + System.err.println("usage: PollRPCServer <spec>"); + System.exit(1); + } + Transport transport = new Transport(); + Supervisor orb = new Supervisor(transport); + Target target = orb.connect(new Spec(args[0])); + Request req = new Request("frt.rpc.ping"); + int retry = 0; + System.out.print("polling '" + args[0] + "' "); + while (true) { + target.invokeSync(req, 60.0); + System.out.print("."); + if (req.errorCode() != ErrorCode.CONNECTION + || ++retry == 500) { + break; + } + try { Thread.sleep(250); } catch (Exception e) {} + target = orb.connect(new Spec(args[0])); + req = new Request("frt.rpc.ping"); + } + if (req.isError()) { + System.out.println(" fail"); + System.exit(1); + } + System.out.println(" ok"); + } +} diff --git a/jrt_test/src/java/SimpleServer.java b/jrt_test/src/java/SimpleServer.java new file mode 100644 index 00000000000..b2859b65f65 --- /dev/null +++ b/jrt_test/src/java/SimpleServer.java @@ -0,0 +1,50 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +import com.yahoo.jrt.*; + +public class SimpleServer { + + public void rpc_inc(Request req) { + req.returnValues().add(new Int32Value(req.parameters().get(0).asInt32() + + 1)); + } + + public void rpc_echo(Request req) { + for (int i = 0; i < req.parameters().size(); i++) { + req.returnValues().add(req.parameters().get(i)); + } + } + + public void rpc_test(Request req) { + int value = req.parameters().get(0).asInt32(); + int error = req.parameters().get(1).asInt32(); + int extra = req.parameters().get(2).asInt8(); + + req.returnValues().add(new Int32Value(value)); + if (extra != 0) { + req.returnValues().add(new Int32Value(value)); + } + if (error != 0) { + req.setError(error, "Custom error"); + } + } + + public static void main(String[] args) { + if (args.length != 1) { + System.err.println("usage: SimpleServer <spec>"); + System.exit(1); + } + Supervisor orb = new Supervisor(new Transport()); + SimpleServer handler = new SimpleServer(); + orb.addMethod(new Method("inc", "i", "i", handler, "rpc_inc")); + orb.addMethod(new Method("echo", "*", "*", handler, "rpc_echo")); + orb.addMethod(new Method("test", "iib", "i", handler, "rpc_test")); + try { + orb.listen(new Spec(args[0])); + } catch (ListenFailedException e) { + System.err.println("could not listen at " + args[0]); + System.exit(1); + } + orb.transport().join(); + } +} diff --git a/jrt_test/src/java/build.xml b/jrt_test/src/java/build.xml new file mode 100644 index 00000000000..1b9afee3d15 --- /dev/null +++ b/jrt_test/src/java/build.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project basedir="." default="all" name="jrt-test"> + <!-- Written to assume that classpath is rooted in the current directory. --> + <!-- So this should be OK if you make this script in the root of a filesystem. --> + <!-- If not, just change src.dir to be the root of your sources' package tree --> + <!-- and use e.g. View over a Filesystem to mount that subdirectory with all capabilities. --> + <!-- The idea is that both Ant and NetBeans have to know what the package root is --> + <!-- for the classes in your application. --> + + <!-- Don't worry if you don't know the Ant syntax completely or need help on some tasks! --> + <!-- The standard Ant documentation can be downloaded from AutoUpdate and --> + <!-- and then you can access the Ant manual in the online help. --> + + <property file="build.inc" /> + + <target name="init"> + <property location="classes" name="classes.dir"/> + <property location="." name="src.dir"/> + <property location="doc/api" name="javadoc.dir"/> + <property name="project.name" value="${ant.project.name}"/> + <property location="${project.name}.jar" name="jar"/> + </target> + + <target depends="init" name="compile"> + <!-- Both srcdir and destdir should be package roots. --> + <mkdir dir="${classes.dir}"/> + <javac debug="true" deprecation="true" destdir="${classes.dir}" srcdir="${src.dir}"> + <classpath> + <pathelement location="${JRT_DIR}/lib/jars/jrt.jar"/> + </classpath> + <!-- To add something to the classpath: --> + <!-- <classpath><pathelement location="${mylib}"/></classpath> --> + <!-- To exclude some files: --> + <!-- <exclude name="com/foo/SomeFile.java"/><exclude name="com/foo/somepackage/"/> --> + </javac> + </target> + + <target depends="init,compile" name="jar"> + <!-- To make a standalone app, insert into <jar>: --> + <!-- <manifest><attribute name="Main-Class" value="com.foo.Main"/></manifest> --> + <jar basedir="${classes.dir}" compress="true" jarfile="${jar}"/> + </target> + + <target depends="init,jar" description="Build everything." name="all"/> + + <target depends="init" description="Javadoc for my API." name="javadoc"> + <mkdir dir="${javadoc.dir}"/> + <javadoc destdir="${javadoc.dir}" packagenames="*"> + <sourcepath> + <pathelement location="${src.dir}"/> + </sourcepath> + </javadoc> + </target> + + <target depends="init" description="Clean all build products." name="clean"> + <delete dir="${classes.dir}"/> + <delete dir="${javadoc.dir}"/> + <delete file="${jar}"/> + </target> + +</project> |