mirror of
https://github.com/wassname/ray.git
synced 2026-06-27 21:23:10 +08:00
[Java] ID length fix (#6454)
This commit is contained in:
@@ -6,7 +6,10 @@ import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
public class ActorId extends BaseId implements Serializable {
|
||||
public static final int LENGTH = 8;
|
||||
|
||||
private static final int UNIQUE_BYTES_LENGTH = 4;
|
||||
|
||||
public static final int LENGTH = JobId.LENGTH + UNIQUE_BYTES_LENGTH;
|
||||
|
||||
public static final ActorId NIL = nil();
|
||||
|
||||
|
||||
@@ -10,10 +10,7 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class JobId extends BaseId implements Serializable {
|
||||
|
||||
// Note that the max value of a job id is NIL which value is (2^32 - 1).
|
||||
public static final Long MAX_VALUE = (long) Math.pow(2, 32) - 1;
|
||||
|
||||
public static final int LENGTH = 4;
|
||||
public static final int LENGTH = 2;
|
||||
|
||||
public static final JobId NIL = genNil();
|
||||
|
||||
@@ -39,11 +36,17 @@ public class JobId extends BaseId implements Serializable {
|
||||
}
|
||||
|
||||
public static JobId fromInt(int value) {
|
||||
byte[] bytes = new byte[JobId.LENGTH];
|
||||
if (value > Math.pow(256, JobId.LENGTH)) {
|
||||
throw new IllegalArgumentException(
|
||||
"The integer value is invalid for a JobId. Value: " + value);
|
||||
}
|
||||
byte[] bytes = new byte[Integer.BYTES];
|
||||
ByteBuffer wbb = ByteBuffer.wrap(bytes);
|
||||
wbb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
wbb.putInt(value);
|
||||
return new JobId(bytes);
|
||||
wbb.flip();
|
||||
wbb.limit(JobId.LENGTH);
|
||||
return JobId.fromByteBuffer(wbb);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,16 +2,16 @@ package org.ray.api.id;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Represents the id of a Ray task.
|
||||
*/
|
||||
public class TaskId extends BaseId implements Serializable {
|
||||
|
||||
public static final int LENGTH = 14;
|
||||
private static final int UNIQUE_BYTES_LENGTH = 8;
|
||||
|
||||
public static final int LENGTH = ActorId.LENGTH + UNIQUE_BYTES_LENGTH;
|
||||
|
||||
public static final TaskId NIL = genNil();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user