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
@@ -1,7 +1,7 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.15
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.16
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.15
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.16
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.15
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.16
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Dependencies {
object AkkaServerless {
val ProtocolVersionMajor = 0
val ProtocolVersionMinor = 7
val FrameworkVersion = "0.7.0-beta.15"
val FrameworkVersion = "0.7.0-beta.16"
}

// changing the Scala version of the Java SDK affects end users
Expand Down
2 changes: 1 addition & 1 deletion samples/java-eventsourced-shopping-cart/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.15
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.16
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
Expand Down
2 changes: 1 addition & 1 deletion samples/java-valueentity-shopping-cart/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.15
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.16
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
Expand Down
2 changes: 1 addition & 1 deletion samples/replicatedentity-counter/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.15
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.16
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
Expand Down
2 changes: 1 addition & 1 deletion samples/valueentity-counter/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.15
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.16
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
*
* @param <K> The type for keys.
*/
public final class ReplicatedCounterMap<K> implements ReplicatedData {

private final ReplicatedMap<K, ReplicatedCounter> replicatedMap;

public ReplicatedCounterMap(ReplicatedMap<K, ReplicatedCounter> replicatedMap) {
this.replicatedMap = replicatedMap;
}
public interface ReplicatedCounterMap<K> extends ReplicatedData {

/**
* Get the counter value for the given key.
Expand All @@ -38,14 +32,7 @@ public ReplicatedCounterMap(ReplicatedMap<K, ReplicatedCounter> replicatedMap) {
* @return The current value of the counter at that key, or zero if no counter exists for that
* key.
*/
public long get(K key) {
ReplicatedCounter counter = replicatedMap.get(key);
if (counter != null) {
return counter.getValue();
} else {
return 0;
}
}
long get(K key);

/**
* Increment the counter at the given key by the given amount.
Expand All @@ -56,9 +43,7 @@ public long get(K key) {
* @param by The amount to increment by.
* @return The new value of the counter.
*/
public long increment(K key, long by) {
return getOrCreate(key).increment(by);
}
long increment(K key, long by);

/**
* Decrement the counter at the given key by the given amount.
Expand All @@ -69,35 +54,17 @@ public long increment(K key, long by) {
* @param by The amount to decrement by.
* @return The new value of the counter.
*/
public long decrement(K key, long by) {
return getOrCreate(key).decrement(by);
}

private ReplicatedCounter getOrCreate(K key) {
return replicatedMap.getOrCreate(key, ReplicatedDataFactory::newCounter);
}
long decrement(K key, long by);

public Set<K> keySet() {
return replicatedMap.keySet();
}
Set<K> keySet();

public int size() {
return replicatedMap.size();
}
int size();

public boolean isEmpty() {
return replicatedMap.isEmpty();
}
boolean isEmpty();

public boolean containsKey(K key) {
return replicatedMap.containsKey(key);
}
boolean containsKey(K key);

public void remove(K key) {
replicatedMap.remove(key);
}
void remove(K key);

public void clear() {
replicatedMap.clear();
}
void clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public interface ReplicatedDataFactory {
/** Create a new ReplicatedSet. */
<T> ReplicatedSet<T> newReplicatedSet();

/** Create a new multimap (map of sets). */
<K, V> ReplicatedMultiMap<K, V> newReplicatedMultiMap();

/** Create a new ReplicatedRegister. */
<T> ReplicatedRegister<T> newRegister(T value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
/**
* A Replicated Map that allows both the addition and removal of objects in a map.
*
* <p>Use the more specialized maps if possible, such as {@link ReplicatedCounterMap} and {@link
* ReplicatedRegisterMap}.
* <p>Use the more specialized maps if possible, such as {@link ReplicatedCounterMap}, {@link
* ReplicatedRegisterMap}, and {@link ReplicatedMultiMap}.
*
* <p>A removal can only be done if all of the additions that caused the key to be in the map have
* been seen by this node. This means that, for example, if node 1 adds key A, and node 2 also adds
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright 2021 Lightbend Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.akkaserverless.javasdk.replicatedentity;

import java.util.Collection;
import java.util.Set;

/**
* A replicated map that maps keys to values, where each key may be associated with multiple values.
* Effectively a ReplicatedMap with {@link ReplicatedSet}s as values.
*
* @param <K> The type for keys.
* @param <V> The type for values.
*/
public interface ReplicatedMultiMap<K, V> extends ReplicatedData {

/**
* Get the values for the given key.
*
* @param key The key of the entry.
* @return The current values at the given key, or an empty Set.
*/
Set<V> get(K key);

/**
* Store a key-value pair.
*
* @param key The key of the entry.
* @param value The value to add to the entry.
* @return {@code true} if the multimap changed (this key-value pair was added).
*/
boolean put(K key, V value);

/**
* Store multiple values for a key.
*
* @param key The key of the entry.
* @param values The values to add to the entry.
* @return {@code true} if the multimap changed (values were added).
*/
boolean putAll(K key, Collection<V> values);

/**
* Remove a single key-value pair for the given key and value.
*
* @param key The key of the entry.
* @param value The value to remove from the entry.
* @return {@code true} if the multimap changed (this key-value pair was removed).
*/
boolean remove(K key, V value);

/**
* Remove all values associated with the given key.
*
* @param key The key of the entry.
* @return {@code true} if the multimap changed (values were removed).
*/
boolean removeAll(K key);

/**
* Return the keys contained in this multimap.
*
* <p>Note that the key set contains a key if and only if this multimap maps that key to at least
* one value.
*
* @return the set of keys in this multimap.
*/
Set<K> keySet();

/**
* Return the number of key-value pairs in this multimap.
*
* <p>Note that this does not return the number of distinct keys, which is given by {@code
* keySet().size()}, but the total number of values stored in the multimap.
*
* @return the number of key-value pairs stored in this multimap.
*/
int size();

/**
* Check whether this multimap is empty.
*
* @return {@code true} if this multimap contains no key-value pairs.
*/
boolean isEmpty();

/**
* Check whether this multimap contains at least one value for the given key.
*
* @param key The key of the entry.
* @return {@code true} if there is at least one key-value pair with the key.
*/
boolean containsKey(K key);

/**
* Check whether this multimap contains the given value associated with the given key.
*
* @param key The key of the entry.
* @param value The value of the entry.
* @return {@code true} if the key-value pair is in this multimap.
*/
boolean containsValue(K key, V value);

/** Remove all key-value pairs from the multimap, leaving it empty. */
void clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,47 @@
* @param <K> The type for keys.
* @param <V> The type for values.
*/
public final class ReplicatedRegisterMap<K, V> implements ReplicatedData {
public interface ReplicatedRegisterMap<K, V> extends ReplicatedData {

private final ReplicatedMap<K, ReplicatedRegister<V>> replicatedMap;
/**
* Get the current value of the register at the given key.
*
* @param key The key for the register.
* @return The current value of the register, if it exists (as an Optional).
*/
Optional<V> getValue(K key);

public ReplicatedRegisterMap(ReplicatedMap<K, ReplicatedRegister<V>> replicatedMap) {
this.replicatedMap = replicatedMap;
/**
* Set the current value of the register at the given key, using the default clock.
*
* @param key The key for the register.
* @param value The value of the register to set.
*/
default void setValue(K key, V value) {
setValue(key, value, ReplicatedRegister.Clock.DEFAULT, 0);
}

Optional<V> getValue(K key) {
ReplicatedRegister<V> register = replicatedMap.get(key);
if (register == null) return Optional.empty();
else return Optional.ofNullable(register.get());
}
/**
* Set the current value of the register at the given key, using the given clock and custom clock
* value if required.
*
* @param key The key for the register.
* @param value The value of the register to set.
* @param clock The clock to use.
* @param customClockValue The custom clock value to use if the clock selected is a custom clock.
* This is ignored if the clock is not a custom clock.
*/
void setValue(K key, V value, ReplicatedRegister.Clock clock, long customClockValue);

void setValue(K key, V value) {
ReplicatedRegister<V> register = replicatedMap.get(key);
if (register == null) replicatedMap.getOrCreate(key, f -> f.newRegister(value));
else register.set(value);
}
Set<K> keySet();

public Set<K> keySet() {
return replicatedMap.keySet();
}
int size();

public int size() {
return replicatedMap.size();
}
boolean isEmpty();

public boolean isEmpty() {
return replicatedMap.isEmpty();
}
boolean containsKey(K key);

public boolean containsKey(K key) {
return replicatedMap.containsKey(key);
}

public void remove(K key) {
replicatedMap.remove(key);
}
void remove(K key);

public void clear() {
replicatedMap.clear();
}
void clear();
}
Loading