]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/libuuid/DirectLibuuidFactory.java
Introduce UUID identified and openForEdit/freeze cycle
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / libuuid / DirectLibuuidFactory.java
1 package org.argeo.api.uuid.libuuid;
2
3 import java.nio.ByteBuffer;
4 import java.util.UUID;
5
6 import org.argeo.api.uuid.UuidBinaryUtils;
7 import org.argeo.api.uuid.UuidFactory;
8
9 /**
10 * @deprecated Rather use {@link LibuuidFactory}. This is just a proof of
11 * concept that using shared memory in order to limit the JNI
12 * overhead does not yield any significant performance gain. But it
13 * could be an approach for computing and transferring bulk UUIDs
14 * computations in one go, vi
15 * {@link ByteBuffer#allocateDirect(int)}.
16 */
17 public class DirectLibuuidFactory implements UuidFactory {
18 static {
19 System.loadLibrary("Java_org_argeo_api_uuid_libuuid");
20 }
21
22 @Override
23 public UUID get() {
24 return timeUUID();
25 }
26
27 @Override
28 public UUID timeUUID() {
29 ByteBuffer buf = ByteBuffer.allocateDirect(16);
30 timeUUID(buf);
31 byte[] arr = new byte[16];
32 buf.get(arr);
33 return UuidBinaryUtils.fromBytes(arr);
34 }
35
36 protected native void timeUUID(ByteBuffer uuidBuf);
37
38 @Override
39 public UUID nameUUIDv5(UUID namespace, byte[] data) {
40 throw new UnsupportedOperationException();
41 }
42
43 @Override
44 public UUID nameUUIDv3(UUID namespace, byte[] data) {
45 throw new UnsupportedOperationException();
46 }
47
48 @Override
49 public UUID randomUUIDStrong() {
50 throw new UnsupportedOperationException();
51 }
52
53 @Override
54 public UUID randomUUIDWeak() {
55 throw new UnsupportedOperationException();
56 }
57
58 }