File tree 3 files changed +29
-3
lines changed
grpc-context-utils/src/main/java/org/hypertrace/core/grpcutils/context
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change
1
+ package org .hypertrace .core .grpcutils .context ;
2
+
3
+ import java .util .UUID ;
4
+ import java .util .concurrent .ThreadLocalRandom ;
5
+
6
+ public class FastUUIDGenerator {
7
+ /**
8
+ * This function generates UUIDs using ThreadLocalRandom, which is faster and doesn't block like
9
+ * the default randomUUID method that relies on /dev/random. It's suitable for most random UUID
10
+ * needs.
11
+ */
12
+ public static UUID randomUUID () {
13
+ long mostSigBits = ThreadLocalRandom .current ().nextLong ();
14
+ long leastSigBits = ThreadLocalRandom .current ().nextLong ();
15
+
16
+ // Set the version (4) For random UUID
17
+ mostSigBits &= 0xFFFFFFFFFFFF0FFFL ;
18
+ mostSigBits |= 0x0000000000004000L ;
19
+ // Set variant to RFC 4122
20
+ leastSigBits &= 0x3FFFFFFFFFFFFFFFL ;
21
+ leastSigBits |= 0x8000000000000000L ;
22
+
23
+ return new UUID (mostSigBits , leastSigBits );
24
+ }
25
+ }
Original file line number Diff line number Diff line change 18
18
import java .util .Map ;
19
19
import java .util .Optional ;
20
20
import java .util .Set ;
21
- import java .util .UUID ;
22
21
import java .util .concurrent .Callable ;
23
22
import java .util .stream .Collectors ;
24
23
import javax .annotation .Nonnull ;
@@ -34,7 +33,9 @@ public class RequestContext {
34
33
public static RequestContext forTenantId (String tenantId ) {
35
34
return new RequestContext ()
36
35
.put (RequestContextConstants .TENANT_ID_HEADER_KEY , tenantId )
37
- .put (RequestContextConstants .REQUEST_ID_HEADER_KEY , UUID .randomUUID ().toString ());
36
+ .put (
37
+ RequestContextConstants .REQUEST_ID_HEADER_KEY ,
38
+ FastUUIDGenerator .randomUUID ().toString ());
38
39
}
39
40
40
41
public static RequestContext fromMetadata (Metadata metadata ) {
Original file line number Diff line number Diff line change 7
7
<packageUrl regex =" true" >^pkg:maven/org\.hypertrace\..*@.*$</packageUrl >
8
8
<cpe >cpe:/a:grpc:grpc</cpe >
9
9
</suppress >
10
- <suppress until =" 2023-08-31Z " >
10
+ <suppress until =" 2023-09-30Z " >
11
11
<notes ><![CDATA[
12
12
file name: jackson-databind-2.14.2.jar
13
13
This is currently disputed.
You can’t perform that action at this time.
0 commit comments