ray/java
2020-09-05 10:15:52 +08:00
..
api Java doc: "Starting Ray" page (#10062) 2020-09-05 10:15:52 +08:00
doc Remove pytest from setup.py and other minor changes. (#7700) 2020-03-23 08:46:56 -07:00
runtime Java doc: "Starting Ray" page (#10062) 2020-09-05 10:15:52 +08:00
test [Java] Throw exception if Ray.init() is not called and users try to access ray API (#10497) 2020-09-05 10:09:19 +08:00
tutorial change version from 0.1-SNAPSHOT to 0.9.0-SNAPSHOT (#9778) 2020-08-01 22:38:22 +08:00
build-jar-multiplatform.sh [dist] Mvn deploy (#9777) 2020-07-30 11:48:31 +08:00
BUILD.bazel Cross language exception (#10023) 2020-08-26 10:46:05 +08:00
checkstyle-suppressions.xml [Java] Local and distributed ref counting in Java (#9371) 2020-07-31 11:49:31 +08:00
checkstyle.xml [Java] lint unused imports (#4100) 2019-02-20 12:37:04 -08:00
cleanup.sh Shellcheck comments (#9595) 2020-07-21 16:47:09 -05:00
dependencies.bzl [Java] add maven repo (#10109) 2020-08-14 11:31:01 -07:00
example.conf Updating zero capacity resource semantics (#4555) 2019-04-12 16:53:57 -07:00
generate_jni_header_files.sh Shellcheck quoting (#9596) 2020-07-21 21:56:41 -05:00
modify_generated_java_flatbuffers_files.py [Java] Rename group id and package name. (#7864) 2020-04-12 17:59:34 +08:00
pom.xml [1.0] Simple, universal instead of Simple and universal (#10587) 2020-09-04 14:04:29 -07:00
README.rst [Java] Package native dependencies into jar (#4367) 2019-03-15 12:38:40 +08:00
test.sh [Java] Simplify ray cmd params (#10394) 2020-09-02 19:47:52 +08:00
testng.xml [Java] Use test groups to filter tests of different run modes (#9703) 2020-07-29 11:18:45 +08:00

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 <https://github.com/ray-project/ray/blob/master/java/example.conf>`_.
* 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 <https://github.com/ray-project/ray/blob/master/java/runtime/src/main/resources/ray.default.conf>`_.

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>`_