Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private <V> WritableSingletonStateBase<V> withAnyRegisteredListeners(
@Nonnull final String serviceName,
@Nonnull final String stateKey,
@Nonnull final SingletonState<V> singleton) {
final var state = new FunctionWritableSingletonState<>(serviceName, stateKey, singleton, singleton::set);
final var state = new FunctionWritableSingletonState<>(serviceName, stateKey, singleton);
listeners.forEach(listener -> {
if (listener.stateTypes().contains(SINGLETON)) {
registerSingletonListener(serviceName, state, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,26 @@
import com.swirlds.state.spi.WritableSingletonStateBase;
import jakarta.annotation.Nonnull;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class FunctionWritableSingletonState<S> extends WritableSingletonStateBase<S> {

private final Supplier<S> backingStoreAccessor;

private final Consumer<S> backingStoreMutator;

/**
* Creates a new instance.
*
* @param serviceName The name of the service that owns the state.
* @param stateKey The state key for this instance.
* @param backingStoreAccessor A {@link Supplier} that provides access to the value in the
* backing store.
* @param backingStoreMutator A {@link Consumer} for mutating the value in the backing store.
*/
public FunctionWritableSingletonState(
@Nonnull final String serviceName,
@Nonnull final String stateKey,
@Nonnull final Supplier<S> backingStoreAccessor,
@Nonnull final Consumer<S> backingStoreMutator) {
@Nonnull final Supplier<S> backingStoreAccessor) {
super(serviceName, stateKey);
this.backingStoreAccessor = Objects.requireNonNull(backingStoreAccessor);
this.backingStoreMutator = Objects.requireNonNull(backingStoreMutator);
}

@Override
Expand All @@ -40,11 +34,11 @@ protected S readFromDataSource() {

@Override
protected void putIntoDataSource(@Nonnull S value) {
backingStoreMutator.accept(value);
// No-op as we don't persist updates in web3.
}

@Override
protected void removeFromDataSource() {
backingStoreMutator.accept(null);
// No-op as we don't persist updates in web3.
}
}
Loading