ray/java
Wang Qing 514633456b [Java] Fix out-dated signatures of JNI methods (#2756)
1) Renamed the native JNI methods and some parameters of JNI methods. 
2) Fixed native JNI methods' signatures by `javah` tool.
3) Removed some useless native methods.
2018-08-30 17:59:29 +08:00
..
api [java] Fix the logic of generating TaskID (#2747) 2018-08-27 13:11:33 -07:00
cli [Java] Change log dir to /tmp/raylogs (#2677) 2018-08-18 23:46:36 -07:00
common [java] Remove multi-return API (#2724) 2018-08-26 00:04:54 -07:00
doc [java] Remove multi-return API (#2724) 2018-08-26 00:04:54 -07:00
runtime-common [Java] Fix out-dated signatures of JNI methods (#2756) 2018-08-30 17:59:29 +08:00
runtime-dev [Java] Fix out-dated signatures of JNI methods (#2756) 2018-08-30 17:59:29 +08:00
runtime-native [Java] Fix out-dated signatures of JNI methods (#2756) 2018-08-30 17:59:29 +08:00
test [java] Fix the logic of generating TaskID (#2747) 2018-08-27 13:11:33 -07:00
tutorial [java] Remove multi-return API (#2724) 2018-08-26 00:04:54 -07:00
build.sh [JavaWorker] Enable java worker support (#2094) 2018-05-26 14:38:50 -07:00
checkstyle-suppressions.xml [java] Remove multi-return API (#2724) 2018-08-26 00:04:54 -07:00
checkstyle.xml [JavaWorker] Java code lint check and binding to CI (#2225) 2018-06-09 16:26:54 -07:00
cleanup.sh Upgrade arrow to include more detailed flushing message (#2706) 2018-08-24 11:44:04 -07:00
logfilter.sh [JavaWorker] Enable java worker support (#2094) 2018-05-26 14:38:50 -07:00
pom.xml [multi-language part 1] add a 'language' field to task specification (#2639) 2018-08-16 21:26:42 -07:00
prepare.sh Upgrade arrow to include more detailed flushing message (#2706) 2018-08-24 11:44:04 -07:00
ray.config.ini Upgrade arrow to include more detailed flushing message (#2706) 2018-08-24 11:44:04 -07:00
README.rst add java tutorial (#2491) 2018-07-28 17:09:30 -07:00
run.sh [Java] Java worker cluster support (#2359) 2018-07-09 10:20:41 -07:00
test.sh Support building Java and Python version at the same time. (#2640) 2018-08-14 11:33:51 -07:00
test_cluster.sh add java tutorial (#2491) 2018-07-28 17:09:30 -07:00

This directory contains the java worker, with the following components.

-  java/api: Ray API definition
-  java/common: utilities
-  java/runtime-common: common implementation of the runtime in worker
-  java/runtime-dev: a pure-java mock implementation of the runtime for
   fast development
-  java/runtime-native: a native implementation of the runtime
-  java/test: various tests
-  src/local\_scheduler/lib/java: JNI client library for local scheduler
-  src/plasma/lib/java: JNI client library for plasma storage

Quick start
===========

Starting Ray
------------

.. code:: java

    Ray.init();

Read and write remote objects
-----------------------------

Each remote object is considered a ``RayObject<T>`` where ``T`` is the
type for this object. You can use ``Ray.put`` and ``RayObject<T>.get``
to write and read the objects.

.. code:: java

    Integer x = 1;
    RayObject<Integer> 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<R>`` 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<String> objStr1 = Ray.call(ExampleClass::add, "hello", "world");
            RayObject<String> 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 <https://github.com/ray-project/ray/tree/master/java/doc/installation.rst>`_
- `API document <https://github.com/ray-project/ray/tree/master/java/doc/api.rst>`_
- `Tutorial <https://github.com/ray-project/ray/tree/master/java/tutorial>`_