1 package org
.argeo
.api
.uuid
;
3 import java
.security
.SecureRandom
;
4 import java
.util
.function
.Supplier
;
6 /** A factory for node id base */
7 public interface NodeIdSupplier
extends Supplier
<Long
> {
8 static long toNodeIdBase(byte[] node
) {
9 assert node
.length
== 6;
10 return UuidFactory
.LEAST_SIG_RFC4122_VARIANT
| (node
[0] & 0xFFL
) //
11 | ((node
[1] & 0xFFL
) << 8) //
12 | ((node
[2] & 0xFFL
) << 16) //
13 | ((node
[3] & 0xFFL
) << 24) //
14 | ((node
[4] & 0xFFL
) << 32) //
15 | ((node
[5] & 0xFFL
) << 40); //
18 static boolean isNoMacAddressNodeId(byte[] nodeId
) {
19 return (nodeId
[0] & 1) != 0;
22 static byte[] randomNodeId() {
23 SecureRandom random
= new SecureRandom();
24 byte[] nodeId
= new byte[6];
25 random
.nextBytes(nodeId
);