From 696ca394d26ba077a5b2de16b13bc9a6b7411bfa Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Fri, 11 Sep 2020 19:15:52 +0800 Subject: [PATCH] Remove outdated Java doc and run demo code in CI (#10698) Resolve Conflicts: java/tutorial/pom.xml java/tutorial/pom_template.xml --- doc/source/index.rst | 12 +- doc/source/ray-overview/index.rst | 12 +- java/BUILD.bazel | 11 -- java/README.rst | 83 --------- java/doc/api.rst | 158 ------------------ java/doc/installation.rst | 56 ------- java/example.conf | 24 --- java/pom.xml | 1 - java/test.sh | 13 +- .../src/main/java/io/ray/docdemo/RayDemo.java | 69 ++++++++ .../java/io/ray/docdemo/UsingActorsDemo.java | 2 +- .../java/io/ray/docdemo/WalkthroughDemo.java | 2 +- java/tutorial/README.rst | 25 --- java/tutorial/pom.xml | 82 --------- java/tutorial/pom_template.xml | 78 --------- .../main/java/io/ray/exercise/Exercise01.java | 42 ----- .../main/java/io/ray/exercise/Exercise02.java | 49 ------ .../main/java/io/ray/exercise/Exercise03.java | 41 ----- .../main/java/io/ray/exercise/Exercise04.java | 59 ------- .../main/java/io/ray/exercise/Exercise05.java | 44 ----- java/tutorial/src/main/resources/ray.conf | 3 - 21 files changed, 95 insertions(+), 771 deletions(-) delete mode 100644 java/README.rst delete mode 100644 java/doc/api.rst delete mode 100644 java/doc/installation.rst delete mode 100644 java/example.conf create mode 100644 java/test/src/main/java/io/ray/docdemo/RayDemo.java delete mode 100644 java/tutorial/README.rst delete mode 100644 java/tutorial/pom.xml delete mode 100644 java/tutorial/pom_template.xml delete mode 100644 java/tutorial/src/main/java/io/ray/exercise/Exercise01.java delete mode 100644 java/tutorial/src/main/java/io/ray/exercise/Exercise02.java delete mode 100644 java/tutorial/src/main/java/io/ray/exercise/Exercise03.java delete mode 100644 java/tutorial/src/main/java/io/ray/exercise/Exercise04.java delete mode 100644 java/tutorial/src/main/java/io/ray/exercise/Exercise05.java delete mode 100644 java/tutorial/src/main/resources/ray.conf diff --git a/doc/source/index.rst b/doc/source/index.rst index 291f12b90..e306a5244 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -59,20 +59,20 @@ Ray provides Python and Java API. And Ray uses Tasks (functions) and Actors (Cla public class RayDemo { - public static int f(int x) { + public static int square(int x) { return x * x; } public static class Counter { - private int n = 0; + private int value = 0; public void increment() { - this.n += 1; + this.value += 1; } public int read() { - return this.n; + return this.value; } } @@ -81,10 +81,10 @@ Ray provides Python and Java API. And Ray uses Tasks (functions) and Actors (Cla Ray.init(); { List> objectRefList = new ArrayList<>(); - // Invoke the `f` method 4 times remotely as Ray tasks. + // Invoke the `square` method 4 times remotely as Ray tasks. // The tasks will run in parallel in the background. for (int i = 0; i < 4; i++) { - objectRefList.add(Ray.task(RayDemo::f, i).remote()); + objectRefList.add(Ray.task(RayDemo::square, i).remote()); } // Get the actual results of the tasks with `get`. System.out.println(Ray.get(objectRefList)); // [0, 1, 4, 9] diff --git a/doc/source/ray-overview/index.rst b/doc/source/ray-overview/index.rst index c565ccb2b..bd45faeab 100644 --- a/doc/source/ray-overview/index.rst +++ b/doc/source/ray-overview/index.rst @@ -50,7 +50,7 @@ Parallelizing Python/Java Functions with Ray Tasks public class RayDemo { - public static int f(int x) { + public static int square(int x) { return x * x; } @@ -58,10 +58,10 @@ Parallelizing Python/Java Functions with Ray Tasks // Intialize Ray runtime. Ray.init(); List> objectRefList = new ArrayList<>(); - // Invoke the `f` method 4 times remotely as Ray tasks. + // Invoke the `square` method 4 times remotely as Ray tasks. // The tasks will run in parallel in the background. for (int i = 0; i < 4; i++) { - objectRefList.add(Ray.task(RayDemo::f, i).remote()); + objectRefList.add(Ray.task(RayDemo::square, i).remote()); } // Get the actual results of the tasks. System.out.println(Ray.get(objectRefList)); // [0, 1, 4, 9] @@ -114,14 +114,14 @@ maintain its own internal state. public static class Counter { - private int n = 0; + private int value = 0; public void increment() { - this.n += 1; + this.value += 1; } public int read() { - return this.n; + return this.value; } } diff --git a/java/BUILD.bazel b/java/BUILD.bazel index a5fd3df8b..5f852af9c 100644 --- a/java/BUILD.bazel +++ b/java/BUILD.bazel @@ -13,7 +13,6 @@ all_modules = [ "api", "runtime", "test", - "tutorial", ] java_import( @@ -89,15 +88,6 @@ define_java_module( ], ) -define_java_module( - name = "tutorial", - deps = [ - ":io_ray_ray_api", - ":io_ray_ray_runtime", - "@maven//:com_google_guava_guava", - ], -) - define_java_module( name = "test", deps = [ @@ -231,7 +221,6 @@ genrule( WORK_DIR="$$(pwd)" cp -f $(location //java:io_ray_ray_api_pom) "$$WORK_DIR/java/api/pom.xml" cp -f $(location //java:io_ray_ray_runtime_pom) "$$WORK_DIR/java/runtime/pom.xml" - cp -f $(location //java:io_ray_ray_tutorial_pom) "$$WORK_DIR/java/tutorial/pom.xml" cp -f $(location //java:io_ray_ray_test_pom) "$$WORK_DIR/java/test/pom.xml" date > $@ """, diff --git a/java/README.rst b/java/README.rst deleted file mode 100644 index f774ce57e..000000000 --- a/java/README.rst +++ /dev/null @@ -1,83 +0,0 @@ -Quick start -=========== - -Configuration -------------- -Ray will read your configurations in the following order: - -* Java system properties: e.g., ``-Dray.run-mode=SINGLE_PROCESS``. -* A ``ray.conf`` file in the classpath: `example `_. -* Customise your own ``ray.conf`` path using system property ``-Dray.config=/path/to/ray.conf`` - -For all available config items and default values, see `this file `_. - -Starting Ray ------------- - -.. code:: java - - Ray.init(); - -Read and write remote objects ------------------------------ - -Each remote object is considered a ``RayObject`` where ``T`` is the -type for this object. You can use ``Ray.put`` and ``RayObject.get`` -to write and read the objects. - -.. code:: java - - Integer x = 1; - RayObject obj = Ray.put(x); - Integer x1 = obj.get(); - assert (x.equals(x1)); - -Remote functions ----------------- - -Here is an ordinary java code piece for composing -``hello world example``. - -.. code:: java - - public class ExampleClass { - public static void main(String[] args) { - String str1 = add("hello", "world"); - String str = add(str1, "example"); - System.out.println(str); - } - public static String add(String a, String b) { - return a + " " + b; - } - } - -We use ``@RayRemote`` to indicate that a function is remote, and use -``Ray.call`` to invoke it. The result from the latter is a -``RayObject`` where ``R`` is the return type of the target function. -The following shows the changed example with ``add`` annotated, and -correspondent calls executed on remote machines. - -.. code:: java - - public class ExampleClass { - public static void main(String[] args) { - Ray.init(); - RayObject objStr1 = Ray.call(ExampleClass::add, "hello", "world"); - RayObject objStr2 = Ray.call(ExampleClass::add, objStr1, "example"); - String str = objStr2.get(); - System.out.println(str); - } - - @RayRemote - public static String add(String a, String b) { - return a + " " + b; - } - } - -More information -================ - -- `Installation `_ -- `API document `_ -- `Tutorial `_ - diff --git a/java/doc/api.rst b/java/doc/api.rst deleted file mode 100644 index 4eb630fa5..000000000 --- a/java/doc/api.rst +++ /dev/null @@ -1,158 +0,0 @@ -Ray Java API -============ - -Basic API ---------- - -``Ray.init()`` -~~~~~~~~~~~~~~ - -``Ray.init`` is used to initialize Ray runtime. It should be called befored using -any other Ray APIs. - -``@RayRemote`` -~~~~~~~~~~~~~~ - -The ``@RayRemote`` annotation can be used to decorate static java -methods and classes. - -When the annotation is used on a static method, the target method becomes -a remote function. - -When the annotation is used on a class, the class becomes an actor class. -An actor is the encapsulation of state shared among many remote functions. - -``Ray.call`` -~~~~~~~~~~~~ - -``Ray.call`` is used to invoke a remote function. - -.. code:: java - - RayObject call(RayFunc func, ...); - -The parameters of ``Ray.call`` are the target method ``func``, followed by -its original parameters. - -- The return type of ``func`` must be ``R``. -- Currently at most 6 parameters of ``func`` are allowed. -- Each parameter can either be the raw type ``T``, or ``RayObject``. - -The returned object is labeled as ``RayObject`` and its value will be -put into the object store on the machine where the function call is executed. - -Example: - -.. code:: java - - public class Echo { - - @RayRemote - public static String echo(String str) { return str; } - - } - - RayObject res = Ray.call(Echo::echo, "hello"); - -``Ray.put`` -~~~~~~~~~~~ - -You can also invoke ``Ray.put`` to explicitly place an object into the object -store. - -.. code:: java - - public static RayObject put(T object); - -Example: - -.. code:: java - - RayObject fooObject = Ray.put("foo"); - -``RayObject.get`` -~~~~~~~~~~~~~~~~~~~~ - -.. code:: java - - public class RayObject { - public T get(); - } - -This method is used to fetch the value of this ``RayObject`` from the object store. -It will block the current thread until the requested data is locally available. - -Example: - -.. code:: java - - String foo = fooObject.get(); - -``Ray.wait`` -~~~~~~~~~~~~ - -``Ray.wait`` is used to wait for a list of ``RayObject``\s to be locally available. -It will block the current thread until ``numReturns`` objects are ready or -``timeoutMs`` has passed. - -.. code:: java - - public static WaitResult wait(List> waitList, int numReturns, int timeoutMs); - public static WaitResult wait(List> waitList, int numReturns); - public static WaitResult wait(List> waitList); - -Example: - -.. code:: java - - WaitResult waitResult = Ray.wait(waitList, 5, 1000); - // `ready` is a list of objects that is already in local object store. - List> ready = waitResult.getReady(); - // `unready` is the remaining objects that aren't in local object store. - List> unready = waitResult.getUnready(); - -Actor Support -------------- - -Create Actors -~~~~~~~~~~~~~ - -A regular class annotated with ``@RayRemote`` is an actor class. - -.. code:: java - - @RayRemote - public class Adder { - - private int sum; - - public Adder(int initValue) { - sum = initValue; - } - - public int add(int n) { - return sum += n; - } - } - -To create an actor instance, use ``Ray.createActor()``. - -.. code:: java - - RayActor adder = Ray.createActor(Adder::new, 0); - -Similar to ``Ray.call``, the first parameter of ``Ray.createActor`` is a method that returns an instance -of the Actor class (the method can be either a constructor, or any factory methods). The rest of the parameters are -the arguments of the method. - -Call Actor Methods -~~~~~~~~~~~~~~~~~~ - -``Ray.call`` is also used to call actor methods, where the actor instance must be the first parameter after the remote function. - -.. code:: java - - RayObject result1 = Ray.call(Adder::add, adder, 1); - System.out.println(result1.get()); // 1 - RayObject result2 = Ray.call(Adder::add, adder, 10); - System.out.println(result2.get()); // 11 diff --git a/java/doc/installation.rst b/java/doc/installation.rst deleted file mode 100644 index a956b0044..000000000 --- a/java/doc/installation.rst +++ /dev/null @@ -1,56 +0,0 @@ -Install Ray for Java -==================== - -Ray works for Java 8 and above. Currently, we only support building Ray from source. - -Build from source ------------------ - -Install dependencies -^^^^^^^^^^^^^^^^^^^^ - -First, make sure JDK 8 or above is installed on your machine. If not, you can download it from `here `_. - -Then install the following dependencies. - -For Ubuntu users, run the following commands: -:: - - sudo apt-get update - sudo apt-get install -y maven build-essential curl unzip psmisc python # we install python here because python2 is required to build the webui - - pip install cython==0.29.0 - -For macOS users, run the following commands: -:: - - brew update - brew install maven wget - - pip install cython==0.29.0 - -Build Ray -^^^^^^^^^ - -Then we can start building Ray with the following commands: -:: - - git clone https://github.com/ray-project/ray.git - cd ray - - # Install Bazel. - ci/travis/install-bazel.sh - - # build native components - ./build.sh -l java - - # build java API - cd java - mvn clean install -Dmaven.test.skip - -Run tests -^^^^^^^^^ -:: - - # in `ray/java` directory - mvn test diff --git a/java/example.conf b/java/example.conf deleted file mode 100644 index cbdaf781d..000000000 --- a/java/example.conf +++ /dev/null @@ -1,24 +0,0 @@ -# This is an example ray config file. -# To use this file, copy it to your classpath and rename it to 'ray.conf'. - -# For all available config items and default values, -# see 'java/runtime/src/main/resources/ray.default.conf'. -# For config file format, see 'https://github.com/lightbend/config/blob/master/HOCON.md'. - -ray { - // Run mode, available options are: - // - // `SINGLE_PROCESS`: Ray is running in one single Java process, without Raylet backend, - // object store, and GCS. It's useful for debug. - // `CLUSTER`: Ray is running on one or more nodes, with multiple processes. - run-mode = CLUSTER - - // Available resources on this node. - resources: "CPU:4" - - // The address of the redis server to connect, in format `ip:port`. - // If not provided, Ray processes will be started locally, including - // Redis server, Raylet and object store. - redis.address = "" - -} diff --git a/java/pom.xml b/java/pom.xml index a9251c85c..54b95d161 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -57,7 +57,6 @@ api runtime test - tutorial diff --git a/java/test.sh b/java/test.sh index 181c9bf36..37fcc0547 100755 --- a/java/test.sh +++ b/java/test.sh @@ -50,7 +50,7 @@ echo "Running tests under single-process mode." # bazel test //java:all_tests --jvmopt="-Dray.run-mode=SINGLE_PROCESS" --config=ci || single_exit_code=$? run_testng java -Dray.run-mode="SINGLE_PROCESS" -cp "$ROOT_DIR"/../bazel-bin/java/all_tests_deploy.jar "${TEST_ARGS[@]}" org.testng.TestNG -d /tmp/ray_java_test_output "$ROOT_DIR"/testng.xml -echo "Running connecting existing cluster tests" +echo "Running connecting existing cluster tests." case "${OSTYPE}" in linux*) ip=$(hostname -I | awk '{print $1}');; darwin*) ip=$(ipconfig getifaddr en0);; @@ -60,8 +60,19 @@ RAY_BACKEND_LOG_LEVEL=debug ray start --head --port=6379 --redis-password=123456 RAY_BACKEND_LOG_LEVEL=debug java -cp bazel-bin/java/all_tests_deploy.jar -Dray.address="$ip:6379"\ -Dray.redis.password='123456' -Dray.job.code-search-path="$PWD/bazel-bin/java/all_tests_deploy.jar" io.ray.test.MultiDriverTest ray stop + +echo "Running documentation demo code." +docdemo_path="java/test/src/main/java/io/ray/docdemo/" +for file in "$docdemo_path"*.java; do + file=${file#"$docdemo_path"} + class=${file%".java"} + echo "Running $class" + java -cp bazel-bin/java/all_tests_deploy.jar "io.ray.docdemo.$class" +done + popd + pushd "$ROOT_DIR" echo "Testing maven install." mvn -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN clean install -DskipTests diff --git a/java/test/src/main/java/io/ray/docdemo/RayDemo.java b/java/test/src/main/java/io/ray/docdemo/RayDemo.java new file mode 100644 index 000000000..90f76694e --- /dev/null +++ b/java/test/src/main/java/io/ray/docdemo/RayDemo.java @@ -0,0 +1,69 @@ +package io.ray.docdemo; + +import io.ray.api.ActorHandle; +import io.ray.api.ObjectRef; +import io.ray.api.Ray; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * This class contains demo code of the Ray introduction doc + * (https://docs.ray.io/en/master/index.html and https://docs.ray.io/en/master/ray-overview/index.html). + * + * Please keep them in sync. + */ +public class RayDemo { + + public static int square(int x) { + return x * x; + } + + public static class Counter { + + private int value = 0; + + public void increment() { + this.value += 1; + } + + public int read() { + return this.value; + } + } + + public static void main(String[] args) { + // Intialize Ray runtime. + Ray.init(); + { + List> objectRefList = new ArrayList<>(); + // Invoke the `square` method 4 times remotely as Ray tasks. + // The tasks will run in parallel in the background. + for (int i = 0; i < 4; i++) { + objectRefList.add(Ray.task(RayDemo::square, i).remote()); + } + // Get the actual results of the tasks with `get`. + System.out.println(Ray.get(objectRefList)); // [0, 1, 4, 9] + } + + { + List> counters = new ArrayList<>(); + // Create 4 actors from the `Counter` class. + // They will run in remote worker processes. + for (int i = 0; i < 4; i++) { + counters.add(Ray.actor(Counter::new).remote()); + } + + // Invoke the `increment` method on each actor. + // This will send an actor task to each remote actor. + for (ActorHandle counter : counters) { + counter.task(Counter::increment).remote(); + } + // Invoke the `read` method on each actor, and print the results. + List> objectRefList = counters.stream() + .map(counter -> counter.task(Counter::read).remote()) + .collect(Collectors.toList()); + System.out.println(Ray.get(objectRefList)); // [1, 1, 1, 1] + } + } +} diff --git a/java/test/src/main/java/io/ray/docdemo/UsingActorsDemo.java b/java/test/src/main/java/io/ray/docdemo/UsingActorsDemo.java index aa1d356f5..8d86d8c7e 100644 --- a/java/test/src/main/java/io/ray/docdemo/UsingActorsDemo.java +++ b/java/test/src/main/java/io/ray/docdemo/UsingActorsDemo.java @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit; import org.testng.Assert; /** - * This class contains demo code of the Ray core Using Actors doc (https://docs.ray.io/en/latest/actors.html). + * This class contains demo code of the Ray core Using Actors doc (https://docs.ray.io/en/master/actors.html). * * Please keep them in sync. */ diff --git a/java/test/src/main/java/io/ray/docdemo/WalkthroughDemo.java b/java/test/src/main/java/io/ray/docdemo/WalkthroughDemo.java index 960ddf0b5..da6e21e54 100644 --- a/java/test/src/main/java/io/ray/docdemo/WalkthroughDemo.java +++ b/java/test/src/main/java/io/ray/docdemo/WalkthroughDemo.java @@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit; import org.testng.Assert; /** - * This class contains demo code of the Ray core walkthrough doc (https://docs.ray.io/en/latest/walkthrough.html). + * This class contains demo code of the Ray core walkthrough doc (https://docs.ray.io/en/master/walkthrough.html). * * Please keep them in sync. */ diff --git a/java/tutorial/README.rst b/java/tutorial/README.rst deleted file mode 100644 index 95bf08d60..000000000 --- a/java/tutorial/README.rst +++ /dev/null @@ -1,25 +0,0 @@ -Ray Java Tutorial -================= - -- `Installation guide `_ -- `API document `_ - -Exercises ---------- - -Each file of ``java/example/src/main/java/io/ray/exercise/Exercise*.java`` is a separate exercise. -To run them, execute the following command under ``ray/java`` folder. - -.. code-block:: shell - - java -classpath "tutorial/target/ray-tutorial-1.0.jar:tutorial/lib/*" Exercise01 - -`Exercise 1 `_: Define a remote function, and execute multiple remote functions in parallel. - -`Exercise 2 `_: Execute remote functions in parallel with some dependencies. - -`Exercise 3 `_: Call remote functions from within remote functions. - -`Exercise 4 `_: Use ``Ray.wait`` to ignore stragglers. - -`Exercise 5 `_: Actor Support of create Actor and call Actor method. diff --git a/java/tutorial/pom.xml b/java/tutorial/pom.xml deleted file mode 100644 index 2cc6dcec1..000000000 --- a/java/tutorial/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - io.ray - ray-superpom - 1.0.0 - - 4.0.0 - - ray-tutorial - - java tutorial - Tutorial of using Ray with Java - - jar - - - true - - - - - io.ray - ray-api - ${project.version} - - - io.ray - ray-runtime - ${project.version} - - - com.google.guava - guava - 27.0.1-jre - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20.1 - - - ${basedir}/../ray.config.ini - - -ea - -Djava.library.path=${basedir}/../../build/src/plasma:${basedir}/../../build/src/ray/raylet - -noverify - -DlogOutput=console - - ${basedir}/src/main/java/ - ${project.build.directory}/classes/ - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - ${basedir}/lib - false - false - true - - - - - - - diff --git a/java/tutorial/pom_template.xml b/java/tutorial/pom_template.xml deleted file mode 100644 index 2ff7d9458..000000000 --- a/java/tutorial/pom_template.xml +++ /dev/null @@ -1,78 +0,0 @@ - -{auto_gen_header} - - - - io.ray - ray-superpom - 1.0.0 - - 4.0.0 - - ray-tutorial - - java tutorial - Tutorial of using Ray with Java - - jar - - - true - - - - - io.ray - ray-api - ${project.version} - - - io.ray - ray-runtime - ${project.version} - -{generated_bzl_deps} - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20.1 - - - ${basedir}/../ray.config.ini - - -ea - -Djava.library.path=${basedir}/../../build/src/plasma:${basedir}/../../build/src/ray/raylet - -noverify - -DlogOutput=console - - ${basedir}/src/main/java/ - ${project.build.directory}/classes/ - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - ${basedir}/lib - false - false - true - - - - - - - diff --git a/java/tutorial/src/main/java/io/ray/exercise/Exercise01.java b/java/tutorial/src/main/java/io/ray/exercise/Exercise01.java deleted file mode 100644 index 2b743006e..000000000 --- a/java/tutorial/src/main/java/io/ray/exercise/Exercise01.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.ray.exercise; - -import io.ray.api.ObjectRef; -import io.ray.api.Ray; -import java.io.Serializable; - -/** - * Define a remote function, and execute multiple remote functions in parallel. - */ -public class Exercise01 implements Serializable { - - /** - * A plain remote function. - */ - public static String sayHello() { - String ret = "hello"; - System.out.println(ret); - return ret; - } - - public static String sayWorld() { - String ret = "world!"; - System.out.println(ret); - return ret; - } - - public static void main(String[] args) throws Exception { - try { - // Use `Ray.init` to initialize the Ray runtime. - Ray.init(); - // Use `Ray.call` to call a remote function. - ObjectRef hello = Ray.task(Exercise01::sayHello).remote(); - ObjectRef world = Ray.task(Exercise01::sayWorld).remote(); - System.out.println("First remote call result:" + hello.get()); - System.out.println("Second remote call result:" + world.get()); - } catch (Throwable t) { - t.printStackTrace(); - } finally { - Ray.shutdown(); - } - } -} diff --git a/java/tutorial/src/main/java/io/ray/exercise/Exercise02.java b/java/tutorial/src/main/java/io/ray/exercise/Exercise02.java deleted file mode 100644 index 7dc47009b..000000000 --- a/java/tutorial/src/main/java/io/ray/exercise/Exercise02.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.ray.exercise; - -import io.ray.api.ObjectRef; -import io.ray.api.Ray; - -/** - * Execute remote functions in parallel with some dependencies. - */ -public class Exercise02 { - - public static String sayHello() { - String ret = "hello"; - System.out.println(ret); - return ret; - } - - public static String sayWorld() { - String ret = "world!"; - System.out.println(ret); - return ret; - } - - /** - * A remote function with dependency. - */ - public static String merge(String hello, String world) { - return hello + "," + world; - } - - public static String sayHelloWorld() { - ObjectRef hello = Ray.task(Exercise02::sayHello).remote(); - ObjectRef world = Ray.task(Exercise02::sayWorld).remote(); - // Pass unfinished results as the parameters to another remote function. - return Ray.task(Exercise02::merge, hello, world).remote().get(); - } - - public static void main(String[] args) throws Exception { - try { - Ray.init(); - String helloWorld = Exercise02.sayHelloWorld(); - System.out.println(helloWorld); - assert helloWorld.equals("hello,world!"); - } catch (Throwable t) { - t.printStackTrace(); - } finally { - Ray.shutdown(); - } - } -} diff --git a/java/tutorial/src/main/java/io/ray/exercise/Exercise03.java b/java/tutorial/src/main/java/io/ray/exercise/Exercise03.java deleted file mode 100644 index cebf9a0a3..000000000 --- a/java/tutorial/src/main/java/io/ray/exercise/Exercise03.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.ray.exercise; - -import io.ray.api.ObjectRef; -import io.ray.api.Ray; - -/** - * Call a remote function from within another remote function. - */ -public class Exercise03 { - - /** - * A remote function which will call another remote function. - */ - public static String sayHelloWithWorld() { - String ret = "hello"; - System.out.println(ret); - ObjectRef world = Ray.task(Exercise03::sayWorld).remote(); - return ret + "," + world.get(); - } - - /** - * A remote function which will be called by another remote function. - */ - public static String sayWorld() { - String ret = "world!"; - System.out.println(ret); - return ret; - } - - public static void main(String[] args) throws Exception { - try { - Ray.init(); - String helloWithWorld = Ray.task(Exercise03::sayHelloWithWorld).remote().get(); - System.out.println(helloWithWorld); - } catch (Throwable t) { - t.printStackTrace(); - } finally { - Ray.shutdown(); - } - } -} diff --git a/java/tutorial/src/main/java/io/ray/exercise/Exercise04.java b/java/tutorial/src/main/java/io/ray/exercise/Exercise04.java deleted file mode 100644 index 7c2e56739..000000000 --- a/java/tutorial/src/main/java/io/ray/exercise/Exercise04.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.ray.exercise; - -import com.google.common.collect.ImmutableList; -import io.ray.api.ObjectRef; -import io.ray.api.Ray; -import io.ray.api.WaitResult; -import java.util.List; - -/** - * Use Ray.wait to ignore stragglers - */ -public class Exercise04 { - - public static String f1() { - System.out.println("Executing f1"); - return "f1"; - } - - public static String f2() { - System.out.println("Executing f2"); - return "f2"; - } - - /** - * A slow remote function. - */ - public static String f3() { - System.out.println("Executing f3"); - try { - Thread.sleep(5000L); - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("Finished executing f3"); - return "f3"; - } - - public static void main(String[] args) throws Exception { - try { - Ray.init(); - List> waitList = ImmutableList.of( - Ray.task(Exercise04::f1).remote(), - Ray.task(Exercise04::f2).remote(), - Ray.task(Exercise04::f3).remote() - ); - // Ray.wait will block until specified number of results are ready - // or specified timeout have passed. - // In this case, the result of f3 will be ignored. - WaitResult waitResult = Ray.wait(waitList, 2, 3000); - System.out.printf("%d ready object(s): \n", waitResult.getReady().size()); - waitResult.getReady().forEach(rayObject -> System.out.println(rayObject.get())); - System.out.printf("%d unready object(s): \n", waitResult.getUnready().size()); - } catch (Throwable t) { - t.printStackTrace(); - } finally { - Ray.shutdown(); - } - } -} diff --git a/java/tutorial/src/main/java/io/ray/exercise/Exercise05.java b/java/tutorial/src/main/java/io/ray/exercise/Exercise05.java deleted file mode 100644 index e89412770..000000000 --- a/java/tutorial/src/main/java/io/ray/exercise/Exercise05.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.ray.exercise; - -import io.ray.api.ActorHandle; -import io.ray.api.ObjectRef; -import io.ray.api.Ray; - -/** - * Show usage of actors. - */ -public class Exercise05 { - - public static void main(String[] args) { - try { - Ray.init(); - // `Ray.createActor` creates an actor instance. - ActorHandle adder = Ray.actor(Adder::new, 0).remote(); - // Use `Ray.task(actor, parameters).remote()` to call an actor method. - ObjectRef result1 = adder.task(Adder::add, 1).remote(); - System.out.println(result1.get()); - ObjectRef result2 = adder.task(Adder::add, 10).remote(); - System.out.println(result2.get()); - } catch (Throwable t) { - t.printStackTrace(); - } finally { - Ray.shutdown(); - } - } - - /** - * An example actor. - */ - public static class Adder { - - public Adder(int initValue) { - sum = initValue; - } - - public int add(int n) { - return sum += n; - } - - private int sum; - } -} diff --git a/java/tutorial/src/main/resources/ray.conf b/java/tutorial/src/main/resources/ray.conf deleted file mode 100644 index d4c2ca1cd..000000000 --- a/java/tutorial/src/main/resources/ray.conf +++ /dev/null @@ -1,3 +0,0 @@ -ray { - run-mode: CLUSTER -}