Skip to content

Commit 09ea8d0

Browse files
Deprecate random seed
1 parent a0922ad commit 09ea8d0

2 files changed

Lines changed: 5 additions & 32 deletions

File tree

sdk-common/src/main/java/dev/restate/sdk/common/InvocationId.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
package dev.restate.sdk.common;
1010

1111
/**
12-
* This represents a stable identifier created by Restate for this invocation. It can be used as
13-
* idempotency key when accessing external systems.
12+
* This represents a stable identifier created by Restate for this invocation.
1413
*
1514
* <p>You can embed it in external system requests by using {@link #toString()}.
1615
*/
1716
public interface InvocationId {
1817

1918
/**
20-
* @return a seed to be used with {@link java.util.Random}.
19+
* @deprecated Just use the random provided by the context API.
2120
*/
21+
@Deprecated(forRemoval = true)
2222
long toRandomSeed();
2323

2424
@Override

sdk-core/src/main/java/dev/restate/sdk/core/InvocationIdImpl.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@
99
package dev.restate.sdk.core;
1010

1111
import dev.restate.sdk.common.InvocationId;
12-
import java.nio.charset.StandardCharsets;
13-
import java.security.MessageDigest;
14-
import java.security.NoSuchAlgorithmException;
1512
import java.util.Objects;
16-
import org.jspecify.annotations.Nullable;
1713

1814
final class InvocationIdImpl implements InvocationId {
1915

2016
private final String id;
21-
private Long seed;
17+
private long seed;
2218

23-
InvocationIdImpl(String debugId, @Nullable Long seed) {
19+
InvocationIdImpl(String debugId, long seed) {
2420
this.id = debugId;
25-
// If random seed null, it will be computed
2621
this.seed = seed;
2722
}
2823

@@ -41,28 +36,6 @@ public int hashCode() {
4136

4237
@Override
4338
public long toRandomSeed() {
44-
if (seed == null) {
45-
// Hash the seed to SHA-256 to increase entropy
46-
MessageDigest md;
47-
try {
48-
md = MessageDigest.getInstance("SHA-256");
49-
} catch (NoSuchAlgorithmException e) {
50-
throw new RuntimeException(e);
51-
}
52-
byte[] digest = md.digest(id.getBytes(StandardCharsets.UTF_8));
53-
54-
// Generate the long
55-
long n = 0;
56-
n |= ((long) (digest[7] & 0xFF) << (Byte.SIZE * 7));
57-
n |= ((long) (digest[6] & 0xFF) << (Byte.SIZE * 6));
58-
n |= ((long) (digest[5] & 0xFF) << (Byte.SIZE * 5));
59-
n |= ((long) (digest[4] & 0xFF) << (Byte.SIZE * 4));
60-
n |= ((long) (digest[3] & 0xFF) << (Byte.SIZE * 3));
61-
n |= ((digest[2] & 0xFF) << (Byte.SIZE * 2));
62-
n |= ((digest[1] & 0xFF) << Byte.SIZE);
63-
n |= (digest[0] & 0xFF);
64-
seed = n;
65-
}
6639
return seed;
6740
}
6841

0 commit comments

Comments
 (0)