| 6 | import java.util.Random; |
| 7 | |
| 8 | public class ActorId extends BaseId implements Serializable { |
| 9 | |
| 10 | private static final int UNIQUE_BYTES_LENGTH = 12; |
| 11 | |
| 12 | public static final int LENGTH = JobId.LENGTH + UNIQUE_BYTES_LENGTH; |
| 13 | |
| 14 | public static final ActorId NIL = nil(); |
| 15 | |
| 16 | private ActorId(byte[] id) { |
| 17 | super(id); |
| 18 | } |
| 19 | |
| 20 | public static ActorId fromByteBuffer(ByteBuffer bb) { |
| 21 | return new ActorId(byteBuffer2Bytes(bb)); |
| 22 | } |
| 23 | |
| 24 | public static ActorId fromBytes(byte[] bytes) { |
| 25 | return new ActorId(bytes); |
| 26 | } |
| 27 | |
| 28 | /** Generate a nil ActorId. */ |
| 29 | private static ActorId nil() { |
| 30 | byte[] b = new byte[LENGTH]; |
| 31 | Arrays.fill(b, (byte) 0xFF); |
| 32 | return new ActorId(b); |
| 33 | } |
| 34 | |
| 35 | /** Generate an ActorId with random value. Used for local mode and test only. */ |
| 36 | public static ActorId fromRandom() { |
| 37 | byte[] b = new byte[LENGTH]; |
| 38 | new Random().nextBytes(b); |
| 39 | return new ActorId(b); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public int size() { |
| 44 | return LENGTH; |
| 45 | } |
| 46 | |
| 47 | public JobId getJobId() { |
| 48 | byte[] actorBytes = getBytes(); |
| 49 | ByteBuffer bf = ByteBuffer.wrap(actorBytes, UNIQUE_BYTES_LENGTH, JobId.LENGTH); |
| 50 | return JobId.fromByteBuffer(bf); |
| 51 | } |
| 52 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…