Committed by
Gerrit Code Review
Refactored primitive builders to consolidate methods into the base DistributedPrimitiveBuilder
Change-Id: I9a24117b41d1feeb5cf460c6adfa484aabcbb8c1
Showing
19 changed files
with
181 additions
and
393 deletions
... | @@ -89,7 +89,8 @@ public class DistributedDhcpStore implements DhcpStore { | ... | @@ -89,7 +89,8 @@ public class DistributedDhcpStore implements DhcpStore { |
89 | freeIPPool = storageService.<Ip4Address>setBuilder() | 89 | freeIPPool = storageService.<Ip4Address>setBuilder() |
90 | .withName("onos-dhcp-freeIP") | 90 | .withName("onos-dhcp-freeIP") |
91 | .withSerializer(Serializer.using(KryoNamespaces.API)) | 91 | .withSerializer(Serializer.using(KryoNamespaces.API)) |
92 | - .build(); | 92 | + .build() |
93 | + .asDistributedSet(); | ||
93 | 94 | ||
94 | log.info("Started"); | 95 | log.info("Started"); |
95 | } | 96 | } | ... | ... |
... | @@ -56,7 +56,8 @@ public class SetTestAddCommand extends AbstractShellCommand { | ... | @@ -56,7 +56,8 @@ public class SetTestAddCommand extends AbstractShellCommand { |
56 | set = storageService.<String>setBuilder() | 56 | set = storageService.<String>setBuilder() |
57 | .withName(setName) | 57 | .withName(setName) |
58 | .withSerializer(serializer) | 58 | .withSerializer(serializer) |
59 | - .build(); | 59 | + .build() |
60 | + .asDistributedSet(); | ||
60 | 61 | ||
61 | // Add a single element to the set | 62 | // Add a single element to the set |
62 | if (values.length == 1) { | 63 | if (values.length == 1) { | ... | ... |
... | @@ -61,7 +61,8 @@ public class SetTestGetCommand extends AbstractShellCommand { | ... | @@ -61,7 +61,8 @@ public class SetTestGetCommand extends AbstractShellCommand { |
61 | set = storageService.<String>setBuilder() | 61 | set = storageService.<String>setBuilder() |
62 | .withName(setName) | 62 | .withName(setName) |
63 | .withSerializer(serializer) | 63 | .withSerializer(serializer) |
64 | - .build(); | 64 | + .build() |
65 | + .asDistributedSet(); | ||
65 | 66 | ||
66 | // Print the set size | 67 | // Print the set size |
67 | if (size) { | 68 | if (size) { | ... | ... |
... | @@ -64,7 +64,8 @@ public class SetTestRemoveCommand extends AbstractShellCommand { | ... | @@ -64,7 +64,8 @@ public class SetTestRemoveCommand extends AbstractShellCommand { |
64 | set = storageService.<String>setBuilder() | 64 | set = storageService.<String>setBuilder() |
65 | .withName(setName) | 65 | .withName(setName) |
66 | .withSerializer(serializer) | 66 | .withSerializer(serializer) |
67 | - .build(); | 67 | + .build() |
68 | + .asDistributedSet(); | ||
68 | 69 | ||
69 | if (clear) { | 70 | if (clear) { |
70 | set.clear(); | 71 | set.clear(); | ... | ... |
... | @@ -52,7 +52,8 @@ public class ClassifierManager implements ClassifierService { | ... | @@ -52,7 +52,8 @@ public class ClassifierManager implements ClassifierService { |
52 | classifierList = storageService.<DeviceId>setBuilder() | 52 | classifierList = storageService.<DeviceId>setBuilder() |
53 | .withName("classifier") | 53 | .withName("classifier") |
54 | .withSerializer(Serializer.using(KryoNamespaces.API)) | 54 | .withSerializer(Serializer.using(KryoNamespaces.API)) |
55 | - .build(); | 55 | + .build() |
56 | + .asDistributedSet(); | ||
56 | log.info("Started"); | 57 | log.info("Started"); |
57 | } | 58 | } |
58 | 59 | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.store.primitives.impl; | 16 | +package org.onosproject.store.primitives; |
17 | 17 | ||
18 | import java.lang.reflect.Array; | 18 | import java.lang.reflect.Array; |
19 | import java.util.Collection; | 19 | import java.util.Collection; |
... | @@ -37,30 +37,14 @@ import org.onosproject.store.service.Synchronous; | ... | @@ -37,30 +37,14 @@ import org.onosproject.store.service.Synchronous; |
37 | */ | 37 | */ |
38 | public class DefaultDistributedSet<E> extends Synchronous<AsyncDistributedSet<E>> implements DistributedSet<E> { | 38 | public class DefaultDistributedSet<E> extends Synchronous<AsyncDistributedSet<E>> implements DistributedSet<E> { |
39 | 39 | ||
40 | - private static final long OPERATION_TIMEOUT_MILLIS = 5000; | 40 | + private final long operationTimeoutMillis; |
41 | 41 | ||
42 | private final AsyncDistributedSet<E> asyncSet; | 42 | private final AsyncDistributedSet<E> asyncSet; |
43 | 43 | ||
44 | - public DefaultDistributedSet(AsyncDistributedSet<E> asyncSet) { | 44 | + public DefaultDistributedSet(AsyncDistributedSet<E> asyncSet, long operationTimeoutMillis) { |
45 | super(asyncSet); | 45 | super(asyncSet); |
46 | this.asyncSet = asyncSet; | 46 | this.asyncSet = asyncSet; |
47 | - } | 47 | + this.operationTimeoutMillis = operationTimeoutMillis; |
48 | - | ||
49 | - private static <T> T complete(CompletableFuture<T> future) { | ||
50 | - try { | ||
51 | - return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); | ||
52 | - } catch (InterruptedException e) { | ||
53 | - Thread.currentThread().interrupt(); | ||
54 | - throw new StorageException.Interrupted(); | ||
55 | - } catch (TimeoutException e) { | ||
56 | - throw new StorageException.Timeout(); | ||
57 | - } catch (ExecutionException e) { | ||
58 | - if (e.getCause() instanceof StorageException) { | ||
59 | - throw (StorageException) e.getCause(); | ||
60 | - } else { | ||
61 | - throw new StorageException(e.getCause()); | ||
62 | - } | ||
63 | - } | ||
64 | } | 48 | } |
65 | 49 | ||
66 | @Override | 50 | @Override |
... | @@ -149,4 +133,21 @@ public class DefaultDistributedSet<E> extends Synchronous<AsyncDistributedSet<E> | ... | @@ -149,4 +133,21 @@ public class DefaultDistributedSet<E> extends Synchronous<AsyncDistributedSet<E> |
149 | public void removeListener(SetEventListener<E> listener) { | 133 | public void removeListener(SetEventListener<E> listener) { |
150 | complete(asyncSet.removeListener(listener)); | 134 | complete(asyncSet.removeListener(listener)); |
151 | } | 135 | } |
136 | + | ||
137 | + private <T> T complete(CompletableFuture<T> future) { | ||
138 | + try { | ||
139 | + return future.get(operationTimeoutMillis, TimeUnit.MILLISECONDS); | ||
140 | + } catch (InterruptedException e) { | ||
141 | + Thread.currentThread().interrupt(); | ||
142 | + throw new StorageException.Interrupted(); | ||
143 | + } catch (TimeoutException e) { | ||
144 | + throw new StorageException.Timeout(); | ||
145 | + } catch (ExecutionException e) { | ||
146 | + if (e.getCause() instanceof StorageException) { | ||
147 | + throw (StorageException) e.getCause(); | ||
148 | + } else { | ||
149 | + throw new StorageException(e.getCause()); | ||
150 | + } | ||
151 | + } | ||
152 | + } | ||
152 | } | 153 | } | ... | ... |
... | @@ -24,7 +24,8 @@ import org.onosproject.store.service.Serializer; | ... | @@ -24,7 +24,8 @@ import org.onosproject.store.service.Serializer; |
24 | * | 24 | * |
25 | * @param <T> distributed primitive type | 25 | * @param <T> distributed primitive type |
26 | */ | 26 | */ |
27 | -public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive> { | 27 | +public abstract class DistributedPrimitiveBuilder<B extends DistributedPrimitiveBuilder<B, T>, |
28 | + T extends DistributedPrimitive> { | ||
28 | 29 | ||
29 | private DistributedPrimitive.Type type; | 30 | private DistributedPrimitive.Type type; |
30 | private String name; | 31 | private String name; |
... | @@ -32,6 +33,8 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive | ... | @@ -32,6 +33,8 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive |
32 | private Serializer serializer; | 33 | private Serializer serializer; |
33 | private boolean partitionsDisabled = false; | 34 | private boolean partitionsDisabled = false; |
34 | private boolean meteringDisabled = false; | 35 | private boolean meteringDisabled = false; |
36 | + private boolean readOnly = false; | ||
37 | + private boolean relaxedReadConsistency = false; | ||
35 | 38 | ||
36 | public DistributedPrimitiveBuilder(DistributedPrimitive.Type type) { | 39 | public DistributedPrimitiveBuilder(DistributedPrimitive.Type type) { |
37 | this.type = type; | 40 | this.type = type; |
... | @@ -43,9 +46,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive | ... | @@ -43,9 +46,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive |
43 | * @param name primitive name | 46 | * @param name primitive name |
44 | * @return this builder | 47 | * @return this builder |
45 | */ | 48 | */ |
46 | - public DistributedPrimitiveBuilder<T> withName(String name) { | 49 | + public B withName(String name) { |
47 | this.name = name; | 50 | this.name = name; |
48 | - return this; | 51 | + return (B) this; |
49 | } | 52 | } |
50 | 53 | ||
51 | /** | 54 | /** |
... | @@ -54,9 +57,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive | ... | @@ -54,9 +57,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive |
54 | * @param serializer serializer | 57 | * @param serializer serializer |
55 | * @return this builder | 58 | * @return this builder |
56 | */ | 59 | */ |
57 | - public DistributedPrimitiveBuilder<T> withSerializer(Serializer serializer) { | 60 | + public B withSerializer(Serializer serializer) { |
58 | this.serializer = serializer; | 61 | this.serializer = serializer; |
59 | - return this; | 62 | + return (B) this; |
60 | } | 63 | } |
61 | 64 | ||
62 | /** | 65 | /** |
... | @@ -65,9 +68,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive | ... | @@ -65,9 +68,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive |
65 | * @param applicationId application identifier | 68 | * @param applicationId application identifier |
66 | * @return this builder | 69 | * @return this builder |
67 | */ | 70 | */ |
68 | - public DistributedPrimitiveBuilder<T> withApplicationId(ApplicationId applicationId) { | 71 | + public B withApplicationId(ApplicationId applicationId) { |
69 | this.applicationId = applicationId; | 72 | this.applicationId = applicationId; |
70 | - return this; | 73 | + return (B) this; |
71 | } | 74 | } |
72 | 75 | ||
73 | /** | 76 | /** |
... | @@ -77,9 +80,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive | ... | @@ -77,9 +80,9 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive |
77 | * @return this builder | 80 | * @return this builder |
78 | */ | 81 | */ |
79 | @Deprecated | 82 | @Deprecated |
80 | - public DistributedPrimitiveBuilder<T> withPartitionsDisabled() { | 83 | + public B withPartitionsDisabled() { |
81 | this.partitionsDisabled = true; | 84 | this.partitionsDisabled = true; |
82 | - return this; | 85 | + return (B) this; |
83 | } | 86 | } |
84 | 87 | ||
85 | /** | 88 | /** |
... | @@ -88,9 +91,27 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive | ... | @@ -88,9 +91,27 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive |
88 | * @return this builder | 91 | * @return this builder |
89 | */ | 92 | */ |
90 | @Deprecated | 93 | @Deprecated |
91 | - public DistributedPrimitiveBuilder<T> withMeteringDisabled() { | 94 | + public B withMeteringDisabled() { |
92 | this.meteringDisabled = true; | 95 | this.meteringDisabled = true; |
93 | - return this; | 96 | + return (B) this; |
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Disables state changing operations on the returned distributed primitive. | ||
101 | + * @return this builder | ||
102 | + */ | ||
103 | + public B withUpdatesDisabled() { | ||
104 | + this.readOnly = true; | ||
105 | + return (B) this; | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * Turns on relaxed consistency for read operations. | ||
110 | + * @return this builder | ||
111 | + */ | ||
112 | + public B withRelaxedReadConsistency() { | ||
113 | + this.relaxedReadConsistency = true; | ||
114 | + return (B) this; | ||
94 | } | 115 | } |
95 | 116 | ||
96 | /** | 117 | /** |
... | @@ -112,6 +133,24 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive | ... | @@ -112,6 +133,24 @@ public abstract class DistributedPrimitiveBuilder<T extends DistributedPrimitive |
112 | } | 133 | } |
113 | 134 | ||
114 | /** | 135 | /** |
136 | + * Returns if updates are disabled. | ||
137 | + * | ||
138 | + * @return {@code true} if yes; {@code false} otherwise | ||
139 | + */ | ||
140 | + public final boolean readOnly() { | ||
141 | + return readOnly; | ||
142 | + } | ||
143 | + | ||
144 | + /** | ||
145 | + * Returns if consistency is relaxed for read operations. | ||
146 | + * | ||
147 | + * @return {@code true} if yes; {@code false} otherwise | ||
148 | + */ | ||
149 | + public final boolean relaxedReadConsistency() { | ||
150 | + return relaxedReadConsistency; | ||
151 | + } | ||
152 | + | ||
153 | + /** | ||
115 | * Returns the serializer. | 154 | * Returns the serializer. |
116 | * | 155 | * |
117 | * @return serializer | 156 | * @return serializer | ... | ... |
... | @@ -19,6 +19,8 @@ import java.util.Collection; | ... | @@ -19,6 +19,8 @@ import java.util.Collection; |
19 | import java.util.Set; | 19 | import java.util.Set; |
20 | import java.util.concurrent.CompletableFuture; | 20 | import java.util.concurrent.CompletableFuture; |
21 | 21 | ||
22 | +import org.onosproject.store.primitives.DefaultDistributedSet; | ||
23 | + | ||
22 | /** | 24 | /** |
23 | * A distributed collection designed for holding unique elements. | 25 | * A distributed collection designed for holding unique elements. |
24 | * <p> | 26 | * <p> |
... | @@ -122,6 +124,26 @@ public interface AsyncDistributedSet<E> extends DistributedPrimitive { | ... | @@ -122,6 +124,26 @@ public interface AsyncDistributedSet<E> extends DistributedPrimitive { |
122 | */ | 124 | */ |
123 | CompletableFuture<Boolean> removeAll(Collection<? extends E> c); | 125 | CompletableFuture<Boolean> removeAll(Collection<? extends E> c); |
124 | 126 | ||
127 | + | ||
128 | + /** | ||
129 | + * Returns a new {@link DistributedSet} that is backed by this instance. | ||
130 | + * | ||
131 | + * @return new {@code DistributedSet} instance | ||
132 | + */ | ||
133 | + default DistributedSet<E> asDistributedSet() { | ||
134 | + return asDistributedSet(DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS); | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * Returns a new {@link DistributedSet} that is backed by this instance. | ||
139 | + * | ||
140 | + * @param timeoutMillis timeout duration for the returned DistributedSet operations | ||
141 | + * @return new {@code DistributedSet} instance | ||
142 | + */ | ||
143 | + default DistributedSet<E> asDistributedSet(long timeoutMillis) { | ||
144 | + return new DefaultDistributedSet<>(this, timeoutMillis); | ||
145 | + } | ||
146 | + | ||
125 | /** | 147 | /** |
126 | * Returns the entries as a immutable set. The returned set is a snapshot and will not reflect new changes made to | 148 | * Returns the entries as a immutable set. The returned set is a snapshot and will not reflect new changes made to |
127 | * this AsyncDistributedSet | 149 | * this AsyncDistributedSet | ... | ... |
... | @@ -20,7 +20,8 @@ import org.onosproject.store.primitives.DistributedPrimitiveBuilder; | ... | @@ -20,7 +20,8 @@ import org.onosproject.store.primitives.DistributedPrimitiveBuilder; |
20 | /** | 20 | /** |
21 | * Builder for AtomicCounter. | 21 | * Builder for AtomicCounter. |
22 | */ | 22 | */ |
23 | -public abstract class AtomicCounterBuilder extends DistributedPrimitiveBuilder<AsyncAtomicCounter> { | 23 | +public abstract class AtomicCounterBuilder |
24 | + extends DistributedPrimitiveBuilder<AtomicCounterBuilder, AsyncAtomicCounter> { | ||
24 | public AtomicCounterBuilder() { | 25 | public AtomicCounterBuilder() { |
25 | super(DistributedPrimitive.Type.COUNTER); | 26 | super(DistributedPrimitive.Type.COUNTER); |
26 | } | 27 | } | ... | ... |
... | @@ -22,7 +22,8 @@ import org.onosproject.store.primitives.DistributedPrimitiveBuilder; | ... | @@ -22,7 +22,8 @@ import org.onosproject.store.primitives.DistributedPrimitiveBuilder; |
22 | * | 22 | * |
23 | * @param <V> atomic value type | 23 | * @param <V> atomic value type |
24 | */ | 24 | */ |
25 | -public abstract class AtomicValueBuilder<V> extends DistributedPrimitiveBuilder<AsyncAtomicValue<V>> { | 25 | +public abstract class AtomicValueBuilder<V> |
26 | + extends DistributedPrimitiveBuilder<AtomicValueBuilder<V>, AsyncAtomicValue<V>> { | ||
26 | 27 | ||
27 | public AtomicValueBuilder() { | 28 | public AtomicValueBuilder() { |
28 | super(DistributedPrimitive.Type.VALUE); | 29 | super(DistributedPrimitive.Type.VALUE); | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.service; | 16 | package org.onosproject.store.service; |
17 | 17 | ||
18 | -import org.onosproject.core.ApplicationId; | 18 | +import org.onosproject.store.primitives.DistributedPrimitiveBuilder; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * Builder for {@link ConsistentMap} instances. | 21 | * Builder for {@link ConsistentMap} instances. |
... | @@ -23,115 +23,32 @@ import org.onosproject.core.ApplicationId; | ... | @@ -23,115 +23,32 @@ import org.onosproject.core.ApplicationId; |
23 | * @param <K> type for map key | 23 | * @param <K> type for map key |
24 | * @param <V> type for map value | 24 | * @param <V> type for map value |
25 | */ | 25 | */ |
26 | -public interface ConsistentMapBuilder<K, V> { | 26 | +public abstract class ConsistentMapBuilder<K, V> |
27 | + extends DistributedPrimitiveBuilder<ConsistentMapBuilder<K, V>, ConsistentMap<K, V>> { | ||
27 | 28 | ||
28 | - /** | 29 | + private boolean purgeOnUninstall = false; |
29 | - * Sets the name of the map. | ||
30 | - * <p> | ||
31 | - * Each map is identified by a unique map name. Different instances with the same name are all backed by the | ||
32 | - * same backend state. | ||
33 | - * </p> | ||
34 | - * <p> | ||
35 | - * <b>Note:</b> This is a mandatory parameter. | ||
36 | - * </p> | ||
37 | - * | ||
38 | - * @param name name of the map | ||
39 | - * @return this ConsistentMapBuilder | ||
40 | - */ | ||
41 | - ConsistentMapBuilder<K, V> withName(String name); | ||
42 | - | ||
43 | - /** | ||
44 | - * Sets the identifier of the application that owns this map instance. | ||
45 | - * <p> | ||
46 | - * Note: If {@code purgeOnUninstall} option is enabled, applicationId | ||
47 | - * must be specified. | ||
48 | - * </p> | ||
49 | - * | ||
50 | - * @param id applicationId owning the consistent map | ||
51 | - * @return this ConsistentMapBuilder | ||
52 | - */ | ||
53 | - ConsistentMapBuilder<K, V> withApplicationId(ApplicationId id); | ||
54 | - | ||
55 | - /** | ||
56 | - * Sets a serializer that can be used to serialize | ||
57 | - * both the keys and values inserted into the map. The serializer | ||
58 | - * builder should be pre-populated with any classes that will be | ||
59 | - * put into the map. | ||
60 | - * <p> | ||
61 | - * Note: This is a mandatory parameter. | ||
62 | - * </p> | ||
63 | - * | ||
64 | - * @param serializer serializer | ||
65 | - * @return this ConsistentMapBuilder | ||
66 | - */ | ||
67 | - ConsistentMapBuilder<K, V> withSerializer(Serializer serializer); | ||
68 | - | ||
69 | - /** | ||
70 | - * Disables distribution of map entries across multiple database partitions. | ||
71 | - * <p> | ||
72 | - * When partitioning is disabled, the returned map will have a single partition | ||
73 | - * that spans the entire cluster. Furthermore, the changes made to the map are | ||
74 | - * ephemeral and do not survive a full cluster restart. | ||
75 | - * </p> | ||
76 | - * <p> | ||
77 | - * Disabling partitions is more appropriate when the returned map is used for | ||
78 | - * coordination activities such as leader election and not for long term data persistence. | ||
79 | - * </p> | ||
80 | - * <p> | ||
81 | - * Note: By default partitions are enabled and entries in the map are durable. | ||
82 | - * </p> | ||
83 | - * @return this ConsistentMapBuilder | ||
84 | - */ | ||
85 | - ConsistentMapBuilder<K, V> withPartitionsDisabled(); | ||
86 | 30 | ||
87 | - /** | 31 | + public ConsistentMapBuilder() { |
88 | - * Disables map updates. | 32 | + super(DistributedPrimitive.Type.CONSISTENT_MAP); |
89 | - * <p> | 33 | + } |
90 | - * Attempt to update the built map will throw {@code UnsupportedOperationException}. | ||
91 | - * | ||
92 | - * @return this ConsistentMapBuilder | ||
93 | - */ | ||
94 | - ConsistentMapBuilder<K, V> withUpdatesDisabled(); | ||
95 | - | ||
96 | - /** | ||
97 | - * Purges map contents when the application owning the map is uninstalled. | ||
98 | - * <p> | ||
99 | - * When this option is enabled, the caller must provide a applicationId via | ||
100 | - * the {@code withAppliationId} builder method. | ||
101 | - * <p> | ||
102 | - * By default map entries will NOT be purged when owning application is uninstalled. | ||
103 | - * | ||
104 | - * @return this ConsistentMapBuilder | ||
105 | - */ | ||
106 | - ConsistentMapBuilder<K, V> withPurgeOnUninstall(); | ||
107 | 34 | ||
108 | /** | 35 | /** |
109 | - * Instantiates Metering service to gather usage and performance metrics. | 36 | + * Clears map contents when the owning application is uninstalled. |
110 | - * By default, usage data will be stored. | ||
111 | * | 37 | * |
112 | - * @return this ConsistentMapBuilder | 38 | + * return this builder |
113 | */ | 39 | */ |
114 | - ConsistentMapBuilder<K, V> withMeteringDisabled(); | 40 | + public ConsistentMapBuilder<K, V> withPurgeOnUninstall() { |
41 | + purgeOnUninstall = true; | ||
42 | + return this; | ||
43 | + } | ||
115 | 44 | ||
116 | /** | 45 | /** |
117 | - * Provides weak consistency for map gets. | 46 | + * Returns if map entries need to be cleared when owning application is uninstalled. |
118 | - * <p> | 47 | + * @return {@code true} if yes; {@code false} otherwise. |
119 | - * While this can lead to improved read performance, it can also make the behavior | ||
120 | - * heard to reason. Only turn this on if you know what you are doing. By default | ||
121 | - * reads are strongly consistent. | ||
122 | - * | ||
123 | - * @return this ConsistentMapBuilder | ||
124 | - */ | ||
125 | - ConsistentMapBuilder<K, V> withRelaxedReadConsistency(); | ||
126 | - | ||
127 | - /** | ||
128 | - * Builds an consistent map based on the configuration options | ||
129 | - * supplied to this builder. | ||
130 | - * | ||
131 | - * @return new consistent map | ||
132 | - * @throws java.lang.RuntimeException if a mandatory parameter is missing | ||
133 | */ | 48 | */ |
134 | - ConsistentMap<K, V> build(); | 49 | + public boolean purgeOnUninstall() { |
50 | + return purgeOnUninstall; | ||
51 | + } | ||
135 | 52 | ||
136 | /** | 53 | /** |
137 | * Builds an async consistent map based on the configuration options | 54 | * Builds an async consistent map based on the configuration options |
... | @@ -140,5 +57,5 @@ public interface ConsistentMapBuilder<K, V> { | ... | @@ -140,5 +57,5 @@ public interface ConsistentMapBuilder<K, V> { |
140 | * @return new async consistent map | 57 | * @return new async consistent map |
141 | * @throws java.lang.RuntimeException if a mandatory parameter is missing | 58 | * @throws java.lang.RuntimeException if a mandatory parameter is missing |
142 | */ | 59 | */ |
143 | - AsyncConsistentMap<K, V> buildAsyncMap(); | 60 | + public abstract AsyncConsistentMap<K, V> buildAsyncMap(); |
144 | } | 61 | } | ... | ... |
... | @@ -15,127 +15,37 @@ | ... | @@ -15,127 +15,37 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.service; | 16 | package org.onosproject.store.service; |
17 | 17 | ||
18 | -import org.onosproject.core.ApplicationId; | 18 | +import org.onosproject.store.primitives.DistributedPrimitiveBuilder; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * Builder for distributed set. | 21 | * Builder for distributed set. |
22 | * | 22 | * |
23 | * @param <E> type set elements. | 23 | * @param <E> type set elements. |
24 | */ | 24 | */ |
25 | -public interface DistributedSetBuilder<E> { | 25 | +public abstract class DistributedSetBuilder<E> extends DistributedPrimitiveBuilder<DistributedSetBuilder<E>, |
26 | + AsyncDistributedSet<E>> { | ||
26 | 27 | ||
27 | - /** | 28 | + private boolean purgeOnUninstall = false; |
28 | - * Sets the name of the set. | ||
29 | - * <p> | ||
30 | - * Each set is identified by a unique name. | ||
31 | - * </p> | ||
32 | - * <p> | ||
33 | - * Note: This is a mandatory parameter. | ||
34 | - * </p> | ||
35 | - * | ||
36 | - * @param name name of the set | ||
37 | - * @return this DistributedSetBuilder | ||
38 | - */ | ||
39 | - DistributedSetBuilder<E> withName(String name); | ||
40 | 29 | ||
41 | - /** | 30 | + public DistributedSetBuilder() { |
42 | - * Sets the owner applicationId for the set. | 31 | + super(DistributedPrimitive.Type.SET); |
43 | - * <p> | 32 | + } |
44 | - * Note: If {@code purgeOnUninstall} option is enabled, applicationId | ||
45 | - * must be specified. | ||
46 | - * </p> | ||
47 | - * | ||
48 | - * @param id applicationId owning the set | ||
49 | - * @return this DistributedSetBuilder | ||
50 | - */ | ||
51 | - DistributedSetBuilder<E> withApplicationId(ApplicationId id); | ||
52 | 33 | ||
53 | /** | 34 | /** |
54 | - * Sets a serializer that can be used to serialize | 35 | + * Enables clearing set contents when the owning application is uninstalled. |
55 | - * the elements add to the set. The serializer | ||
56 | - * builder should be pre-populated with any classes that will be | ||
57 | - * put into the set. | ||
58 | - * <p> | ||
59 | - * Note: This is a mandatory parameter. | ||
60 | - * </p> | ||
61 | * | 36 | * |
62 | - * @param serializer serializer | 37 | + * return this builder |
63 | - * @return this DistributedSetBuilder | ||
64 | */ | 38 | */ |
65 | - DistributedSetBuilder<E> withSerializer(Serializer serializer); | 39 | + public DistributedSetBuilder<E> withPurgeOnUninstall() { |
40 | + purgeOnUninstall = true; | ||
41 | + return this; | ||
42 | + } | ||
66 | 43 | ||
67 | /** | 44 | /** |
68 | - * Disables set updates. | 45 | + * Returns if set contents need to be cleared when owning application is uninstalled. |
69 | - * <p> | 46 | + * @return {@code true} if yes; {@code false} otherwise. |
70 | - * Attempt to update the built set will throw {@code UnsupportedOperationException}. | ||
71 | - * | ||
72 | - * @return this DistributedSetBuilder | ||
73 | - */ | ||
74 | - DistributedSetBuilder<E> withUpdatesDisabled(); | ||
75 | - | ||
76 | - /** | ||
77 | - * Provides weak consistency for set reads. | ||
78 | - * <p> | ||
79 | - * While this can lead to improved read performance, it can also make the behavior | ||
80 | - * heard to reason. Only turn this on if you know what you are doing. By default | ||
81 | - * reads are strongly consistent. | ||
82 | - * | ||
83 | - * @return this DistributedSetBuilder | ||
84 | - */ | ||
85 | - DistributedSetBuilder<E> withRelaxedReadConsistency(); | ||
86 | - | ||
87 | - /** | ||
88 | - * Disables distribution of set entries across multiple database partitions. | ||
89 | - * <p> | ||
90 | - * When partitioning is disabled, the returned set will have a single partition | ||
91 | - * that spans the entire cluster. Furthermore, the changes made to the set are | ||
92 | - * ephemeral and do not survive a full cluster restart. | ||
93 | - * </p> | ||
94 | - * <p> | ||
95 | - * Disabling partitions is more appropriate when the returned set is used for | ||
96 | - * simple coordination activities and not for long term data persistence. | ||
97 | - * </p> | ||
98 | - * <p> | ||
99 | - * Note: By default partitions are enabled and entries in the set are durable. | ||
100 | - * </p> | ||
101 | - * @return this DistributedSetBuilder | ||
102 | - */ | ||
103 | - DistributedSetBuilder<E> withPartitionsDisabled(); | ||
104 | - | ||
105 | - /** | ||
106 | - * Instantiate Metrics service to gather usage and performance metrics. | ||
107 | - * By default usage information is enabled | ||
108 | - * @return this DistributedSetBuilder | ||
109 | - */ | ||
110 | - DistributedSetBuilder<E> withMeteringDisabled(); | ||
111 | - | ||
112 | - /** | ||
113 | - * Purges set contents when the application owning the set is uninstalled. | ||
114 | - * <p> | ||
115 | - * When this option is enabled, the caller must provide a applicationId via | ||
116 | - * the {@code withAppliationId} builder method. | ||
117 | - * <p> | ||
118 | - * By default set contents will NOT be purged when owning application is uninstalled. | ||
119 | - * | ||
120 | - * @return this DistributedSetBuilder | ||
121 | - */ | ||
122 | - DistributedSetBuilder<E> withPurgeOnUninstall(); | ||
123 | - | ||
124 | - /** | ||
125 | - * Builds an set based on the configuration options | ||
126 | - * supplied to this builder. | ||
127 | - * | ||
128 | - * @return new set | ||
129 | - * @throws java.lang.RuntimeException if a mandatory parameter is missing | ||
130 | - */ | ||
131 | - DistributedSet<E> build(); | ||
132 | - | ||
133 | - /** | ||
134 | - * Builds an {@link AsyncDistributedSet async set} based on the configuration options | ||
135 | - * supplied to this builder. | ||
136 | - * | ||
137 | - * @return new AsyncDistributedSet | ||
138 | - * @throws java.lang.RuntimeException if a mandatory parameter is missing | ||
139 | */ | 47 | */ |
140 | - AsyncDistributedSet<E> buildAsyncSet(); | 48 | + public boolean purgeOnUninstall() { |
49 | + return purgeOnUninstall; | ||
50 | + } | ||
141 | } | 51 | } | ... | ... |
... | @@ -20,7 +20,8 @@ import org.onosproject.store.primitives.DistributedPrimitiveBuilder; | ... | @@ -20,7 +20,8 @@ import org.onosproject.store.primitives.DistributedPrimitiveBuilder; |
20 | /** | 20 | /** |
21 | * Abstract base class for a transaction context builder. | 21 | * Abstract base class for a transaction context builder. |
22 | */ | 22 | */ |
23 | -public abstract class TransactionContextBuilder extends DistributedPrimitiveBuilder<TransactionContext> { | 23 | +public abstract class TransactionContextBuilder |
24 | + extends DistributedPrimitiveBuilder<TransactionContextBuilder, TransactionContext> { | ||
24 | 25 | ||
25 | public TransactionContextBuilder() { | 26 | public TransactionContextBuilder() { |
26 | super(DistributedPrimitive.Type.TRANSACTION_CONTEXT); | 27 | super(DistributedPrimitive.Type.TRANSACTION_CONTEXT); | ... | ... |
... | @@ -29,7 +29,6 @@ import java.util.function.Function; | ... | @@ -29,7 +29,6 @@ import java.util.function.Function; |
29 | import java.util.function.Predicate; | 29 | import java.util.function.Predicate; |
30 | import java.util.stream.Collectors; | 30 | import java.util.stream.Collectors; |
31 | 31 | ||
32 | -import org.onosproject.core.ApplicationId; | ||
33 | import org.onosproject.store.primitives.ConsistentMapBackedJavaMap; | 32 | import org.onosproject.store.primitives.ConsistentMapBackedJavaMap; |
34 | 33 | ||
35 | import com.google.common.base.Objects; | 34 | import com.google.common.base.Objects; |
... | @@ -293,53 +292,11 @@ public final class TestConsistentMap<K, V> extends ConsistentMapAdapter<K, V> { | ... | @@ -293,53 +292,11 @@ public final class TestConsistentMap<K, V> extends ConsistentMapAdapter<K, V> { |
293 | return new Builder(); | 292 | return new Builder(); |
294 | } | 293 | } |
295 | 294 | ||
296 | - public static class Builder<K, V> implements ConsistentMapBuilder<K, V> { | 295 | + public static class Builder<K, V> extends ConsistentMapBuilder<K, V> { |
297 | - String mapName = "map"; | ||
298 | - | ||
299 | - @Override | ||
300 | - public ConsistentMapBuilder<K, V> withName(String mapName) { | ||
301 | - this.mapName = mapName; | ||
302 | - return this; | ||
303 | - } | ||
304 | - | ||
305 | - @Override | ||
306 | - public ConsistentMapBuilder<K, V> withApplicationId(ApplicationId id) { | ||
307 | - return this; | ||
308 | - } | ||
309 | - | ||
310 | - @Override | ||
311 | - public ConsistentMapBuilder<K, V> withSerializer(Serializer serializer) { | ||
312 | - return this; | ||
313 | - } | ||
314 | - | ||
315 | - @Override | ||
316 | - public ConsistentMapBuilder<K, V> withPartitionsDisabled() { | ||
317 | - return this; | ||
318 | - } | ||
319 | - | ||
320 | - @Override | ||
321 | - public ConsistentMapBuilder<K, V> withUpdatesDisabled() { | ||
322 | - return this; | ||
323 | - } | ||
324 | - | ||
325 | - @Override | ||
326 | - public ConsistentMapBuilder<K, V> withPurgeOnUninstall() { | ||
327 | - return this; | ||
328 | - } | ||
329 | - | ||
330 | - @Override | ||
331 | - public ConsistentMapBuilder<K, V> withRelaxedReadConsistency() { | ||
332 | - return this; | ||
333 | - } | ||
334 | - | ||
335 | - @Override | ||
336 | - public ConsistentMapBuilder<K, V> withMeteringDisabled() { | ||
337 | - return this; | ||
338 | - } | ||
339 | 296 | ||
340 | @Override | 297 | @Override |
341 | public ConsistentMap<K, V> build() { | 298 | public ConsistentMap<K, V> build() { |
342 | - return new TestConsistentMap<>(mapName); | 299 | + return new TestConsistentMap<>(name()); |
343 | } | 300 | } |
344 | 301 | ||
345 | @Override | 302 | @Override | ... | ... |
... | @@ -237,7 +237,8 @@ public class ECDeviceStore | ... | @@ -237,7 +237,8 @@ public class ECDeviceStore |
237 | .withSerializer(Serializer.using(KryoNamespaces.API)) | 237 | .withSerializer(Serializer.using(KryoNamespaces.API)) |
238 | .withPartitionsDisabled() | 238 | .withPartitionsDisabled() |
239 | .withRelaxedReadConsistency() | 239 | .withRelaxedReadConsistency() |
240 | - .build(); | 240 | + .build() |
241 | + .asDistributedSet(); | ||
241 | 242 | ||
242 | deviceDescriptions.addListener(deviceUpdateListener); | 243 | deviceDescriptions.addListener(deviceUpdateListener); |
243 | portDescriptions.addListener(portUpdateListener); | 244 | portDescriptions.addListener(portUpdateListener); | ... | ... |
... | @@ -15,13 +15,10 @@ | ... | @@ -15,13 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.primitives.impl; | 16 | package org.onosproject.store.primitives.impl; |
17 | 17 | ||
18 | -import org.onosproject.core.ApplicationId; | ||
19 | import org.onosproject.store.service.AsyncConsistentMap; | 18 | import org.onosproject.store.service.AsyncConsistentMap; |
20 | import org.onosproject.store.service.ConsistentMap; | 19 | import org.onosproject.store.service.ConsistentMap; |
21 | import org.onosproject.store.service.ConsistentMapBuilder; | 20 | import org.onosproject.store.service.ConsistentMapBuilder; |
22 | -import org.onosproject.store.service.Serializer; | ||
23 | 21 | ||
24 | -import static com.google.common.base.Preconditions.checkArgument; | ||
25 | import static com.google.common.base.Preconditions.checkState; | 22 | import static com.google.common.base.Preconditions.checkState; |
26 | 23 | ||
27 | /** | 24 | /** |
... | @@ -30,85 +27,25 @@ import static com.google.common.base.Preconditions.checkState; | ... | @@ -30,85 +27,25 @@ import static com.google.common.base.Preconditions.checkState; |
30 | * @param <K> type for map key | 27 | * @param <K> type for map key |
31 | * @param <V> type for map value | 28 | * @param <V> type for map value |
32 | */ | 29 | */ |
33 | -public class DefaultConsistentMapBuilder<K, V> implements ConsistentMapBuilder<K, V> { | 30 | +public class DefaultConsistentMapBuilder<K, V> extends ConsistentMapBuilder<K, V> { |
34 | 31 | ||
35 | - private Serializer serializer; | ||
36 | - private String name; | ||
37 | - private ApplicationId applicationId; | ||
38 | - private boolean purgeOnUninstall = false; | ||
39 | - private boolean partitionsEnabled = true; | ||
40 | - private boolean readOnly = false; | ||
41 | - private boolean metering = true; | ||
42 | - private boolean relaxedReadConsistency = false; | ||
43 | private final DatabaseManager manager; | 32 | private final DatabaseManager manager; |
44 | - private static final long DEFAULT_OPERATION_TIMEOUT_MILLIS = 5000L; | ||
45 | 33 | ||
46 | public DefaultConsistentMapBuilder(DatabaseManager manager) { | 34 | public DefaultConsistentMapBuilder(DatabaseManager manager) { |
47 | this.manager = manager; | 35 | this.manager = manager; |
48 | } | 36 | } |
49 | 37 | ||
50 | - @Override | ||
51 | - public ConsistentMapBuilder<K, V> withName(String name) { | ||
52 | - checkArgument(name != null && !name.isEmpty()); | ||
53 | - this.name = name; | ||
54 | - return this; | ||
55 | - } | ||
56 | - | ||
57 | - @Override | ||
58 | - public ConsistentMapBuilder<K, V> withApplicationId(ApplicationId id) { | ||
59 | - checkArgument(id != null); | ||
60 | - this.applicationId = id; | ||
61 | - return this; | ||
62 | - } | ||
63 | - | ||
64 | - @Override | ||
65 | - public ConsistentMapBuilder<K, V> withPurgeOnUninstall() { | ||
66 | - purgeOnUninstall = true; | ||
67 | - return this; | ||
68 | - } | ||
69 | - | ||
70 | - @Override | ||
71 | - public ConsistentMapBuilder<K, V> withMeteringDisabled() { | ||
72 | - metering = false; | ||
73 | - return this; | ||
74 | - } | ||
75 | - | ||
76 | - @Override | ||
77 | - public ConsistentMapBuilder<K, V> withSerializer(Serializer serializer) { | ||
78 | - checkArgument(serializer != null); | ||
79 | - this.serializer = serializer; | ||
80 | - return this; | ||
81 | - } | ||
82 | - | ||
83 | - @Override | ||
84 | - public ConsistentMapBuilder<K, V> withPartitionsDisabled() { | ||
85 | - partitionsEnabled = false; | ||
86 | - return this; | ||
87 | - } | ||
88 | - | ||
89 | - @Override | ||
90 | - public ConsistentMapBuilder<K, V> withUpdatesDisabled() { | ||
91 | - readOnly = true; | ||
92 | - return this; | ||
93 | - } | ||
94 | - | ||
95 | - @Override | ||
96 | - public ConsistentMapBuilder<K, V> withRelaxedReadConsistency() { | ||
97 | - relaxedReadConsistency = true; | ||
98 | - return this; | ||
99 | - } | ||
100 | - | ||
101 | private void validateInputs() { | 38 | private void validateInputs() { |
102 | - checkState(name != null, "name must be specified"); | 39 | + checkState(name() != null, "name must be specified"); |
103 | - checkState(serializer != null, "serializer must be specified"); | 40 | + checkState(serializer() != null, "serializer must be specified"); |
104 | - if (purgeOnUninstall) { | 41 | + if (purgeOnUninstall()) { |
105 | - checkState(applicationId != null, "ApplicationId must be specified when purgeOnUninstall is enabled"); | 42 | + checkState(applicationId() != null, "ApplicationId must be specified when purgeOnUninstall is enabled"); |
106 | } | 43 | } |
107 | } | 44 | } |
108 | 45 | ||
109 | @Override | 46 | @Override |
110 | public ConsistentMap<K, V> build() { | 47 | public ConsistentMap<K, V> build() { |
111 | - return buildAndRegisterMap().asConsistentMap(DEFAULT_OPERATION_TIMEOUT_MILLIS); | 48 | + return buildAndRegisterMap().asConsistentMap(); |
112 | } | 49 | } |
113 | 50 | ||
114 | @Override | 51 | @Override |
... | @@ -118,25 +55,25 @@ public class DefaultConsistentMapBuilder<K, V> implements ConsistentMapBuilder<K | ... | @@ -118,25 +55,25 @@ public class DefaultConsistentMapBuilder<K, V> implements ConsistentMapBuilder<K |
118 | 55 | ||
119 | private DefaultAsyncConsistentMap<K, V> buildAndRegisterMap() { | 56 | private DefaultAsyncConsistentMap<K, V> buildAndRegisterMap() { |
120 | validateInputs(); | 57 | validateInputs(); |
121 | - Database database = partitionsEnabled ? manager.partitionedDatabase : manager.inMemoryDatabase; | 58 | + Database database = partitionsDisabled() ? manager.inMemoryDatabase : manager.partitionedDatabase; |
122 | - if (relaxedReadConsistency) { | 59 | + if (relaxedReadConsistency()) { |
123 | return manager.registerMap( | 60 | return manager.registerMap( |
124 | - new AsyncCachingConsistentMap<>(name, | 61 | + new AsyncCachingConsistentMap<>(name(), |
125 | - applicationId, | 62 | + applicationId(), |
126 | database, | 63 | database, |
127 | - serializer, | 64 | + serializer(), |
128 | - readOnly, | 65 | + readOnly(), |
129 | - purgeOnUninstall, | 66 | + purgeOnUninstall(), |
130 | - metering)); | 67 | + meteringEnabled())); |
131 | } else { | 68 | } else { |
132 | return manager.registerMap( | 69 | return manager.registerMap( |
133 | - new DefaultAsyncConsistentMap<>(name, | 70 | + new DefaultAsyncConsistentMap<>(name(), |
134 | - applicationId, | 71 | + applicationId(), |
135 | database, | 72 | database, |
136 | - serializer, | 73 | + serializer(), |
137 | - readOnly, | 74 | + readOnly(), |
138 | - purgeOnUninstall, | 75 | + purgeOnUninstall(), |
139 | - metering)); | 76 | + meteringEnabled())); |
140 | } | 77 | } |
141 | } | 78 | } |
142 | } | 79 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -20,7 +20,6 @@ import java.util.function.Supplier; | ... | @@ -20,7 +20,6 @@ import java.util.function.Supplier; |
20 | import org.onosproject.core.ApplicationId; | 20 | import org.onosproject.core.ApplicationId; |
21 | import org.onosproject.store.service.AsyncDistributedSet; | 21 | import org.onosproject.store.service.AsyncDistributedSet; |
22 | import org.onosproject.store.service.ConsistentMapBuilder; | 22 | import org.onosproject.store.service.ConsistentMapBuilder; |
23 | -import org.onosproject.store.service.DistributedSet; | ||
24 | import org.onosproject.store.service.Serializer; | 23 | import org.onosproject.store.service.Serializer; |
25 | import org.onosproject.store.service.DistributedSetBuilder; | 24 | import org.onosproject.store.service.DistributedSetBuilder; |
26 | 25 | ||
... | @@ -29,7 +28,7 @@ import org.onosproject.store.service.DistributedSetBuilder; | ... | @@ -29,7 +28,7 @@ import org.onosproject.store.service.DistributedSetBuilder; |
29 | * | 28 | * |
30 | * @param <E> type for set elements | 29 | * @param <E> type for set elements |
31 | */ | 30 | */ |
32 | -public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> { | 31 | +public class DefaultDistributedSetBuilder<E> extends DistributedSetBuilder<E> { |
33 | 32 | ||
34 | private String name; | 33 | private String name; |
35 | private ConsistentMapBuilder<E, Boolean> mapBuilder; | 34 | private ConsistentMapBuilder<E, Boolean> mapBuilder; |
... | @@ -90,12 +89,7 @@ public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> | ... | @@ -90,12 +89,7 @@ public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> |
90 | } | 89 | } |
91 | 90 | ||
92 | @Override | 91 | @Override |
93 | - public DistributedSet<E> build() { | 92 | + public AsyncDistributedSet<E> build() { |
94 | - return new DefaultDistributedSet<E>(buildAsyncSet()); | ||
95 | - } | ||
96 | - | ||
97 | - @Override | ||
98 | - public AsyncDistributedSet<E> buildAsyncSet() { | ||
99 | return new DefaultAsyncDistributedSet<E>(mapBuilder.buildAsyncMap(), name, metering); | 93 | return new DefaultAsyncDistributedSet<E>(mapBuilder.buildAsyncMap(), name, metering); |
100 | } | 94 | } |
101 | } | 95 | } | ... | ... |
... | @@ -82,14 +82,16 @@ public class DefaultTransactionContext implements TransactionContext { | ... | @@ -82,14 +82,16 @@ public class DefaultTransactionContext implements TransactionContext { |
82 | checkState(isOpen, TX_NOT_OPEN_ERROR); | 82 | checkState(isOpen, TX_NOT_OPEN_ERROR); |
83 | checkNotNull(mapName); | 83 | checkNotNull(mapName); |
84 | checkNotNull(serializer); | 84 | checkNotNull(serializer); |
85 | - return txMaps.computeIfAbsent(mapName, name -> new DefaultTransactionalMap<>( | 85 | + return txMaps.computeIfAbsent(mapName, name -> { |
86 | - name, | 86 | + ConsistentMapBuilder mapBuilder = (ConsistentMapBuilder) mapBuilderSupplier.get() |
87 | - mapBuilderSupplier.get() | ||
88 | .withName(name) | 87 | .withName(name) |
89 | - .withSerializer(serializer) | 88 | + .withSerializer(serializer); |
90 | - .buildAsyncMap(), | 89 | + return new DefaultTransactionalMap<>( |
90 | + name, | ||
91 | + mapBuilder.buildAsyncMap(), | ||
91 | this, | 92 | this, |
92 | - serializer)); | 93 | + serializer); |
94 | + }); | ||
93 | } | 95 | } |
94 | 96 | ||
95 | @SuppressWarnings("unchecked") | 97 | @SuppressWarnings("unchecked") | ... | ... |
... | @@ -48,7 +48,7 @@ public class DefaultTransactionContextBuilder extends TransactionContextBuilder | ... | @@ -48,7 +48,7 @@ public class DefaultTransactionContextBuilder extends TransactionContextBuilder |
48 | return new DefaultTransactionContext(transactionId, transactionCommitter, () -> { | 48 | return new DefaultTransactionContext(transactionId, transactionCommitter, () -> { |
49 | ConsistentMapBuilder mapBuilder = mapBuilderSupplier.get(); | 49 | ConsistentMapBuilder mapBuilder = mapBuilderSupplier.get(); |
50 | if (partitionsDisabled()) { | 50 | if (partitionsDisabled()) { |
51 | - mapBuilder = mapBuilder.withPartitionsDisabled(); | 51 | + mapBuilder = (ConsistentMapBuilder) mapBuilder.withPartitionsDisabled(); |
52 | } | 52 | } |
53 | return mapBuilder; | 53 | return mapBuilder; |
54 | }); | 54 | }); | ... | ... |
-
Please register or login to post a comment