mirror of
https://github.com/wassname/ray.git
synced 2026-07-01 08:02:33 +08:00
[JavaWorker] Enable java worker support (#2094)
* Enable java worker support -------------------------- This commit includes a tailored version of the Java worker implementation from Ant Financial. The changes for build system, python module, src module and arrow are in other commits, this commit consists of the following modules: - java/api: Ray API definition - java/common: utilities - java/hook: binary rewrite of the Java byte-code for remote execution - 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 Contributors for this work: Guyang Song, Peng Cao, Senlin Zhu,Xiaoying Chu, Yiming Yu, Yujie Liu, Zhenyu Guo * change the format of java help document from markdown to RST * update the vesion of Arrow for java worker * adapt the new version of plasma java client from arrow which use byte[] instead of custom type * add java worker test to ci * add the example module for better usage guide
This commit is contained in:
committed by
Philipp Moritz
parent
74cca3b284
commit
a8d3c057c1
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.ray.parent</groupId>
|
||||
<artifactId>ray-superpom</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.ray</groupId>
|
||||
<artifactId>ray-api</artifactId>
|
||||
<name>java api for ray</name>
|
||||
<description>java api for ray</description>
|
||||
<url></url>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ray</groupId>
|
||||
<artifactId>ray-common</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.ruedigermoeller</groupId>
|
||||
<artifactId>fst</artifactId>
|
||||
<version>2.47</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.arrow</groupId>
|
||||
<artifactId>arrow-plasma</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,119 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.util.List;
|
||||
import org.ray.api.internal.RayConnector;
|
||||
import org.ray.util.exception.TaskExecutionException;
|
||||
import org.ray.util.logger.DynamicLog;
|
||||
import org.ray.util.logger.RayLog;
|
||||
|
||||
/**
|
||||
* Ray API
|
||||
*/
|
||||
public final class Ray extends Rpc {
|
||||
|
||||
/**
|
||||
* initialize the current worker or the single-box cluster
|
||||
*/
|
||||
public static void init() {
|
||||
if (impl == null) {
|
||||
impl = RayConnector.run();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put obj into object store
|
||||
*/
|
||||
public static <T> RayObject<T> put(T obj) {
|
||||
return impl.put(obj);
|
||||
}
|
||||
|
||||
public static <T, TM> RayObject<T> put(T obj, TM metadata) {
|
||||
return impl.put(obj, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get obj(s) from object store
|
||||
*/
|
||||
static <T> T get(UniqueID objectId) throws TaskExecutionException {
|
||||
return impl.get(objectId);
|
||||
}
|
||||
|
||||
static <T> T getMeta(UniqueID objectId) throws TaskExecutionException {
|
||||
return impl.getMeta(objectId);
|
||||
}
|
||||
|
||||
static <T> List<T> get(List<UniqueID> objectIds) throws TaskExecutionException {
|
||||
return impl.get(objectIds);
|
||||
}
|
||||
|
||||
static <T> List<T> getMeta(List<UniqueID> objectIds) throws TaskExecutionException {
|
||||
return impl.getMeta(objectIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* wait until timeout or enough RayObject are ready
|
||||
*
|
||||
* @param waitfor wait for who
|
||||
* @param numReturns how many of ready is enough
|
||||
* @param timeoutMilliseconds in millisecond
|
||||
*/
|
||||
public static <T> WaitResult<T> wait(RayList<T> waitfor, int numReturns,
|
||||
int timeoutMilliseconds) {
|
||||
return impl.wait(waitfor, numReturns, timeoutMilliseconds);
|
||||
}
|
||||
|
||||
public static <T> WaitResult<T> wait(RayList<T> waitfor, int numReturns) {
|
||||
return impl.wait(waitfor, numReturns, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public static <T> WaitResult<T> wait(RayList<T> waitfor) {
|
||||
return impl.wait(waitfor, waitfor.size(), Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public static <T> WaitResult<T> wait(RayObject<T> waitfor, int timeoutMilliseconds) {
|
||||
RayList<T> waits = new RayList<>();
|
||||
waits.add(waitfor);
|
||||
return impl.wait(waits, 1, timeoutMilliseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* create actor object
|
||||
*/
|
||||
public static <T> RayActor<T> create(Class<T> cls) {
|
||||
try {
|
||||
if (cls.getConstructor() == null) {
|
||||
System.err.println("class " + cls.getName()
|
||||
+ " does not (actors must) have a constructor with no arguments");
|
||||
RayLog.core.error("class " + cls.getName()
|
||||
+ " does not (actors must) have a constructor with no arguments");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.exit(1);
|
||||
return null;
|
||||
}
|
||||
return impl.create(cls);
|
||||
}
|
||||
|
||||
/**
|
||||
* get underlying runtime
|
||||
*/
|
||||
static RayApi internal() {
|
||||
return impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether to use remote lambda
|
||||
*/
|
||||
public static boolean isRemoteLambda() {
|
||||
return impl.isRemoteLambda();
|
||||
}
|
||||
|
||||
private static RayApi impl = null;
|
||||
|
||||
/**
|
||||
* for ray's app's log
|
||||
*/
|
||||
public static DynamicLog getRappLogger() {
|
||||
return RayLog.rapp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import org.ray.util.Sha1Digestor;
|
||||
|
||||
/**
|
||||
* Ray actor abstraction
|
||||
*/
|
||||
public class RayActor<T> extends RayObject<T> implements Externalizable {
|
||||
|
||||
private static final long serialVersionUID = 1877485807405645036L;
|
||||
|
||||
private int taskCounter = 0;
|
||||
|
||||
private UniqueID taskCursor = null;
|
||||
|
||||
private UniqueID actorHandleId = UniqueID.nil;
|
||||
|
||||
private int forksNum = 0;
|
||||
|
||||
public RayActor() {
|
||||
}
|
||||
|
||||
public RayActor(UniqueID id) {
|
||||
super(id);
|
||||
this.taskCounter = 1;
|
||||
}
|
||||
|
||||
public RayActor(UniqueID id, UniqueID actorHandleId) {
|
||||
super(id);
|
||||
this.actorHandleId = actorHandleId;
|
||||
this.taskCounter = 0;
|
||||
}
|
||||
|
||||
public int increaseTaskCounter() {
|
||||
return taskCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>taskCursor</tt>
|
||||
*
|
||||
* @return property value of taskCursor
|
||||
*/
|
||||
public UniqueID getTaskCursor() {
|
||||
return taskCursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>taskCursor</tt>
|
||||
*
|
||||
* @param taskCursor value to be assigned to property taskCursor
|
||||
*/
|
||||
public void setTaskCursor(UniqueID taskCursor) {
|
||||
this.taskCursor = taskCursor;
|
||||
}
|
||||
|
||||
public UniqueID computeNextActorHandleId() {
|
||||
byte[] bytes = Sha1Digestor.digest(actorHandleId.id, ++forksNum);
|
||||
return new UniqueID(bytes);
|
||||
}
|
||||
|
||||
public UniqueID getActorHandleId() {
|
||||
return actorHandleId;
|
||||
}
|
||||
|
||||
public void setActorHandleId(UniqueID actorHandleId) {
|
||||
this.actorHandleId = actorHandleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeObject(this.id);
|
||||
out.writeObject(this.computeNextActorHandleId());
|
||||
out.writeObject(this.taskCursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
|
||||
this.id = (UniqueID) in.readObject();
|
||||
this.actorHandleId = (UniqueID) in.readObject();
|
||||
this.taskCursor = (UniqueID) in.readObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.ray.api.internal.Callable;
|
||||
import org.ray.util.exception.TaskExecutionException;
|
||||
|
||||
/**
|
||||
* Ray runtime abstraction
|
||||
*/
|
||||
public interface RayApi {
|
||||
|
||||
/**
|
||||
* Put obj into object store
|
||||
*
|
||||
* @return RayObject
|
||||
*/
|
||||
<T> RayObject<T> put(T obj);
|
||||
|
||||
<T, TM> RayObject<T> put(T obj, TM metadata);
|
||||
|
||||
/**
|
||||
* Get real obj from object store
|
||||
*/
|
||||
<T> T get(UniqueID objectId) throws TaskExecutionException;
|
||||
|
||||
<T> T getMeta(UniqueID objectId) throws TaskExecutionException;
|
||||
|
||||
/**
|
||||
* Get real objects from object store
|
||||
*
|
||||
* @param objectIds list of ids of objects to get
|
||||
*/
|
||||
<T> List<T> get(List<UniqueID> objectIds) throws TaskExecutionException;
|
||||
|
||||
<T> List<T> getMeta(List<UniqueID> objectIds) throws TaskExecutionException;
|
||||
|
||||
/**
|
||||
* wait until timeout or enough RayObjects are ready
|
||||
*
|
||||
* @param waitfor wait for who
|
||||
* @param numReturns how many of ready is enough
|
||||
* @param timeout in millisecond
|
||||
*/
|
||||
<T> WaitResult<T> wait(RayList<T> waitfor, int numReturns, int timeout);
|
||||
|
||||
/**
|
||||
* create remote actor
|
||||
*/
|
||||
<T> RayActor<T> create(Class<T> cls);
|
||||
|
||||
/**
|
||||
* submit a new task by invoking a remote function
|
||||
*
|
||||
* @param taskId nil
|
||||
* @param funcRun the target running function with @RayRemote
|
||||
* @param returnCount the number of to-be-returned objects from funcRun
|
||||
* @param args arguments to this funcRun, can be its original form or RayObject<original-type>
|
||||
* @return a set of ray objects with their return ids
|
||||
*/
|
||||
RayObjects call(UniqueID taskId, Callable funcRun, int returnCount, Object... args);
|
||||
|
||||
RayObjects call(UniqueID taskId, Class<?> funcCls, Serializable lambda, int returnCount,
|
||||
Object... args);
|
||||
|
||||
/**
|
||||
* In some cases, we would like the return value of a remote function to be splitted into multiple
|
||||
* parts so that they are consumed by multiple further functions separately (potentially on
|
||||
* different machines). We therefore introduce this API so that developers can annotate the
|
||||
* outputs with a set of labels (usually with Integer or String)
|
||||
*
|
||||
* @param taskId nil
|
||||
* @param funcRun the target running function with @RayRemote
|
||||
* @param returnIds a set of labels to be used by the returned objects
|
||||
* @param args arguments to this funcRun, can be its original form or RayObject<original-type>
|
||||
* @return a set of ray objects with their labels and return ids
|
||||
*/
|
||||
<R, RID> RayMap<RID, R> callWithReturnLabels(UniqueID taskId, Callable funcRun,
|
||||
Collection<RID> returnIds, Object... args);
|
||||
|
||||
<R, RID> RayMap<RID, R> callWithReturnLabels(UniqueID taskId, Class<?> funcCls,
|
||||
Serializable lambda, Collection<RID> returnids, Object... args);
|
||||
|
||||
/**
|
||||
* a special case for the above RID-based labeling as <0...returnCount - 1>
|
||||
*
|
||||
* @param taskId nil
|
||||
* @param funcRun the target running function with @RayRemote
|
||||
* @param returnCount the number of to-be-returned objects from funcRun
|
||||
* @param args arguments to this funcRun, can be its original form or RayObject<original-type>
|
||||
* @return an array of returned objects with their Unique ids
|
||||
*/
|
||||
<R> RayList<R> callWithReturnIndices(UniqueID taskId, Callable funcRun, Integer returnCount,
|
||||
Object... args);
|
||||
|
||||
<R> RayList<R> callWithReturnIndices(UniqueID taskId, Class<?> funcCls, Serializable lambda,
|
||||
Integer returnCount, Object... args);
|
||||
|
||||
boolean isRemoteLambda();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.ray.api;
|
||||
|
||||
public @interface RayDisabled {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* A RayList<E> holds a list of RayObject<E>,
|
||||
* and can serves as parameters and/or return values of Ray calls.
|
||||
*/
|
||||
public class RayList<E> extends ArrayList<E> {
|
||||
|
||||
private static final long serialVersionUID = 2129403593610953658L;
|
||||
|
||||
private final ArrayList<RayObject<E>> ids = new ArrayList<>();
|
||||
|
||||
public List<RayObject<E>> Objects() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
// throw new UnsupportedOperationException();
|
||||
return ids.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
// throw new UnsupportedOperationException();
|
||||
return ids.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
// throw new UnsupportedOperationException();
|
||||
return ids.contains(o);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Iterator<RayObject<E>> Iterator() {
|
||||
return ids.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.toArray(a);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean add(RayObject<E> e) {
|
||||
return ids.add(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.containsAll(c);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
//throw new UnsupportedOperationException();
|
||||
ids.clear();
|
||||
}
|
||||
|
||||
public List<E> get() {
|
||||
List<UniqueID> objectIds = new ArrayList<>();
|
||||
for (RayObject<E> id : ids) {
|
||||
objectIds.add(id.getId());
|
||||
}
|
||||
return Ray.get(objectIds);
|
||||
}
|
||||
|
||||
public <T> List<T> getMeta() {
|
||||
List<UniqueID> objectIds = new ArrayList<>();
|
||||
for (RayObject<E> id : ids) {
|
||||
objectIds.add(id.getId());
|
||||
}
|
||||
return Ray.getMeta(objectIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
return ids.get(index).get();
|
||||
}
|
||||
|
||||
public <TM> TM getMeta(int index) {
|
||||
return ids.get(index).getMeta();
|
||||
}
|
||||
|
||||
public RayObject<E> Get(int index) {
|
||||
return ids.get(index);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public E set(int index, E element) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public RayObject<E> set(int index, RayObject<E> element) {
|
||||
return ids.set(index, element);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public void add(int index, E element) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void add(int index, RayObject<E> element) {
|
||||
ids.add(index, element);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public E remove(int index) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public RayObject<E> Remove(int index) {
|
||||
return ids.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.lastIndexOf(o);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public ListIterator<E> listIterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A RayMap<K> maintains a map from K to RayObject<V>,
|
||||
* and serves as parameters and/or return values of Ray calls.
|
||||
*/
|
||||
public class RayMap<K, V> extends HashMap<K, V> {
|
||||
|
||||
private static final long serialVersionUID = 7296072498584721265L;
|
||||
|
||||
private final HashMap<K, RayObject<V>> ids = new HashMap<>();
|
||||
|
||||
public HashMap<K, RayObject<V>> Objects() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
// throw new UnsupportedOperationException();
|
||||
return ids.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
//throw new UnsupportedOperationException();
|
||||
return ids.containsValue(value);
|
||||
}
|
||||
|
||||
// TODO: try to use multiple get
|
||||
public Map<K, V> get() {
|
||||
Map<K, V> objs = new HashMap<>();
|
||||
for (Map.Entry<K, RayObject<V>> id : ids.entrySet()) {
|
||||
objs.put(id.getKey(), id.getValue().get());
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
public <TM> Map<K, TM> getMeta() {
|
||||
Map<K, TM> metas = new HashMap<>();
|
||||
for (Map.Entry<K, RayObject<V>> id : ids.entrySet()) {
|
||||
TM meta = id.getValue().getMeta();
|
||||
metas.put(id.getKey(), meta);
|
||||
}
|
||||
return metas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
return ids.get(key).get();
|
||||
}
|
||||
|
||||
public <TM> TM getMeta(K key) {
|
||||
return ids.get(key).getMeta();
|
||||
}
|
||||
|
||||
public RayObject<V> Get(K key) {
|
||||
return ids.get(key);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public RayObject<V> put(K key, RayObject<V> value) {
|
||||
return ids.put(key, value);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public RayObject<V> Remove(K key) {
|
||||
return ids.remove(key);
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public void putAll(Map<? extends K, ? extends V> m) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
//throw new UnsupportedOperationException();
|
||||
ids.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
return ids.keySet();
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Collection<RayObject<V>> Values() {
|
||||
return ids.values();
|
||||
}
|
||||
|
||||
@RayDisabled
|
||||
@Deprecated
|
||||
@Override
|
||||
public Set<java.util.Map.Entry<K, V>> entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Set<java.util.Map.Entry<K, RayObject<V>>> EntrySet() {
|
||||
return ids.entrySet();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.ray.util.exception.TaskExecutionException;
|
||||
|
||||
/**
|
||||
* RayObject<T> is a handle for T object, which may or may not be available now.
|
||||
* That said, RayObject can be viewed as a Future object with metadata.
|
||||
*/
|
||||
public class RayObject<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3250003902037418062L;
|
||||
|
||||
UniqueID id;
|
||||
|
||||
public RayObject() {
|
||||
}
|
||||
|
||||
public RayObject(UniqueID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public T get() throws TaskExecutionException {
|
||||
return Ray.get(id);
|
||||
}
|
||||
|
||||
public <TM> TM getMeta() throws TaskExecutionException {
|
||||
return Ray.getMeta(id);
|
||||
}
|
||||
|
||||
public UniqueID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.ray.api;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
/**
|
||||
* Real object or ray future proxy for multiple returns
|
||||
*/
|
||||
public class RayObjects {
|
||||
|
||||
protected RayObject[] objs;
|
||||
|
||||
public RayObjects(UniqueID[] ids) {
|
||||
this.objs = new RayObject[ids.length];
|
||||
for (int k = 0; k < ids.length; k++) {
|
||||
this.objs[k] = new RayObject<>(ids[k]);
|
||||
}
|
||||
}
|
||||
|
||||
public RayObjects(RayObject[] objs) {
|
||||
this.objs = objs;
|
||||
}
|
||||
|
||||
public RayObject pop() {
|
||||
RayObject lastObj = objs[objs.length - 1];
|
||||
objs = ArrayUtils.subarray(objs, 0, objs.length - 1);
|
||||
return lastObj;
|
||||
}
|
||||
|
||||
public RayObject[] getObjs() {
|
||||
return objs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* a ray remote function or class (as an actor)
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RayRemote {
|
||||
|
||||
/**
|
||||
* whether to use external I/O pool to execute the function
|
||||
*/
|
||||
boolean externalIO() default false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.ray.api;
|
||||
|
||||
/**
|
||||
* a RPC service that represent the data processing services implemented in Ray
|
||||
*
|
||||
* it is programmed in other services but will be shipped and executed on ray machines at runtime
|
||||
*/
|
||||
public @interface RayService {
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
package org.ray.api;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a status of type T of a task.
|
||||
*/
|
||||
public class TaskStatus<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3382082416577683751L;
|
||||
|
||||
public T status;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package org.ray.api;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Unique ID for task, worker, function...
|
||||
*/
|
||||
public class UniqueID implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8588849129675565761L;
|
||||
|
||||
public static final int LENGTH = 20;
|
||||
|
||||
byte[] id;
|
||||
|
||||
public UniqueID(byte[] id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public UniqueID(ByteBuffer bb) {
|
||||
assert (bb.remaining() == LENGTH);
|
||||
id = new byte[bb.remaining()];
|
||||
bb.get(id);
|
||||
}
|
||||
|
||||
public UniqueID(String optionValue) {
|
||||
assert (optionValue.length() == 2 * LENGTH);
|
||||
int j = 0;
|
||||
|
||||
id = new byte[LENGTH];
|
||||
for (int i = 0; i < LENGTH; i++) {
|
||||
char c1 = optionValue.charAt(j++);
|
||||
char c2 = optionValue.charAt(j++);
|
||||
int first = c1 <= '9' ? (c1 - '0') : (c1 - 'a' + 0xa);
|
||||
int second = c2 <= '9' ? (c2 - '0') : (c2 - 'a' + 0xa);
|
||||
id[i] = (byte) (first * 16 + second);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
String hex = "0123456789abcdef";
|
||||
for (int i = 0; i < LENGTH; i++) {
|
||||
int val = id[i] & 0xff;
|
||||
s += hex.charAt(val >> 4);
|
||||
s += hex.charAt(val & 0xf);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ByteBuffer ToByteBuffer() {
|
||||
return ByteBuffer.wrap(id);
|
||||
}
|
||||
|
||||
public UniqueID copy() {
|
||||
byte[] nid = Arrays.copyOf(id, id.length);
|
||||
return new UniqueID(nid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0xdeadbeef;
|
||||
IntBuffer bb = ByteBuffer.wrap(id).asIntBuffer();
|
||||
while (bb.hasRemaining()) {
|
||||
hash ^= bb.get();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(obj instanceof UniqueID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UniqueID r = (UniqueID) obj;
|
||||
return Arrays.equals(id, r.id);
|
||||
}
|
||||
|
||||
public boolean isNil() {
|
||||
for (byte b : id) {
|
||||
if (b != (byte) 0xFF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final UniqueID nil = genNil();
|
||||
|
||||
public static UniqueID genNil() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
b[i] = (byte) 0xFF;
|
||||
}
|
||||
|
||||
return new UniqueID(b);
|
||||
}
|
||||
|
||||
public static UniqueID randomID() {
|
||||
byte[] b = new byte[LENGTH];
|
||||
new Random().nextBytes(b);
|
||||
return new UniqueID(b);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.ray.api;
|
||||
|
||||
|
||||
/**
|
||||
* The result of Ray.wait() distinguish the ready ones and the remain ones
|
||||
*/
|
||||
public class WaitResult<T> {
|
||||
|
||||
private final RayList<T> readyOnes;
|
||||
private final RayList<T> remainOnes;
|
||||
|
||||
public WaitResult(RayList<T> readyOnes, RayList<T> remainOnes) {
|
||||
this.readyOnes = readyOnes;
|
||||
this.remainOnes = remainOnes;
|
||||
}
|
||||
|
||||
public RayList<T> getReadyOnes() {
|
||||
return readyOnes;
|
||||
}
|
||||
|
||||
public RayList<T> getRemainOnes() {
|
||||
return remainOnes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_0_1<R0> extends RayFunc {
|
||||
|
||||
R0 apply() throws Throwable;
|
||||
|
||||
static <R0> R0 execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_0_1.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_0_1<R0> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns2;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_0_2<R0, R1> extends RayFunc {
|
||||
|
||||
MultipleReturns2<R0, R1> apply() throws Throwable;
|
||||
|
||||
static <R0, R1> MultipleReturns2<R0, R1> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_0_2.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_0_2<R0, R1> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns3;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_0_3<R0, R1, R2> extends RayFunc {
|
||||
|
||||
MultipleReturns3<R0, R1, R2> apply() throws Throwable;
|
||||
|
||||
static <R0, R1, R2> MultipleReturns3<R0, R1, R2> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_0_3.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_0_3<R0, R1, R2> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns4;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_0_4<R0, R1, R2, R3> extends RayFunc {
|
||||
|
||||
MultipleReturns4<R0, R1, R2, R3> apply() throws Throwable;
|
||||
|
||||
static <R0, R1, R2, R3> MultipleReturns4<R0, R1, R2, R3> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_0_4.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_0_4<R0, R1, R2, R3> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_0_n<R, RID> extends RayFunc {
|
||||
|
||||
Map<RID, R> apply(Collection<RID> returnids) throws Throwable;
|
||||
|
||||
static <R, RID> Map<RID, R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_0_n.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_0_n<R, RID> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((Collection<RID>) args[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_0_n_list<R> extends RayFunc {
|
||||
|
||||
List<R> apply() throws Throwable;
|
||||
|
||||
static <R> List<R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_0_n_list.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_0_n_list<R> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_1_1<T0, R0> extends RayFunc {
|
||||
|
||||
R0 apply(T0 t0) throws Throwable;
|
||||
|
||||
static <T0, R0> R0 execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_1_1.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_1_1<T0, R0> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns2;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_1_2<T0, R0, R1> extends RayFunc {
|
||||
|
||||
MultipleReturns2<R0, R1> apply(T0 t0) throws Throwable;
|
||||
|
||||
static <T0, R0, R1> MultipleReturns2<R0, R1> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_1_2.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_1_2<T0, R0, R1> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns3;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_1_3<T0, R0, R1, R2> extends RayFunc {
|
||||
|
||||
MultipleReturns3<R0, R1, R2> apply(T0 t0) throws Throwable;
|
||||
|
||||
static <T0, R0, R1, R2> MultipleReturns3<R0, R1, R2> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_1_3.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_1_3<T0, R0, R1, R2> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns4;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_1_4<T0, R0, R1, R2, R3> extends RayFunc {
|
||||
|
||||
MultipleReturns4<R0, R1, R2, R3> apply(T0 t0) throws Throwable;
|
||||
|
||||
static <T0, R0, R1, R2, R3> MultipleReturns4<R0, R1, R2, R3> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_1_4.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_1_4<T0, R0, R1, R2, R3> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_1_n<T0, R, RID> extends RayFunc {
|
||||
|
||||
Map<RID, R> apply(Collection<RID> returnids, T0 t0) throws Throwable;
|
||||
|
||||
static <T0, R, RID> Map<RID, R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_1_n.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_1_n<T0, R, RID> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((Collection<RID>) args[0], (T0) args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_1_n_list<T0, R> extends RayFunc {
|
||||
|
||||
List<R> apply(T0 t0) throws Throwable;
|
||||
|
||||
static <T0, R> List<R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_1_n_list.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_1_n_list<T0, R> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_2_1<T0, T1, R0> extends RayFunc {
|
||||
|
||||
R0 apply(T0 t0, T1 t1) throws Throwable;
|
||||
|
||||
static <T0, T1, R0> R0 execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_2_1.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_2_1<T0, T1, R0> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns2;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_2_2<T0, T1, R0, R1> extends RayFunc {
|
||||
|
||||
MultipleReturns2<R0, R1> apply(T0 t0, T1 t1) throws Throwable;
|
||||
|
||||
static <T0, T1, R0, R1> MultipleReturns2<R0, R1> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_2_2.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_2_2<T0, T1, R0, R1> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns3;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_2_3<T0, T1, R0, R1, R2> extends RayFunc {
|
||||
|
||||
MultipleReturns3<R0, R1, R2> apply(T0 t0, T1 t1) throws Throwable;
|
||||
|
||||
static <T0, T1, R0, R1, R2> MultipleReturns3<R0, R1, R2> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_2_3.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_2_3<T0, T1, R0, R1, R2> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns4;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_2_4<T0, T1, R0, R1, R2, R3> extends RayFunc {
|
||||
|
||||
MultipleReturns4<R0, R1, R2, R3> apply(T0 t0, T1 t1) throws Throwable;
|
||||
|
||||
static <T0, T1, R0, R1, R2, R3> MultipleReturns4<R0, R1, R2, R3> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_2_4.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_2_4<T0, T1, R0, R1, R2, R3> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_2_n<T0, T1, R, RID> extends RayFunc {
|
||||
|
||||
Map<RID, R> apply(Collection<RID> returnids, T0 t0, T1 t1) throws Throwable;
|
||||
|
||||
static <T0, T1, R, RID> Map<RID, R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_2_n.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_2_n<T0, T1, R, RID> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((Collection<RID>) args[0], (T0) args[1], (T1) args[2]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_2_n_list<T0, T1, R> extends RayFunc {
|
||||
|
||||
List<R> apply(T0 t0, T1 t1) throws Throwable;
|
||||
|
||||
static <T0, T1, R> List<R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_2_n_list.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_2_n_list<T0, T1, R> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_3_1<T0, T1, T2, R0> extends RayFunc {
|
||||
|
||||
R0 apply(T0 t0, T1 t1, T2 t2) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, R0> R0 execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_3_1.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_3_1<T0, T1, T2, R0> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns2;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_3_2<T0, T1, T2, R0, R1> extends RayFunc {
|
||||
|
||||
MultipleReturns2<R0, R1> apply(T0 t0, T1 t1, T2 t2) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, R0, R1> MultipleReturns2<R0, R1> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_3_2.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_3_2<T0, T1, T2, R0, R1> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns3;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_3_3<T0, T1, T2, R0, R1, R2> extends RayFunc {
|
||||
|
||||
MultipleReturns3<R0, R1, R2> apply(T0 t0, T1 t1, T2 t2) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, R0, R1, R2> MultipleReturns3<R0, R1, R2> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_3_3.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_3_3<T0, T1, T2, R0, R1, R2> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns4;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_3_4<T0, T1, T2, R0, R1, R2, R3> extends RayFunc {
|
||||
|
||||
MultipleReturns4<R0, R1, R2, R3> apply(T0 t0, T1 t1, T2 t2) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, R0, R1, R2, R3> MultipleReturns4<R0, R1, R2, R3> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_3_4.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_3_4<T0, T1, T2, R0, R1, R2, R3> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_3_n<T0, T1, T2, R, RID> extends RayFunc {
|
||||
|
||||
Map<RID, R> apply(Collection<RID> returnids, T0 t0, T1 t1, T2 t2) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, R, RID> Map<RID, R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_3_n.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_3_n<T0, T1, T2, R, RID> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((Collection<RID>) args[0], (T0) args[1], (T1) args[2], (T2) args[3]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_3_n_list<T0, T1, T2, R> extends RayFunc {
|
||||
|
||||
List<R> apply(T0 t0, T1 t1, T2 t2) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, R> List<R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_3_n_list.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_3_n_list<T0, T1, T2, R> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_4_1<T0, T1, T2, T3, R0> extends RayFunc {
|
||||
|
||||
R0 apply(T0 t0, T1 t1, T2 t2, T3 t3) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, R0> R0 execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_4_1.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_4_1<T0, T1, T2, T3, R0> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns2;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_4_2<T0, T1, T2, T3, R0, R1> extends RayFunc {
|
||||
|
||||
MultipleReturns2<R0, R1> apply(T0 t0, T1 t1, T2 t2, T3 t3) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, R0, R1> MultipleReturns2<R0, R1> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_4_2.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_4_2<T0, T1, T2, T3, R0, R1> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns3;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_4_3<T0, T1, T2, T3, R0, R1, R2> extends RayFunc {
|
||||
|
||||
MultipleReturns3<R0, R1, R2> apply(T0 t0, T1 t1, T2 t2, T3 t3) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, R0, R1, R2> MultipleReturns3<R0, R1, R2> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_4_3.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_4_3<T0, T1, T2, T3, R0, R1, R2> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns4;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_4_4<T0, T1, T2, T3, R0, R1, R2, R3> extends RayFunc {
|
||||
|
||||
MultipleReturns4<R0, R1, R2, R3> apply(T0 t0, T1 t1, T2 t2, T3 t3) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, R0, R1, R2, R3> MultipleReturns4<R0, R1, R2, R3> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_4_4.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_4_4<T0, T1, T2, T3, R0, R1, R2, R3> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_4_n<T0, T1, T2, T3, R, RID> extends RayFunc {
|
||||
|
||||
Map<RID, R> apply(Collection<RID> returnids, T0 t0, T1 t1, T2 t2, T3 t3) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, R, RID> Map<RID, R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_4_n.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_4_n<T0, T1, T2, T3, R, RID> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((Collection<RID>) args[0], (T0) args[1], (T1) args[2], (T2) args[3], (T3) args[4]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_4_n_list<T0, T1, T2, T3, R> extends RayFunc {
|
||||
|
||||
List<R> apply(T0 t0, T1 t1, T2 t2, T3 t3) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, R> List<R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_4_n_list.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_4_n_list<T0, T1, T2, T3, R> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_5_1<T0, T1, T2, T3, T4, R0> extends RayFunc {
|
||||
|
||||
R0 apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, R0> R0 execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_5_1.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_5_1<T0, T1, T2, T3, T4, R0> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns2;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_5_2<T0, T1, T2, T3, T4, R0, R1> extends RayFunc {
|
||||
|
||||
MultipleReturns2<R0, R1> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, R0, R1> MultipleReturns2<R0, R1> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_5_2.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_5_2<T0, T1, T2, T3, T4, R0, R1> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns3;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_5_3<T0, T1, T2, T3, T4, R0, R1, R2> extends RayFunc {
|
||||
|
||||
MultipleReturns3<R0, R1, R2> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, R0, R1, R2> MultipleReturns3<R0, R1, R2> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_5_3.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_5_3<T0, T1, T2, T3, T4, R0, R1, R2> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns4;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_5_4<T0, T1, T2, T3, T4, R0, R1, R2, R3> extends RayFunc {
|
||||
|
||||
MultipleReturns4<R0, R1, R2, R3> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, R0, R1, R2, R3> MultipleReturns4<R0, R1, R2, R3> execute(
|
||||
Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_5_4.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_5_4<T0, T1, T2, T3, T4, R0, R1, R2, R3> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_5_n<T0, T1, T2, T3, T4, R, RID> extends RayFunc {
|
||||
|
||||
Map<RID, R> apply(Collection<RID> returnids, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, R, RID> Map<RID, R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_5_n.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_5_n<T0, T1, T2, T3, T4, R, RID> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((Collection<RID>) args[0], (T0) args[1], (T1) args[2], (T2) args[3], (T3) args[4],
|
||||
(T4) args[5]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_5_n_list<T0, T1, T2, T3, T4, R> extends RayFunc {
|
||||
|
||||
List<R> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, R> List<R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_5_n_list.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_5_n_list<T0, T1, T2, T3, T4, R> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_6_1<T0, T1, T2, T3, T4, T5, R0> extends RayFunc {
|
||||
|
||||
R0 apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, T5, R0> R0 execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_6_1.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_6_1<T0, T1, T2, T3, T4, T5, R0> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns2;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_6_2<T0, T1, T2, T3, T4, T5, R0, R1> extends RayFunc {
|
||||
|
||||
MultipleReturns2<R0, R1> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, T5, R0, R1> MultipleReturns2<R0, R1> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_6_2.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_6_2<T0, T1, T2, T3, T4, T5, R0, R1> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns3;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_6_3<T0, T1, T2, T3, T4, T5, R0, R1, R2> extends RayFunc {
|
||||
|
||||
MultipleReturns3<R0, R1, R2> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, T5, R0, R1, R2> MultipleReturns3<R0, R1, R2> execute(Object[] args)
|
||||
throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_6_3.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_6_3<T0, T1, T2, T3, T4, T5, R0, R1, R2> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
import org.ray.api.returns.MultipleReturns4;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_6_4<T0, T1, T2, T3, T4, T5, R0, R1, R2, R3> extends RayFunc {
|
||||
|
||||
MultipleReturns4<R0, R1, R2, R3> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, T5, R0, R1, R2, R3> MultipleReturns4<R0, R1, R2, R3> execute(
|
||||
Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_6_4.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_6_4<T0, T1, T2, T3, T4, T5, R0, R1, R2, R3> f = SerializationUtils
|
||||
.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_6_n<T0, T1, T2, T3, T4, T5, R, RID> extends RayFunc {
|
||||
|
||||
Map<RID, R> apply(Collection<RID> returnids, T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
|
||||
throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, T5, R, RID> Map<RID, R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_6_n.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_6_n<T0, T1, T2, T3, T4, T5, R, RID> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((Collection<RID>) args[0], (T0) args[1], (T1) args[2], (T2) args[3], (T3) args[4],
|
||||
(T4) args[5], (T5) args[6]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.funcs;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.ray.api.internal.RayFunc;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RayFunc_6_n_list<T0, T1, T2, T3, T4, T5, R> extends RayFunc {
|
||||
|
||||
List<R> apply(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) throws Throwable;
|
||||
|
||||
static <T0, T1, T2, T3, T4, T5, R> List<R> execute(Object[] args) throws Throwable {
|
||||
String name = (String) args[args.length - 2];
|
||||
assert (name.equals(RayFunc_6_n_list.class.getName()));
|
||||
byte[] funcBytes = (byte[]) args[args.length - 1];
|
||||
RayFunc_6_n_list<T0, T1, T2, T3, T4, T5, R> f = SerializationUtils.deserialize(funcBytes);
|
||||
return f
|
||||
.apply((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.ray.api.internal;
|
||||
|
||||
/**
|
||||
* hold the remote call
|
||||
*/
|
||||
public interface Callable {
|
||||
|
||||
void run() throws Throwable;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.ray.api.internal;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.ray.api.RayApi;
|
||||
import org.ray.util.logger.RayLog;
|
||||
|
||||
/**
|
||||
* Mediator, which pulls the {@code org.ray.api.RayApi} up to run.
|
||||
*/
|
||||
public class RayConnector {
|
||||
|
||||
private static final String className = "org.ray.core.RayRuntime";
|
||||
|
||||
public static RayApi run() {
|
||||
try {
|
||||
Method m = Class.forName(className).getDeclaredMethod("init");
|
||||
m.setAccessible(true);
|
||||
RayApi api = (RayApi) m.invoke(null);
|
||||
m.setAccessible(false);
|
||||
return api;
|
||||
} catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) {
|
||||
RayLog.core.error("Load " + className + " class failed.", e);
|
||||
throw new Error("RayApi is not successfully initiated.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.ray.api.internal;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Base of the ray remote function
|
||||
*/
|
||||
public interface RayFunc extends Serializable {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.ray.api.returns;
|
||||
|
||||
/**
|
||||
* Multiple return objects for user's method
|
||||
*/
|
||||
public class MultipleReturns {
|
||||
|
||||
protected final Object[] values;
|
||||
|
||||
public MultipleReturns(Object values[]) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public Object[] getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.ray.api.returns;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MultipleReturns2<R0, R1> extends MultipleReturns {
|
||||
|
||||
public MultipleReturns2(R0 r0, R1 r1) {
|
||||
super(new Object[]{r0, r1});
|
||||
}
|
||||
|
||||
public R0 get0() {
|
||||
return (R0) this.values[0];
|
||||
}
|
||||
|
||||
public R1 get1() {
|
||||
return (R1) this.values[1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.ray.api.returns;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MultipleReturns3<R0, R1, R2> extends MultipleReturns {
|
||||
|
||||
public MultipleReturns3(R0 r0, R1 r1, R2 r2) {
|
||||
super(new Object[]{r0, r1, r2});
|
||||
}
|
||||
|
||||
public R0 get0() {
|
||||
return (R0) this.values[0];
|
||||
}
|
||||
|
||||
public R1 get1() {
|
||||
return (R1) this.values[1];
|
||||
}
|
||||
|
||||
public R2 get2() {
|
||||
return (R2) this.values[2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.ray.api.returns;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MultipleReturns4<R0, R1, R2, R3> extends MultipleReturns {
|
||||
|
||||
public MultipleReturns4(R0 r0, R1 r1, R2 r2, R3 r3) {
|
||||
super(new Object[]{r0, r1, r2, r3});
|
||||
}
|
||||
|
||||
public R0 get0() {
|
||||
return (R0) this.values[0];
|
||||
}
|
||||
|
||||
public R1 get1() {
|
||||
return (R1) this.values[1];
|
||||
}
|
||||
|
||||
public R2 get2() {
|
||||
return (R2) this.values[2];
|
||||
}
|
||||
|
||||
public R3 get3() {
|
||||
return (R3) this.values[3];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.ray.api.returns;
|
||||
|
||||
import org.ray.api.RayObject;
|
||||
import org.ray.api.RayObjects;
|
||||
import org.ray.api.UniqueID;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class RayObjects2<R0, R1> extends RayObjects {
|
||||
|
||||
public RayObjects2(UniqueID[] ids) {
|
||||
super(ids);
|
||||
}
|
||||
|
||||
public RayObjects2(RayObject objs[]) {
|
||||
super(objs);
|
||||
}
|
||||
|
||||
public RayObject<R0> r0() {
|
||||
return objs[0];
|
||||
}
|
||||
|
||||
public RayObject<R1> r1() {
|
||||
return objs[1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.ray.api.returns;
|
||||
|
||||
import org.ray.api.RayObject;
|
||||
import org.ray.api.RayObjects;
|
||||
import org.ray.api.UniqueID;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class RayObjects3<R0, R1, R2> extends RayObjects {
|
||||
|
||||
public RayObjects3(UniqueID[] ids) {
|
||||
super(ids);
|
||||
}
|
||||
|
||||
public RayObjects3(RayObject objs[]) {
|
||||
super(objs);
|
||||
}
|
||||
|
||||
public RayObject<R0> r0() {
|
||||
return objs[0];
|
||||
}
|
||||
|
||||
public RayObject<R1> r1() {
|
||||
return objs[1];
|
||||
}
|
||||
|
||||
public RayObject<R2> r2() {
|
||||
return objs[2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.ray.api.returns;
|
||||
|
||||
import org.ray.api.RayObject;
|
||||
import org.ray.api.RayObjects;
|
||||
import org.ray.api.UniqueID;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class RayObjects4<R0, R1, R2, R3> extends RayObjects {
|
||||
|
||||
public RayObjects4(UniqueID[] ids) {
|
||||
super(ids);
|
||||
}
|
||||
|
||||
public RayObjects4(RayObject objs[]) {
|
||||
super(objs);
|
||||
}
|
||||
|
||||
public RayObject<R0> r0() {
|
||||
return objs[0];
|
||||
}
|
||||
|
||||
public RayObject<R1> r1() {
|
||||
return objs[1];
|
||||
}
|
||||
|
||||
public RayObject<R2> r2() {
|
||||
return objs[2];
|
||||
}
|
||||
|
||||
public RayObject<R3> r3() {
|
||||
return objs[3];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user