ray/java
2019-07-12 19:00:13 +08:00
..
api [ID Refactor] Shorten the length of JobID to 4 bytes (#5110) 2019-07-11 14:25:16 +08:00
doc Update installation instructions to include bazel and remove outdated… (#4171) 2019-02-26 23:07:43 -08:00
runtime Fix GcsClient resource map (#5171) 2019-07-11 16:05:12 +08:00
streaming Fix pom file generation (#4800) 2019-05-17 10:56:39 +08:00
test Fix Java MultithreadingTest (#5182) 2019-07-12 19:00:13 +08:00
tutorial [Java][Bazel] Refine auto-generated pom files (#4780) 2019-05-16 11:19:31 +08:00
BUILD.bazel Define common data structures with protobuf. (#5121) 2019-07-08 22:41:37 +08:00
checkstyle-suppressions.xml [Java] Upgrade checkstyle plugin (#4375) 2019-03-15 11:36:09 -07:00
checkstyle.xml [Java] lint unused imports (#4100) 2019-02-20 12:37:04 -08:00
cleanup.sh [Java] fix java/cleanup.sh (#2989) 2018-09-28 21:31:47 -05:00
dependencies.bzl Define common data structures with protobuf. (#5121) 2019-07-08 22:41:37 +08:00
example.conf Updating zero capacity resource semantics (#4555) 2019-04-12 16:53:57 -07:00
modify_generated_java_flatbuffers_files.py [gRPC] Migrate gcs data structures to protobuf (#5024) 2019-06-25 14:31:19 -07:00
pom.xml [Java][Bazel] Refine auto-generated pom files (#4780) 2019-05-16 11:19:31 +08:00
README.rst [Java] Package native dependencies into jar (#4367) 2019-03-15 12:38:40 +08:00
test.sh Fix pom file generation (#4800) 2019-05-17 10:56:39 +08:00
testng.xml [Java] TestNG outputs more verbose error messages (#4507) 2019-04-02 17:41:20 +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>`_