ray/java
fyrestone fc6259a656
Cross language serialization for primitive types (#7711)
* Cross language serialization for Java and Python

* Use strict types when Python serializing

* Handle recursive objects in Python; Pin msgpack >= 0.6.0, < 1.0.0

* Disable gc for optimizing msgpack loads

* Fix merge bug

* Java call Python use returnType; Fix ClassLoaderTest

* Fix RayMethodsTest

* Fix checkstyle

* Fix lint

* prepare_args raises exception if try to transfer a non-deserializable object to another language

* Fix CrossLanguageInvocationTest.java, Python msgpack treat float as double

* Minor fixes

* Fix compile error on linux

* Fix lint in java/BUILD.bazel

* Fix test_failure

* Fix lint

* Class<?> to Class<T>; Refine metadata bytes.

* Rename FST to Fst; sort java dependencies

* Change Class<?>[] to Optional<Class<?>>; sort requirements in setup.py

* Improve CrossLanguageInvocationTest

* Refactor MessagePackSerializer.java

* Refactor MessagePackSerializer.java; Refine CrossLanguageInvocationTest.java

* Remove unnecessary dependencies for Java; Add getReturnType() for RayFunction in Java

* Fix bug

* Remove custom cross language type support

* Replace Serializer.Meta with MutableBoolean

* Remove @SuppressWarnings support from checkstyle.xml; Add null test in CrossLanguageInvocationTest.java

* Refine MessagePackSerializer.pack

* Ray.get support RayObject as input

* Improve comments and error info

* Remove classLoader argument from serializer

* Separate msgpack from pickle5 in Python

* Pair<byte[], MutableBoolean> to Pair<byte[], Boolean>

* Remove public static <T> T get(RayObject<T> object), use RayObject.get() instead

* Refine test

* small fixes

Co-authored-by: 刘宝 <po.lb@antfin.com>
Co-authored-by: Hao Chen <chenh1024@gmail.com>
2020-04-08 21:10:57 +08:00
..
api Cross language serialization for primitive types (#7711) 2020-04-08 21:10:57 +08:00
doc Remove pytest from setup.py and other minor changes. (#7700) 2020-03-23 08:46:56 -07:00
runtime Cross language serialization for primitive types (#7711) 2020-04-08 21:10:57 +08:00
test Cross language serialization for primitive types (#7711) 2020-04-08 21:10:57 +08:00
tutorial [Java] New Java actor API (#7414) 2020-03-04 22:39:23 +08:00
BUILD.bazel Cross language serialization for primitive types (#7711) 2020-04-08 21:10:57 +08:00
checkstyle-suppressions.xml [Java] New Java actor API (#7414) 2020-03-04 22:39:23 +08: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 Cross language serialization for primitive types (#7711) 2020-04-08 21:10:57 +08:00
example.conf Updating zero capacity resource semantics (#4555) 2019-04-12 16:53:57 -07:00
generate_jni_header_files.sh Support multiple core workers in one process (#7623) 2020-04-07 11:01:47 +08:00
modify_generated_java_flatbuffers_files.py Remove future imports (#6724) 2020-01-09 00:15:48 -08:00
pom.xml enable maven checkstyle (#6829) 2020-01-20 23:41:54 -08:00
README.rst [Java] Package native dependencies into jar (#4367) 2019-03-15 12:38:40 +08:00
test.sh [Java] Enable direct call by default. (#7408) 2020-03-13 12:25:30 +08:00
testng.xml [Java] Support direct call for normal tasks (#7193) 2020-02-21 10:03:34 +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>`_