Skip to content

Commit

Permalink
Remove stream, seems unneeded. (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Jun 4, 2024
1 parent 4b2431d commit de2f240
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,7 @@ void onStartMessage(MessageLite msg) {
this.entriesToReplay = startMessage.getKnownEntries();

// Set up the state cache
this.userStateStore =
new UserStateStore(
startMessage.getPartialState(),
startMessage.getStateMapList().stream()
.collect(
Collectors.toMap(
Protocol.StartMessage.StateEntry::getKey,
Protocol.StartMessage.StateEntry::getValue)));
this.userStateStore = new UserStateStore(startMessage);

// Tracing and logging setup
this.loggingContextSetter.set(
Expand Down
18 changes: 8 additions & 10 deletions sdk-core/src/main/java/dev/restate/sdk/core/UserStateStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
package dev.restate.sdk.core;

import com.google.protobuf.ByteString;
import dev.restate.generated.service.protocol.Protocol;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

final class UserStateStore {

Expand Down Expand Up @@ -46,14 +45,13 @@ public ByteBuffer getValue() {
private boolean isPartial;
private final HashMap<ByteString, State> map;

UserStateStore(boolean isPartial, Map<ByteString, ByteString> map) {
this.isPartial = isPartial;
this.map =
new HashMap<>(
map.entrySet().stream()
.collect(
Collectors.toMap(
Map.Entry::getKey, e -> new Value(e.getValue().asReadOnlyByteBuffer()))));
UserStateStore(Protocol.StartMessage startMessage) {
this.isPartial = startMessage.getPartialState();
this.map = new HashMap<>(startMessage.getStateMapCount());
for (int i = 0; i < startMessage.getStateMapCount(); i++) {
Protocol.StartMessage.StateEntry entry = startMessage.getStateMap(i);
this.map.put(entry.getKey(), new Value(entry.getValue().asReadOnlyByteBuffer()));
}
}

public State get(ByteString key) {
Expand Down

0 comments on commit de2f240

Please sign in to comment.