import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.Clock;
-import java.util.Random;
import java.util.UUID;
/**
*
* @see https://datatracker.ietf.org/doc/html/rfc4122
*/
-public class SimpleUuidFactory extends AbstractUuidFactory {
+public class SimpleUuidFactory extends AbstractAsyncUuidFactory {
private final static Logger logger = System.getLogger(SimpleUuidFactory.class.getName());
public final static UuidFactory DEFAULT = new SimpleUuidFactory(null, -1, null);
- private SecureRandom secureRandom;
- private final TimeUuidState timeUuidState;
-
// private NodeId macAddressNodeId;
// private NodeId defaultNodeId;
private byte[] macAddressNodeId;
private byte[] defaultNodeId;
public SimpleUuidFactory(byte[] nodeId, int offset, Clock clock) {
+ byte[] hardwareAddress = getHardwareAddress();
+// macAddressNodeId = hardwareAddress != null ? new NodeId(hardwareAddress, 0) : null;
+ macAddressNodeId = toNodeId(hardwareAddress, 0);
+
+// defaultNodeId = nodeId != null ? new NodeId(nodeId, offset) : macAddressNodeId;
+ defaultNodeId = nodeId != null ? toNodeId(nodeId, offset) : toNodeId(macAddressNodeId, 0);
+ if (defaultNodeId == null)
+ throw new IllegalStateException("No default node id specified");
+ }
+
+ @Override
+ protected SecureRandom newSecureRandom() {
+ SecureRandom secureRandom;
try {
secureRandom = SecureRandom.getInstance("DRBG",
DrbgParameters.instantiation(256, DrbgParameters.Capability.PR_AND_RESEED, "UUID".getBytes()));
secureRandom = new SecureRandom();
}
}
-
- byte[] hardwareAddress = getHardwareAddress();
-// macAddressNodeId = hardwareAddress != null ? new NodeId(hardwareAddress, 0) : null;
- macAddressNodeId = toNodeId(hardwareAddress, 0);
-
-// defaultNodeId = nodeId != null ? new NodeId(nodeId, offset) : macAddressNodeId;
- defaultNodeId = nodeId != null ? toNodeId(nodeId, offset) : toNodeId(macAddressNodeId, 0);
- if (defaultNodeId == null)
- throw new IllegalStateException("No default node id specified");
-
- timeUuidState = new ConcurrentTimeUuidState(secureRandom, clock);
+ return secureRandom;
}
/*
*/
@Override
- public UUID timeUUIDwithMacAddress() {
+ public UUID newTimeUUIDwithMacAddress() {
if (macAddressNodeId == null)
throw new UnsupportedOperationException("No MAC address is available");
return newTimeUUID(timeUuidState.useTimestamp(), timeUuidState.getClockSequence(), macAddressNodeId, 0);
}
@Override
- public UUID timeUUID() {
+ public UUID newTimeUUID() {
return newTimeUUID(timeUuidState.useTimestamp(), timeUuidState.getClockSequence(), defaultNodeId, 0);
}
- /*
- * NAME BASED (version 3 and 5)
- */
- @Override
- public UUID nameUUIDv5(UUID namespace, byte[] name) {
- return newNameUUIDv5(namespace, name);
- }
-
- @Override
- public UUID nameUUIDv3(UUID namespace, byte[] name) {
- return newNameUUIDv3(namespace, name);
- }
-
/*
* RANDOM v4
*/
- @Override
- public UUID randomUUID(Random random) {
- return newRandomUUID(random);
- }
-
- @Override
- public UUID randomUUID() {
- return randomUUID(secureRandom);
- }
+// @Override
+// public UUID randomUUID(Random random) {
+// return newRandomUUID(random);
+// }
+// @Override
+// public UUID randomUUID() {
+// return randomUUID(secureRandom);
+// }
+//
// static class NodeId extends ThreadLocal<byte[]> {
// private byte[] source;
// private int offset;