From cf250164501260c4748eac533289acd8d84570d8 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Fri, 29 Sep 2023 11:41:47 -0400 Subject: [PATCH 1/7] Update ServiceProviderRegistry to use side-effect free set functions. --- .../provider/CacheServiceProviderRegistry.java | 10 +++------- ...fly.clustering.server.infinispan.provider.proto | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/clustering/server/infinispan/src/main/java/org/wildfly/clustering/server/infinispan/provider/CacheServiceProviderRegistry.java b/clustering/server/infinispan/src/main/java/org/wildfly/clustering/server/infinispan/provider/CacheServiceProviderRegistry.java index 9946d3696e02..29838bab3dd5 100644 --- a/clustering/server/infinispan/src/main/java/org/wildfly/clustering/server/infinispan/provider/CacheServiceProviderRegistry.java +++ b/clustering/server/infinispan/src/main/java/org/wildfly/clustering/server/infinispan/provider/CacheServiceProviderRegistry.java @@ -203,13 +203,9 @@ public CompletionStage topologyChanged(TopologyChangedEvent { if (!leftMembers.isEmpty()) { try (Batch batch = batcher.createBatch()) { - try (CloseableIterator>> entries = cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK).entrySet().iterator()) { - while (entries.hasNext()) { - Map.Entry> entry = entries.next(); - Set
addresses = entry.getValue(); - if (addresses.removeAll(leftMembers)) { - entry.setValue(addresses); - } + try (CloseableIterator keys = cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK).keySet().iterator()) { + while (keys.hasNext()) { + cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS, Flag.IGNORE_RETURN_VALUES).compute(keys.next(), new AddressSetRemoveFunction(leftMembers)); } } } diff --git a/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto b/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto index de677ad29422..24a146690520 100644 --- a/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto +++ b/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto @@ -19,3 +19,17 @@ message AddressSetAddFunction { message AddressSetRemoveFunction { repeated org.infinispan.remoting.transport.jgroups.JGroupsAddress address = 1; } + +/** + * @TypeId(145) + */ +message AddressSetAddFunction { + repeated org.infinispan.remoting.transport.jgroups.JGroupsAddress address = 1; +} + +/** + * @TypeId(146) + */ +message AddressSetRemoveFunction { + repeated org.infinispan.remoting.transport.jgroups.JGroupsAddress address = 1; +} From d96387d796d868d9342f4bbba57c4fed5cc26717 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Fri, 29 Sep 2023 16:15:03 -0400 Subject: [PATCH 2/7] Drop deprecated functions and reindex marshallers. --- .../ee/cache/function/MapPutFunction.java | 7 +------ .../ee/cache/function/MapRemoveFunction.java | 4 ---- .../ee/cache/function/SetAddFunction.java | 3 +-- .../ee/cache/function/SetRemoveFunction.java | 3 +-- ...y.clustering.server.infinispan.provider.proto | 16 ---------------- 5 files changed, 3 insertions(+), 30 deletions(-) diff --git a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapPutFunction.java b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapPutFunction.java index f9615b5dc084..14373f708a56 100644 --- a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapPutFunction.java +++ b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapPutFunction.java @@ -5,7 +5,6 @@ package org.wildfly.clustering.ee.cache.function; -import java.util.Collections; import java.util.Map; /** @@ -17,14 +16,10 @@ public class MapPutFunction extends MapComputeFunction { public MapPutFunction(K key, V value) { - super(Collections.singletonMap(key, value)); + super(Map.of(key, value)); } MapPutFunction(Map.Entry entry) { this(entry.getKey(), entry.getValue()); } - - public Map.Entry getEntry() { - return this.getOperand().entrySet().iterator().next(); - } } diff --git a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapRemoveFunction.java b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapRemoveFunction.java index bf70cbfdefe3..6cd0b96761cf 100644 --- a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapRemoveFunction.java +++ b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/MapRemoveFunction.java @@ -18,8 +18,4 @@ public class MapRemoveFunction extends MapComputeFunction { public MapRemoveFunction(K key) { super(Collections.singletonMap(key, null)); } - - public K getKey() { - return this.getOperand().keySet().iterator().next(); - } } diff --git a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetAddFunction.java b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetAddFunction.java index bd6edb99ebc3..82d63c7ea06c 100644 --- a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetAddFunction.java +++ b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetAddFunction.java @@ -6,7 +6,6 @@ package org.wildfly.clustering.ee.cache.function; import java.util.Collection; -import java.util.Collections; import java.util.Set; /** @@ -17,7 +16,7 @@ public class SetAddFunction extends CollectionAddFunction> { public SetAddFunction(V value) { - this(Collections.singleton(value)); + this(Set.of(value)); } public SetAddFunction(Collection values) { diff --git a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetRemoveFunction.java b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetRemoveFunction.java index ae8da27f3062..45b113441d75 100644 --- a/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetRemoveFunction.java +++ b/clustering/ee/cache/src/main/java/org/wildfly/clustering/ee/cache/function/SetRemoveFunction.java @@ -6,7 +6,6 @@ package org.wildfly.clustering.ee.cache.function; import java.util.Collection; -import java.util.Collections; import java.util.Set; /** @@ -17,7 +16,7 @@ public class SetRemoveFunction extends CollectionRemoveFunction> { public SetRemoveFunction(V value) { - this(Collections.singleton(value)); + this(Set.of(value)); } public SetRemoveFunction(Collection values) { diff --git a/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto b/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto index 24a146690520..78896743c849 100644 --- a/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto +++ b/clustering/server/infinispan/src/main/resources/org.wildfly.clustering.server.infinispan.provider.proto @@ -1,7 +1,5 @@ package org.wildfly.clustering.server.infinispan.provider; -import "org.jgroups.stack.proto"; -import "org.jgroups.util.proto"; import "org.infinispan.remoting.transport.jgroups.proto"; // IDs: 140 -144 @@ -19,17 +17,3 @@ message AddressSetAddFunction { message AddressSetRemoveFunction { repeated org.infinispan.remoting.transport.jgroups.JGroupsAddress address = 1; } - -/** - * @TypeId(145) - */ -message AddressSetAddFunction { - repeated org.infinispan.remoting.transport.jgroups.JGroupsAddress address = 1; -} - -/** - * @TypeId(146) - */ -message AddressSetRemoveFunction { - repeated org.infinispan.remoting.transport.jgroups.JGroupsAddress address = 1; -} From bd453838afa1cd5f3be3dcdd94977c8827a822de Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Fri, 4 Aug 2023 14:31:46 -0400 Subject: [PATCH 3/7] Cosmetic field rename. --- .../clustering/ee/infinispan/CacheEntryMutator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryMutator.java b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryMutator.java index da68209714f1..74ed040c234c 100644 --- a/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryMutator.java +++ b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryMutator.java @@ -19,7 +19,7 @@ public class CacheEntryMutator implements Mutator { private final Cache cache; - private final K id; + private final K key; private final V value; private final AtomicBoolean mutated; @@ -27,9 +27,9 @@ public CacheEntryMutator(Cache cache, Map.Entry entry) { this(cache, entry.getKey(), entry.getValue()); } - public CacheEntryMutator(Cache cache, K id, V value) { + public CacheEntryMutator(Cache cache, K key, V value) { this.cache = cache; - this.id = id; + this.key = key; this.value = value; this.mutated = cache.getCacheConfiguration().transaction().transactionMode().isTransactional() ? new AtomicBoolean(false) : null; } @@ -39,7 +39,7 @@ public void mutate() { // We only ever have to perform a replace once within a batch if ((this.mutated == null) || this.mutated.compareAndSet(false, true)) { // Use FAIL_SILENTLY to prevent mutation from failing locally due to remote exceptions - this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.FAIL_SILENTLY).put(this.id, this.value); + this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.FAIL_SILENTLY).put(this.key, this.value); } } } From 10bc6ccbfae058a199ae81ba4aa29c9971d1659b Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Fri, 4 Aug 2023 14:32:18 -0400 Subject: [PATCH 4/7] Add identity Marshaller for use with non-persistent caches. --- .../marshalling/spi/Marshaller.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/clustering/marshalling/spi/src/main/java/org/wildfly/clustering/marshalling/spi/Marshaller.java b/clustering/marshalling/spi/src/main/java/org/wildfly/clustering/marshalling/spi/Marshaller.java index 62dc9bd30d09..477e9a7dac27 100644 --- a/clustering/marshalling/spi/src/main/java/org/wildfly/clustering/marshalling/spi/Marshaller.java +++ b/clustering/marshalling/spi/src/main/java/org/wildfly/clustering/marshalling/spi/Marshaller.java @@ -14,6 +14,25 @@ */ public interface Marshaller extends Marshallability { + static Marshaller identity() { + return new Marshaller<>() { + @Override + public boolean isMarshallable(Object object) { + return true; + } + + @Override + public T read(T value) throws IOException { + return value; + } + + @Override + public T write(T value) throws IOException { + return value; + } + }; + } + /** * Reads a value from its marshalled form. * @param value the marshalled form From d5a4d164dca302813978e3b5d6ae2e8a857c85d2 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Fri, 4 Aug 2023 14:43:14 -0400 Subject: [PATCH 5/7] Add compute-based mutator implementations. --- .../RemoteCacheComputeMutatorFactory.java | 36 ++++++++++++++++++ .../RemoteCacheEntryComputeMutator.java | 35 ++++++++++++++++++ .../CacheComputeMutatorFactory.java | 36 ++++++++++++++++++ .../infinispan/CacheEntryComputeMutator.java | 37 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheComputeMutatorFactory.java create mode 100644 clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheEntryComputeMutator.java create mode 100644 clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheComputeMutatorFactory.java create mode 100644 clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryComputeMutator.java diff --git a/clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheComputeMutatorFactory.java b/clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheComputeMutatorFactory.java new file mode 100644 index 000000000000..0cc7ac96819c --- /dev/null +++ b/clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheComputeMutatorFactory.java @@ -0,0 +1,36 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.ee.hotrod; + +import java.util.function.BiFunction; +import java.util.function.Function; + +import org.infinispan.client.hotrod.RemoteCache; +import org.wildfly.clustering.ee.Mutator; +import org.wildfly.clustering.ee.MutatorFactory; + +/** + * Factory that creates compute-based Mutator instances. + * @author Paul Ferraro + * @param the cache key type + * @param the cache value type + * @param the function operand type + */ +public class RemoteCacheComputeMutatorFactory implements MutatorFactory { + + private final RemoteCache cache; + private final Function> functionFactory; + + public RemoteCacheComputeMutatorFactory(RemoteCache cache, Function> functionFactory) { + this.cache = cache; + this.functionFactory = functionFactory; + } + + @Override + public Mutator createMutator(K key, O operand) { + return new RemoteCacheEntryComputeMutator<>(this.cache, key, this.functionFactory.apply(operand)); + } +} diff --git a/clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheEntryComputeMutator.java b/clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheEntryComputeMutator.java new file mode 100644 index 000000000000..b59d8a5deb3b --- /dev/null +++ b/clustering/ee/hotrod/src/main/java/org/wildfly/clustering/ee/hotrod/RemoteCacheEntryComputeMutator.java @@ -0,0 +1,35 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.ee.hotrod; + +import java.util.function.BiFunction; + +import org.infinispan.client.hotrod.RemoteCache; +import org.wildfly.clustering.ee.Mutator; + +/** + * Mutator for a cache entry using a compute function. + * @author Paul Ferraro + * @param the cache key type + * @param the cache value type + */ +public class RemoteCacheEntryComputeMutator implements Mutator { + + private final RemoteCache cache; + private final K key; + private final BiFunction function; + + public RemoteCacheEntryComputeMutator(RemoteCache cache, K key, BiFunction function) { + this.cache = cache; + this.key = key; + this.function = function; + } + + @Override + public void mutate() { + this.cache.compute(this.key, this.function); + } +} diff --git a/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheComputeMutatorFactory.java b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheComputeMutatorFactory.java new file mode 100644 index 000000000000..48009201c930 --- /dev/null +++ b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheComputeMutatorFactory.java @@ -0,0 +1,36 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.ee.infinispan; + +import java.util.function.BiFunction; +import java.util.function.Function; + +import org.infinispan.Cache; +import org.wildfly.clustering.ee.Mutator; +import org.wildfly.clustering.ee.MutatorFactory; + +/** + * Factory that creates compute-based Mutator instances. + * @author Paul Ferraro + * @param the cache key type + * @param the cache value type + * @param the function operand type + */ +public class CacheComputeMutatorFactory implements MutatorFactory { + + private final Cache cache; + private final Function> functionFactory; + + public CacheComputeMutatorFactory(Cache cache, Function> functionFactory) { + this.cache = cache; + this.functionFactory = functionFactory; + } + + @Override + public Mutator createMutator(K key, O operand) { + return new CacheEntryComputeMutator<>(this.cache, key, this.functionFactory.apply(operand)); + } +} diff --git a/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryComputeMutator.java b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryComputeMutator.java new file mode 100644 index 000000000000..8a0297b6bf69 --- /dev/null +++ b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheEntryComputeMutator.java @@ -0,0 +1,37 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.ee.infinispan; + +import java.util.function.BiFunction; + +import org.infinispan.Cache; +import org.infinispan.context.Flag; +import org.wildfly.clustering.ee.Mutator; + +/** + * Mutator for a cache entry using a compute function. + * @author Paul Ferraro + * @param the cache key type + * @param the cache value type + */ +public class CacheEntryComputeMutator implements Mutator { + + private final Cache cache; + private final K key; + private final BiFunction function; + + public CacheEntryComputeMutator(Cache cache, K key, BiFunction function) { + this.cache = cache; + this.key = key; + this.function = function; + } + + @Override + public void mutate() { + // Use FAIL_SILENTLY to prevent mutation from failing locally due to remote exceptions + this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.FAIL_SILENTLY).compute(this.key, this.function); + } +} From a5eebe43d0b78d155e2ff2b2b61583b6c50849f8 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Mon, 14 Aug 2023 12:18:24 -0400 Subject: [PATCH 6/7] WFLY-18233 Optimize payload of ATTRIBUTE granularity mapping in distributed session manager using Infinispan's Cache.compute(...) --- .../SimpleImmutableSessionAttributes.java | 13 +- .../CoarseImmutableSessionAttributes.java | 32 ---- .../coarse/CoarseSessionAttributes.java | 3 +- .../fine/FineImmutableSessionAttributes.java | 36 ----- .../session/fine/FineSessionAttributes.java | 101 ++++-------- ...ibutesSerializationContextInitializer.java | 8 +- .../session/fine/SessionAttributeKey.java | 25 --- .../SessionAttributeMapComputeFunction.java | 20 +++ ...AttributeMapComputeFunctionMarshaller.java | 52 ++++++ .../fine/SessionAttributeMapEntry.java | 52 +++++- .../SessionAttributeMapEntryMarshaller.java | 60 +++---- ...ly.clustering.web.cache.session.fine.proto | 20 +++ ...eMapComputeFunctionMarshallerTestCase.java | 32 ++++ ...onAttributeMapEntryMarshallerTestCase.java | 29 ++++ ...sionManagerFactoryServiceConfigurator.java | 3 +- .../{coarse => }/SessionAttributesKey.java | 2 +- .../SessionManagerNearCacheFactory.java | 36 +---- ...essionSerializationContextInitializer.java | 1 + ...ributeSerializationContextInitializer.java | 24 --- .../CoarseSessionAttributesFactory.java | 5 +- .../fine/FineSessionAttributesFactory.java | 96 ++++------- .../session/fine/SessionAttributeKey.java | 49 ------ .../fine/SessionAttributeKeyMarshaller.java | 55 ------- .../fine/SessionAttributeNamesKey.java | 18 --- ...clustering.web.hotrod.session.coarse.proto | 10 -- ...y.clustering.web.hotrod.session.fine.proto | 19 --- ...ildfly.clustering.web.hotrod.session.proto | 7 + ...essionAttributesKeyMarshallerTestCase.java | 6 +- ...SessionAttributeKeyMarshallerTestCase.java | 25 --- ...onAttributeNamesKeyMarshallerTestCase.java | 24 --- .../{coarse => }/SessionAttributesKey.java | 2 +- .../SessionAttributesKeyFormatter.java | 2 +- ...essionSerializationContextInitializer.java | 1 + ...ributeSerializationContextInitializer.java | 24 --- .../CoarseSessionAttributesFactory.java | 5 +- .../fine/FineSessionAttributesFactory.java | 150 +++++++----------- ...ibutesSerializationContextInitializer.java | 25 --- .../session/fine/SessionAttributeKey.java | 49 ------ .../fine/SessionAttributeKeyFormatter.java | 35 ---- .../fine/SessionAttributeKeyMarshaller.java | 52 ------ .../fine/SessionAttributeNamesKey.java | 18 --- .../SessionAttributeNamesKeyFormatter.java | 21 --- ...tering.web.infinispan.session.coarse.proto | 10 -- ...ustering.web.infinispan.session.fine.proto | 19 --- ...ly.clustering.web.infinispan.session.proto | 7 + .../web/infinispan/KeyMapperTestCase.java | 8 +- .../SessionAttributesKeyTestCase.java | 3 +- .../fine/SessionAttributeKeyTestCase.java | 27 ---- .../SessionAttributeNamesKeyTestCase.java | 26 --- 49 files changed, 390 insertions(+), 957 deletions(-) delete mode 100644 clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseImmutableSessionAttributes.java delete mode 100644 clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineImmutableSessionAttributes.java rename clustering/web/{hotrod/src/main/java/org/wildfly/clustering/web/hotrod => cache/src/main/java/org/wildfly/clustering/web/cache}/session/fine/FineSessionAttributesSerializationContextInitializer.java (66%) delete mode 100644 clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeKey.java create mode 100644 clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunction.java create mode 100644 clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshaller.java create mode 100644 clustering/web/cache/src/main/resources/org.wildfly.clustering.web.cache.session.fine.proto create mode 100644 clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshallerTestCase.java create mode 100644 clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshallerTestCase.java rename clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/{coarse => }/SessionAttributesKey.java (85%) delete mode 100644 clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java delete mode 100644 clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKey.java delete mode 100644 clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshaller.java delete mode 100644 clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKey.java delete mode 100644 clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.coarse.proto delete mode 100644 clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.fine.proto rename clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/{coarse => }/SessionAttributesKeyMarshallerTestCase.java (75%) delete mode 100644 clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshallerTestCase.java delete mode 100644 clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKeyMarshallerTestCase.java rename clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/{coarse => }/SessionAttributesKey.java (84%) rename clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/{coarse => }/SessionAttributesKeyFormatter.java (90%) delete mode 100644 clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java delete mode 100644 clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesSerializationContextInitializer.java delete mode 100644 clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKey.java delete mode 100644 clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyFormatter.java delete mode 100644 clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyMarshaller.java delete mode 100644 clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKey.java delete mode 100644 clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyFormatter.java delete mode 100644 clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.coarse.proto delete mode 100644 clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.fine.proto rename clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/{coarse => }/SessionAttributesKeyTestCase.java (91%) delete mode 100644 clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyTestCase.java delete mode 100644 clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyTestCase.java diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleImmutableSessionAttributes.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleImmutableSessionAttributes.java index f7a621545b48..62464bf1a18d 100644 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleImmutableSessionAttributes.java +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleImmutableSessionAttributes.java @@ -5,9 +5,10 @@ package org.wildfly.clustering.web.cache.session; import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; import org.wildfly.clustering.web.session.ImmutableSessionAttributes; @@ -20,11 +21,11 @@ public class SimpleImmutableSessionAttributes implements ImmutableSessionAttribu private final Map attributes; public SimpleImmutableSessionAttributes(ImmutableSessionAttributes attributes) { - Map map = new HashMap<>(); - for (String name: attributes.getAttributeNames()) { - map.put(name, attributes.getAttribute(name)); - } - this.attributes = Collections.unmodifiableMap(map); + this(attributes.getAttributeNames().stream().collect(Collectors.toMap(Function.identity(), attributes::getAttribute))); + } + + public SimpleImmutableSessionAttributes(Map attributes) { + this.attributes = Collections.unmodifiableMap(attributes); } @Override diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseImmutableSessionAttributes.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseImmutableSessionAttributes.java deleted file mode 100644 index d5fcdbfe9828..000000000000 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseImmutableSessionAttributes.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.clustering.web.cache.session.coarse; - -import java.util.Map; -import java.util.Set; - -import org.wildfly.clustering.web.session.ImmutableSessionAttributes; - -/** - * Exposes session attributes for a coarse granularity session. - * @author Paul Ferraro - */ -public class CoarseImmutableSessionAttributes implements ImmutableSessionAttributes { - private final Map attributes; - - public CoarseImmutableSessionAttributes(Map attributes) { - this.attributes = attributes; - } - - @Override - public Set getAttributeNames() { - return this.attributes.keySet(); - } - - @Override - public Object getAttribute(String name) { - return this.attributes.get(name); - } -} diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseSessionAttributes.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseSessionAttributes.java index 7185f6b36372..e2e416d7a29d 100644 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseSessionAttributes.java +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseSessionAttributes.java @@ -14,12 +14,13 @@ import org.wildfly.clustering.marshalling.spi.Marshallability; import org.wildfly.clustering.web.cache.session.SessionActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributes; +import org.wildfly.clustering.web.cache.session.SimpleImmutableSessionAttributes; /** * Exposes session attributes for a coarse granularity session. * @author Paul Ferraro */ -public class CoarseSessionAttributes extends CoarseImmutableSessionAttributes implements SessionAttributes { +public class CoarseSessionAttributes extends SimpleImmutableSessionAttributes implements SessionAttributes { private final Map attributes; private final Mutator mutator; private final Marshallability marshallability; diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineImmutableSessionAttributes.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineImmutableSessionAttributes.java deleted file mode 100644 index 659c0bcb997a..000000000000 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineImmutableSessionAttributes.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.clustering.web.cache.session.fine; - -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import org.wildfly.clustering.web.session.ImmutableSessionAttributes; - -/** - * Exposes session attributes for fine granularity sessions. - * @author Paul Ferraro - */ -public class FineImmutableSessionAttributes implements ImmutableSessionAttributes { - private final Map names; - private final Map attributes; - - public FineImmutableSessionAttributes(Map names, Map attributes) { - this.names = names; - this.attributes = attributes; - } - - @Override - public Set getAttributeNames() { - return this.names.keySet(); - } - - @Override - public Object getAttribute(String name) { - UUID attributeId = this.names.get(name); - return (attributeId != null) ? this.attributes.get(attributeId) : null; - } -} diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributes.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributes.java index 70d11c589ae3..1af0159bda6c 100644 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributes.java +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributes.java @@ -2,52 +2,42 @@ * Copyright The WildFly Authors * SPDX-License-Identifier: Apache-2.0 */ + package org.wildfly.clustering.web.cache.session.fine; import java.io.IOException; import java.io.NotSerializableException; import java.util.Map; -import java.util.Set; import java.util.TreeMap; -import java.util.TreeSet; -import java.util.UUID; -import java.util.function.Function; import org.wildfly.clustering.ee.Immutability; -import org.wildfly.clustering.ee.UUIDFactory; +import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.cache.CacheProperties; -import org.wildfly.clustering.ee.cache.function.MapComputeFunction; import org.wildfly.clustering.marshalling.spi.Marshaller; import org.wildfly.clustering.web.cache.session.SessionAttributeActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributes; +import org.wildfly.clustering.web.cache.session.SimpleImmutableSessionAttributes; /** - * Exposes session attributes for fine granularity sessions. + * Exposes session attributes for a fine granularity sessions. * @author Paul Ferraro */ -public class FineSessionAttributes extends FineImmutableSessionAttributes implements SessionAttributes { - - private final Map> namesCache; - private final Map attributeCache; - private final NK namesKey; - private final Map names; - private final Map attributes; - private final Marshaller marshaller; - private final Function keyFactory; +public class FineSessionAttributes extends SimpleImmutableSessionAttributes implements SessionAttributes { + + private final K key; + private final Map attributes; + private final Marshaller marshaller; + private final MutatorFactory> mutatorFactory; private final Immutability immutability; private final CacheProperties properties; private final SessionAttributeActivationNotifier notifier; - private final Map nameUpdates = new TreeMap<>(); - private final Map updates = new TreeMap<>(); - - public FineSessionAttributes(Map> namesCache, NK namesKey, Map names, Map attributeCache, Function keyFactory, Map attributes, Marshaller marshaller, Immutability immutability, CacheProperties properties, SessionAttributeActivationNotifier notifier) { - super(names, attributes); - this.namesCache = namesCache; - this.namesKey = namesKey; - this.names = names; - this.attributeCache = attributeCache; - this.keyFactory = keyFactory; + private final Map updates = new TreeMap<>(); + + public FineSessionAttributes(K key, Map attributes, MutatorFactory> mutatorFactory, Marshaller marshaller, Immutability immutability, CacheProperties properties, SessionAttributeActivationNotifier notifier) { + super(attributes); + this.key = key; this.attributes = attributes; + this.mutatorFactory = mutatorFactory; this.marshaller = marshaller; this.immutability = immutability; this.properties = properties; @@ -62,14 +52,13 @@ public FineSessionAttributes(Map> namesCache, NK namesKey, @Override public Object getAttribute(String name) { - UUID id = this.names.get(name); - Object value = (id != null) ? this.attributes.get(id) : null; + Object value = this.attributes.get(name); if (value != null) { // If the object is mutable, we need to mutate this value on close if (!this.immutability.test(value)) { synchronized (this.updates) { - this.updates.put(id, value); + this.updates.put(name, value); } } } @@ -79,19 +68,11 @@ public Object getAttribute(String name) { @Override public Object removeAttribute(String name) { - UUID id = this.names.remove(name); - - if (id != null) { - synchronized (this.nameUpdates) { - this.nameUpdates.put(name, null); - } - } - - Object result = (id != null) ? this.attributes.remove(id) : null; + Object result = this.attributes.remove(name); if (result != null) { synchronized (this.updates) { - this.updates.put(id, null); + this.updates.put(name, null); } } @@ -108,21 +89,11 @@ public Object setAttribute(String name, Object value) { throw new IllegalArgumentException(new NotSerializableException(value.getClass().getName())); } - UUID id = UUIDFactory.INSECURE.get(); - UUID existing = this.names.putIfAbsent(name, id); - if (existing == null) { - synchronized (this.nameUpdates) { - this.nameUpdates.put(name, id); - } - } else { - id = existing; - } - - Object result = this.attributes.put(id, value); + Object result = this.attributes.put(name, value); if (value != result) { synchronized (this.updates) { - this.updates.put(id, value); + this.updates.put(name, value); } } @@ -136,35 +107,21 @@ public void close() { this.notifier.prePassivate(value); } } - Set removals = new TreeSet<>(); synchronized (this.updates) { if (!this.updates.isEmpty()) { - Map updates = new TreeMap<>(); - for (Map.Entry entry : this.updates.entrySet()) { - AK key = this.keyFactory.apply(entry.getKey()); + Map updates = new TreeMap<>(); + for (Map.Entry entry : this.updates.entrySet()) { + String name = entry.getKey(); Object value = entry.getValue(); - if (value != null) { - updates.put(key, this.write(value)); - } else { - removals.add(key); - } + updates.put(name, (value != null) ? this.write(value) : null); } - if (!updates.isEmpty()) { - this.attributeCache.putAll(updates); - } - } - } - synchronized (this.nameUpdates) { - if (!this.nameUpdates.isEmpty()) { - this.namesCache.compute(this.namesKey, new MapComputeFunction<>(this.nameUpdates)); + + this.mutatorFactory.createMutator(this.key, updates).mutate(); } } - for (AK key : removals) { - this.attributeCache.remove(key); - } } - private AV write(Object value) { + private V write(Object value) { try { return this.marshaller.write(value); } catch (IOException e) { diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/FineSessionAttributesSerializationContextInitializer.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributesSerializationContextInitializer.java similarity index 66% rename from clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/FineSessionAttributesSerializationContextInitializer.java rename to clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributesSerializationContextInitializer.java index d0682376645a..be126fbca38a 100644 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/FineSessionAttributesSerializationContextInitializer.java +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributesSerializationContextInitializer.java @@ -3,15 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.wildfly.clustering.web.hotrod.session.fine; +package org.wildfly.clustering.web.cache.session.fine; import org.infinispan.protostream.SerializationContext; import org.infinispan.protostream.SerializationContextInitializer; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; -import org.wildfly.clustering.web.cache.SessionKeyMarshaller; /** + * {@link SerializationContextInitializer} for this package. * @author Paul Ferraro */ @MetaInfServices(SerializationContextInitializer.class) @@ -19,7 +19,7 @@ public class FineSessionAttributesSerializationContextInitializer extends Abstra @Override public void registerMarshallers(SerializationContext context) { - context.registerMarshaller(new SessionKeyMarshaller<>(SessionAttributeNamesKey.class, SessionAttributeNamesKey::new)); - context.registerMarshaller(new SessionAttributeKeyMarshaller()); + context.registerMarshaller(new SessionAttributeMapComputeFunctionMarshaller<>()); + context.registerMarshaller(new SessionAttributeMapEntryMarshaller()); } } diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeKey.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeKey.java deleted file mode 100644 index 2aa7e547b10c..000000000000 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeKey.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.cache.session.fine; - -import java.util.UUID; - -import org.wildfly.clustering.ee.Key; - -/** - * A key for session attribute entries, identified via session identifier and attribute identifier. - * @author Paul Ferraro - */ -public interface SessionAttributeKey extends Key, Comparable { - - UUID getAttributeId(); - - @Override - default int compareTo(SessionAttributeKey key) { - int result = this.getId().compareTo(key.getId()); - return (result == 0) ? this.getAttributeId().compareTo(key.getAttributeId()) : result; - } -} diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunction.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunction.java new file mode 100644 index 000000000000..5d6dfe2d3603 --- /dev/null +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunction.java @@ -0,0 +1,20 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.web.cache.session.fine; + +import java.util.Map; + +import org.wildfly.clustering.ee.cache.function.MapComputeFunction; + +/** + * @author Paul Ferraro + */ +public class SessionAttributeMapComputeFunction extends MapComputeFunction { + + public SessionAttributeMapComputeFunction(Map operand) { + super(operand); + } +} diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshaller.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshaller.java new file mode 100644 index 000000000000..ea406689fc79 --- /dev/null +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshaller.java @@ -0,0 +1,52 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.web.cache.session.fine; + +import java.io.IOException; +import java.util.Map; +import java.util.TreeMap; + +import org.infinispan.protostream.descriptors.WireType; +import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; +import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; +import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; + +/** + * @author Paul Ferraro + */ +public class SessionAttributeMapComputeFunctionMarshaller implements ProtoStreamMarshaller> { + private static final int ENTRY_INDEX = 1; + + @SuppressWarnings("unchecked") + @Override + public Class> getJavaClass() { + return (Class>) (Class) SessionAttributeMapComputeFunction.class; + } + + @Override + public SessionAttributeMapComputeFunction readFrom(ProtoStreamReader reader) throws IOException { + Map map = new TreeMap<>(); + while (!reader.isAtEnd()) { + int tag = reader.readTag(); + switch (WireType.getTagFieldNumber(tag)) { + case ENTRY_INDEX: + Map.Entry entry = reader.readObject(SessionAttributeMapEntry.class); + map.put(entry.getKey(), entry.getValue()); + break; + default: + reader.skipField(tag); + } + } + return new SessionAttributeMapComputeFunction<>(map); + } + + @Override + public void writeTo(ProtoStreamWriter writer, SessionAttributeMapComputeFunction function) throws IOException { + for (Map.Entry entry : function.getOperand().entrySet()) { + writer.writeObject(ENTRY_INDEX, new SessionAttributeMapEntry<>(entry)); + } + } +} diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntry.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntry.java index 2eb1ac6762ac..e1a5400e70e1 100644 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntry.java +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntry.java @@ -5,18 +5,54 @@ package org.wildfly.clustering.web.cache.session.fine; -import java.util.AbstractMap.SimpleImmutableEntry; -import java.util.UUID; +import java.util.Map; /** - * {@link java.util.Map.Entry} for a session attribute. - * Used to optimize the marshalling of {@link java.util.Map#put(Object, Object)} functions. * @author Paul Ferraro */ -public class SessionAttributeMapEntry extends SimpleImmutableEntry { - private static final long serialVersionUID = -6446474741366055972L; +public class SessionAttributeMapEntry implements Map.Entry { - public SessionAttributeMapEntry(String key, UUID value) { - super(key, value); + private final String name; + private final V value; + + public SessionAttributeMapEntry(Map.Entry entry) { + this(entry.getKey(), entry.getValue()); + } + + public SessionAttributeMapEntry(String name, V value) { + this.name = name; + this.value = value; + } + + @Override + public String getKey() { + return this.name; + } + + @Override + public V getValue() { + return this.value; + } + + @Override + public V setValue(V value) { + throw new IllegalStateException(); + } + + @Override + public int hashCode() { + return this.name.hashCode(); + } + + @Override + public boolean equals(Object object) { + if (!(object instanceof Map.Entry)) return false; + Map.Entry entry = (Map.Entry) object; + return this.name.equals(entry.getKey()) && this.value.equals(entry.getValue()); + } + + @Override + public String toString() { + return Map.entry(this.name, this.value).toString(); } } diff --git a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshaller.java b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshaller.java index 6680b3491862..054238f91196 100644 --- a/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshaller.java +++ b/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshaller.java @@ -6,52 +6,56 @@ package org.wildfly.clustering.web.cache.session.fine; import java.io.IOException; -import java.util.Map; -import java.util.UUID; import org.infinispan.protostream.descriptors.WireType; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; -import org.wildfly.clustering.marshalling.protostream.util.UUIDBuilder; -import org.wildfly.clustering.marshalling.protostream.util.UUIDMarshaller; +import org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValue; /** - * {@link ProtoStreamMarshaller} for a session attribute map entry. * @author Paul Ferraro */ -public enum SessionAttributeMapEntryMarshaller implements ProtoStreamMarshaller> { - INSTANCE; +public class SessionAttributeMapEntryMarshaller implements ProtoStreamMarshaller>> { - private static final int ATTRIBUTE_NAME_INDEX = 1; - private static final int ATTRIBUTE_ID_INDEX = 2; + private static final int NAME_INDEX = 1; + private static final int VALUE_INDEX = 2; + @SuppressWarnings("unchecked") @Override - public Map.Entry readFrom(ProtoStreamReader reader) throws IOException { - String attributeName = null; - UUIDBuilder attributeIdBuilder = UUIDMarshaller.INSTANCE.getBuilder(); + public Class>> getJavaClass() { + return (Class>>) (Class) SessionAttributeMapEntry.class; + } + + @Override + public SessionAttributeMapEntry> readFrom(ProtoStreamReader reader) throws IOException { + String name = null; + ByteBufferMarshalledValue value = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); - int index = WireType.getTagFieldNumber(tag); - if (index == ATTRIBUTE_NAME_INDEX) { - attributeName = reader.readString(); - } else if (index >= ATTRIBUTE_ID_INDEX && index < ATTRIBUTE_ID_INDEX + UUIDMarshaller.INSTANCE.getFields()) { - attributeIdBuilder = UUIDMarshaller.INSTANCE.readField(reader, index - ATTRIBUTE_ID_INDEX, attributeIdBuilder); - } else { - reader.skipField(tag); + switch (WireType.getTagFieldNumber(tag)) { + case NAME_INDEX: + name = reader.readString(); + break; + case VALUE_INDEX: + value = reader.readObject(ByteBufferMarshalledValue.class); + break; + default: + reader.skipField(tag); } } - return new SessionAttributeMapEntry(attributeName, attributeIdBuilder.build()); - } - - @Override - public void writeTo(ProtoStreamWriter writer, Map.Entry entry) throws IOException { - writer.writeString(ATTRIBUTE_NAME_INDEX, entry.getKey()); - UUIDMarshaller.INSTANCE.writeFields(writer, ATTRIBUTE_ID_INDEX, entry.getValue()); + return new SessionAttributeMapEntry<>(name, value); } @Override - public Class getJavaClass() { - return SessionAttributeMapEntry.class; + public void writeTo(ProtoStreamWriter writer, SessionAttributeMapEntry> entry) throws IOException { + String name = entry.getKey(); + if (name != null) { + writer.writeString(NAME_INDEX, name); + } + ByteBufferMarshalledValue value = entry.getValue(); + if (value != null) { + writer.writeObject(VALUE_INDEX, value); + } } } diff --git a/clustering/web/cache/src/main/resources/org.wildfly.clustering.web.cache.session.fine.proto b/clustering/web/cache/src/main/resources/org.wildfly.clustering.web.cache.session.fine.proto new file mode 100644 index 000000000000..dbea0db6537c --- /dev/null +++ b/clustering/web/cache/src/main/resources/org.wildfly.clustering.web.cache.session.fine.proto @@ -0,0 +1,20 @@ +package org.wildfly.clustering.web.cache.session.fine; + +import "org.wildfly.clustering.marshalling.spi.proto"; + +// IDs: 225 - 229 + +/** + * @TypeId(225) + */ +message SessionAttributeMapEntry { + optional string name = 1; + optional org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValue value = 2; +} + +/** + * @TypeId(226) + */ +message SessionAttributeMapComputeFunction { + repeated SessionAttributeMapEntry entry = 1; +} diff --git a/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshallerTestCase.java b/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshallerTestCase.java new file mode 100644 index 000000000000..29b1708b0d90 --- /dev/null +++ b/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapComputeFunctionMarshallerTestCase.java @@ -0,0 +1,32 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.web.cache.session.fine; + +import java.io.IOException; +import java.util.Map; +import java.util.TreeMap; +import java.util.UUID; + +import org.junit.Test; +import org.wildfly.clustering.marshalling.MarshallingTester; +import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; +import org.wildfly.clustering.marshalling.protostream.TestProtoStreamByteBufferMarshaller; +import org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValue; + +/** + * @author Paul Ferraro + */ +public class SessionAttributeMapComputeFunctionMarshallerTestCase { + + @Test + public void test() throws IOException { + Map> map = new TreeMap<>(); + map.put("foo", new ByteBufferMarshalledValue<>(UUID.randomUUID(), TestProtoStreamByteBufferMarshaller.INSTANCE)); + map.put("bar", new ByteBufferMarshalledValue<>(UUID.randomUUID(), TestProtoStreamByteBufferMarshaller.INSTANCE)); + MarshallingTester>> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); + tester.test(new SessionAttributeMapComputeFunction<>(map)); + } +} diff --git a/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshallerTestCase.java b/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshallerTestCase.java new file mode 100644 index 000000000000..8e4f764b8431 --- /dev/null +++ b/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshallerTestCase.java @@ -0,0 +1,29 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.clustering.web.cache.session.fine; + +import java.io.IOException; +import java.util.UUID; + +import org.junit.Test; +import org.wildfly.clustering.marshalling.MarshallingTester; +import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; +import org.wildfly.clustering.marshalling.protostream.TestProtoStreamByteBufferMarshaller; +import org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValue; + +/** + * Validates marshalling of {@link SessionAttributeMapEntry}. + * @author Paul Ferraro + */ +public class SessionAttributeMapEntryMarshallerTestCase { + + @Test + public void test() throws IOException { + ByteBufferMarshalledValue value = new ByteBufferMarshalledValue<>(UUID.randomUUID(), TestProtoStreamByteBufferMarshaller.INSTANCE); + MarshallingTester>> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); + tester.test(new SessionAttributeMapEntry<>("foo", value)); + } +} diff --git a/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/session/hotrod/HotRodSessionManagerFactoryServiceConfigurator.java b/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/session/hotrod/HotRodSessionManagerFactoryServiceConfigurator.java index c20c76c576f2..6934a824aa3d 100644 --- a/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/session/hotrod/HotRodSessionManagerFactoryServiceConfigurator.java +++ b/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/session/hotrod/HotRodSessionManagerFactoryServiceConfigurator.java @@ -72,13 +72,12 @@ public ServiceConfigurator configure(CapabilityServiceSupport support) { NearCacheMode mode = (maxActiveSessions != null) && (maxActiveSessions > 0) ? NearCacheMode.INVALIDATED : NearCacheMode.DISABLED; String configurationName = this.configuration.getConfigurationName(); String templateName = (configurationName != null) ? configurationName : DefaultTemplate.DIST_SYNC.getTemplateName(); - SessionAttributePersistenceStrategy strategy = this.getAttributePersistenceStrategy(); this.cacheConfigurator = new RemoteCacheServiceConfigurator<>(this.getServiceName().append("cache"), this.configuration.getContainerName(), this.getDeploymentName(), new Consumer() { @Override public void accept(RemoteCacheConfigurationBuilder builder) { builder.forceReturnValues(false).nearCacheMode(mode).templateName(templateName).transactionMode(TransactionMode.NONE); if (mode.invalidated()) { - builder.nearCacheFactory(new SessionManagerNearCacheFactory(maxActiveSessions, strategy)); + builder.nearCacheFactory(new SessionManagerNearCacheFactory(maxActiveSessions)); } } }).configure(support); diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/SessionAttributesKey.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionAttributesKey.java similarity index 85% rename from clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/SessionAttributesKey.java rename to clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionAttributesKey.java index def8a88f22fe..0138949c6be7 100644 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/SessionAttributesKey.java +++ b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionAttributesKey.java @@ -2,7 +2,7 @@ * Copyright The WildFly Authors * SPDX-License-Identifier: Apache-2.0 */ -package org.wildfly.clustering.web.hotrod.session.coarse; +package org.wildfly.clustering.web.hotrod.session; import org.wildfly.clustering.ee.hotrod.RemoteCacheKey; diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionManagerNearCacheFactory.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionManagerNearCacheFactory.java index 68aff693eaf6..8051855dc90f 100644 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionManagerNearCacheFactory.java +++ b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionManagerNearCacheFactory.java @@ -8,7 +8,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.function.BiConsumer; import org.infinispan.client.hotrod.MetadataValue; @@ -18,10 +17,6 @@ import org.wildfly.clustering.infinispan.client.near.CaffeineNearCache; import org.wildfly.clustering.infinispan.client.near.EvictionListener; import org.wildfly.clustering.infinispan.client.near.SimpleKeyWeigher; -import org.wildfly.clustering.web.hotrod.session.coarse.SessionAttributesKey; -import org.wildfly.clustering.web.hotrod.session.fine.SessionAttributeKey; -import org.wildfly.clustering.web.hotrod.session.fine.SessionAttributeNamesKey; -import org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; @@ -33,16 +28,14 @@ public class SessionManagerNearCacheFactory implements NearCacheFactory { private final Integer maxActiveSessions; - private final SessionAttributePersistenceStrategy strategy; - public SessionManagerNearCacheFactory(Integer maxActiveSessions, SessionAttributePersistenceStrategy strategy) { + public SessionManagerNearCacheFactory(Integer maxActiveSessions) { this.maxActiveSessions = maxActiveSessions; - this.strategy = strategy; } @Override public NearCache createNearCache(NearCacheConfiguration config, BiConsumer> removedConsumer) { - EvictionListener listener = (this.maxActiveSessions != null) ? new EvictionListener<>(removedConsumer, new InvalidationListener(this.strategy)) : null; + EvictionListener listener = (this.maxActiveSessions != null) ? new EvictionListener<>(removedConsumer, new InvalidationListener()) : null; Caffeine builder = Caffeine.newBuilder(); if (listener != null) { builder.executor(Runnable::run) @@ -58,11 +51,6 @@ public NearCache createNearCache(NearCacheConfiguration config, BiC } private static class InvalidationListener implements BiConsumer>, Map.Entry> { - private final SessionAttributePersistenceStrategy strategy; - - InvalidationListener(SessionAttributePersistenceStrategy strategy) { - this.strategy = strategy; - } @Override public void accept(Cache> cache, Map.Entry entry) { @@ -71,25 +59,7 @@ public void accept(Cache> cache, Map.Entry keys = new LinkedList<>(); keys.add(new SessionAccessMetaDataKey(id)); - switch (this.strategy) { - case COARSE: { - keys.add(new SessionAttributesKey(id)); - break; - } - case FINE: { - SessionAttributeNamesKey namesKey = new SessionAttributeNamesKey(id); - keys.add(namesKey); - MetadataValue namesValue = cache.getIfPresent(namesKey); - if (namesValue != null) { - @SuppressWarnings("unchecked") - Map names = (Map) namesValue.getValue(); - for (UUID attributeId : names.values()) { - keys.add(new SessionAttributeKey(id, attributeId)); - } - } - break; - } - } + keys.add(new SessionAttributesKey(id)); cache.invalidateAll(keys); } } diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionSerializationContextInitializer.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionSerializationContextInitializer.java index abdbfd87577a..264a92c5715f 100644 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionSerializationContextInitializer.java +++ b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/SessionSerializationContextInitializer.java @@ -21,5 +21,6 @@ public class SessionSerializationContextInitializer extends AbstractSerializatio public void registerMarshallers(SerializationContext context) { context.registerMarshaller(new SessionKeyMarshaller<>(SessionCreationMetaDataKey.class, SessionCreationMetaDataKey::new)); context.registerMarshaller(new SessionKeyMarshaller<>(SessionAccessMetaDataKey.class, SessionAccessMetaDataKey::new)); + context.registerMarshaller(new SessionKeyMarshaller<>(SessionAttributesKey.class, SessionAttributesKey::new)); } } diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java deleted file mode 100644 index e92aa2f410cf..000000000000 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.hotrod.session.coarse; - -import org.infinispan.protostream.SerializationContext; -import org.infinispan.protostream.SerializationContextInitializer; -import org.kohsuke.MetaInfServices; -import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; -import org.wildfly.clustering.web.cache.SessionKeyMarshaller; - -/** - * @author Paul Ferraro - */ -@MetaInfServices(SerializationContextInitializer.class) -public class CoarseSessionAttributeSerializationContextInitializer extends AbstractSerializationContextInitializer { - - @Override - public void registerMarshallers(SerializationContext context) { - context.registerMarshaller(new SessionKeyMarshaller<>(SessionAttributesKey.class, SessionAttributesKey::new)); - } -} diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributesFactory.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributesFactory.java index 71d33d206a83..386394d5cb3a 100644 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributesFactory.java +++ b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/coarse/CoarseSessionAttributesFactory.java @@ -21,10 +21,11 @@ import org.wildfly.clustering.web.cache.session.SessionActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributes; import org.wildfly.clustering.web.cache.session.SessionAttributesFactory; -import org.wildfly.clustering.web.cache.session.coarse.CoarseImmutableSessionAttributes; +import org.wildfly.clustering.web.cache.session.SimpleImmutableSessionAttributes; import org.wildfly.clustering.web.cache.session.coarse.CoarseSessionAttributes; import org.wildfly.clustering.web.hotrod.logging.Logger; import org.wildfly.clustering.web.hotrod.session.HotRodSessionAttributesFactoryConfiguration; +import org.wildfly.clustering.web.hotrod.session.SessionAttributesKey; import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider; import org.wildfly.clustering.web.session.ImmutableSessionAttributes; import org.wildfly.clustering.web.session.ImmutableSessionMetaData; @@ -89,7 +90,7 @@ public SessionAttributes createSessionAttributes(String id, Map @Override public ImmutableSessionAttributes createImmutableSessionAttributes(String id, Map values) { - return new CoarseImmutableSessionAttributes(values); + return new SimpleImmutableSessionAttributes(values); } @Override diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/FineSessionAttributesFactory.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/FineSessionAttributesFactory.java index 08160088ff9c..2255613c5dfd 100644 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/FineSessionAttributesFactory.java +++ b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/FineSessionAttributesFactory.java @@ -6,27 +6,26 @@ package org.wildfly.clustering.web.hotrod.session.fine; import java.io.IOException; -import java.util.AbstractMap; -import java.util.HashMap; import java.util.Map; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; -import org.infinispan.client.hotrod.Flag; import org.infinispan.client.hotrod.RemoteCache; import org.wildfly.clustering.ee.Immutability; +import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.cache.CacheProperties; +import org.wildfly.clustering.ee.hotrod.RemoteCacheComputeMutatorFactory; import org.wildfly.clustering.marshalling.spi.Marshaller; import org.wildfly.clustering.web.cache.session.CompositeImmutableSession; import org.wildfly.clustering.web.cache.session.ImmutableSessionAttributeActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributeActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributes; import org.wildfly.clustering.web.cache.session.SessionAttributesFactory; -import org.wildfly.clustering.web.cache.session.fine.FineImmutableSessionAttributes; +import org.wildfly.clustering.web.cache.session.SimpleImmutableSessionAttributes; import org.wildfly.clustering.web.cache.session.fine.FineSessionAttributes; +import org.wildfly.clustering.web.cache.session.fine.SessionAttributeMapComputeFunction; import org.wildfly.clustering.web.hotrod.logging.Logger; import org.wildfly.clustering.web.hotrod.session.HotRodSessionAttributesFactoryConfiguration; +import org.wildfly.clustering.web.hotrod.session.SessionAttributesKey; import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider; import org.wildfly.clustering.web.session.ImmutableSessionAttributes; import org.wildfly.clustering.web.session.ImmutableSessionMetaData; @@ -37,102 +36,73 @@ * A separate cache entry stores the activate attribute names for the session. * @author Paul Ferraro */ -public class FineSessionAttributesFactory implements SessionAttributesFactory, Map>> { +public class FineSessionAttributesFactory implements SessionAttributesFactory> { - private final RemoteCache> namesCache; - private final RemoteCache attributeCache; + private final RemoteCache> cache; private final Marshaller marshaller; private final Immutability immutability; private final CacheProperties properties; + private final MutatorFactory> mutatorFactory; private final HttpSessionActivationListenerProvider provider; public FineSessionAttributesFactory(HotRodSessionAttributesFactoryConfiguration configuration) { - this.namesCache = configuration.getCache(); - this.attributeCache = configuration.getCache(); + this.cache = configuration.getCache(); this.marshaller = configuration.getMarshaller(); this.immutability = configuration.getImmutability(); this.properties = configuration.getCacheProperties(); + this.mutatorFactory = new RemoteCacheComputeMutatorFactory<>(this.cache, SessionAttributeMapComputeFunction::new); this.provider = configuration.getHttpSessionActivationListenerProvider(); } @Override - public Map.Entry, Map> createValue(String id, Void context) { - return new AbstractMap.SimpleImmutableEntry<>(new ConcurrentHashMap<>(), new ConcurrentHashMap<>()); + public Map createValue(String id, Void context) { + return new ConcurrentHashMap<>(); } @Override - public Map.Entry, Map> findValue(String id) { + public Map findValue(String id) { return this.getValue(id, true); } @Override - public Map.Entry, Map> tryValue(String id) { + public Map tryValue(String id) { return this.getValue(id, false); } - private Map.Entry, Map> getValue(String id, boolean purgeIfInvalid) { - Map names = this.namesCache.get(new SessionAttributeNamesKey(id)); - if (names == null) { - return this.createValue(id, null); - } - // Read attribute entries via bulk read - Map keys = new HashMap<>(); - for (Map.Entry entry : names.entrySet()) { - keys.put(new SessionAttributeKey(id, entry.getValue()), entry.getKey()); - } - Map values = this.attributeCache.getAll(keys.keySet()); - // Validate attributes - Map attributes = new ConcurrentHashMap<>(); - for (Map.Entry entry : keys.entrySet()) { - SessionAttributeKey key = entry.getKey(); - V value = values.get(entry.getKey()); - if (value != null) { + private Map getValue(String id, boolean purgeIfInvalid) { + Map attributes = this.createValue(id, null); + Map value = this.cache.get(new SessionAttributesKey(id)); + if (value != null) { + for (Map.Entry entry : value.entrySet()) { + String attributeName = entry.getKey(); try { - attributes.put(key.getAttributeId(), this.marshaller.read(value)); - continue; + attributes.put(attributeName, this.marshaller.read(entry.getValue())); } catch (IOException e) { - Logger.ROOT_LOGGER.failedToActivateSessionAttribute(e, id, entry.getValue()); + Logger.ROOT_LOGGER.failedToActivateSessionAttribute(e, id, attributeName); + if (purgeIfInvalid) { + this.purge(id); + } + return null; } - } else { - Logger.ROOT_LOGGER.missingSessionAttributeCacheEntry(id, entry.getValue()); } - if (purgeIfInvalid) { - this.purge(id); - } - return null; } - return new AbstractMap.SimpleImmutableEntry<>(new ConcurrentHashMap<>(names), attributes); + return attributes; } @Override public boolean remove(String id) { - SessionAttributeNamesKey key = new SessionAttributeNamesKey(id); - Map names = this.namesCache.withFlags(Flag.FORCE_RETURN_VALUE).remove(key); - if (names != null) { - for (UUID attributeId : names.values()) { - this.attributeCache.remove(new SessionAttributeKey(id, attributeId)); - } - } + this.cache.remove(new SessionAttributesKey(id)); return true; } @Override - public SessionAttributes createSessionAttributes(String id, Map.Entry, Map> entry, ImmutableSessionMetaData metaData, C context) { - SessionAttributeActivationNotifier notifier = new ImmutableSessionAttributeActivationNotifier<>(this.provider, new CompositeImmutableSession(id, metaData, this.createImmutableSessionAttributes(id, entry)), context); - return new FineSessionAttributes<>(this.namesCache, new SessionAttributeNamesKey(id), entry.getKey(), this.attributeCache, getKeyFactory(id), entry.getValue(), this.marshaller, this.immutability, this.properties, notifier); + public SessionAttributes createSessionAttributes(String id, Map attributes, ImmutableSessionMetaData metaData, C context) { + SessionAttributeActivationNotifier notifier = this.properties.isPersistent() ? new ImmutableSessionAttributeActivationNotifier<>(this.provider, new CompositeImmutableSession(id, metaData, this.createImmutableSessionAttributes(id, attributes)), context) : null; + return new FineSessionAttributes<>(new SessionAttributesKey(id), attributes, this.mutatorFactory, this.marshaller, this.immutability, this.properties, notifier); } @Override - public ImmutableSessionAttributes createImmutableSessionAttributes(String id, Map.Entry, Map> entry) { - return new FineImmutableSessionAttributes(entry.getKey(), entry.getValue()); - } - - private static Function getKeyFactory(String id) { - return new Function<>() { - @Override - public SessionAttributeKey apply(UUID attributeId) { - return new SessionAttributeKey(id, attributeId); - } - }; + public ImmutableSessionAttributes createImmutableSessionAttributes(String id, Map attributes) { + return new SimpleImmutableSessionAttributes(attributes); } } diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKey.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKey.java deleted file mode 100644 index 3cd9954d386f..000000000000 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKey.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.clustering.web.hotrod.session.fine; - -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - -import org.wildfly.clustering.ee.hotrod.RemoteCacheKey; - -/** - * Cache key for session attributes. - * @author Paul Ferraro - */ -public class SessionAttributeKey extends RemoteCacheKey implements org.wildfly.clustering.web.cache.session.fine.SessionAttributeKey { - - private final UUID attributeId; - - public SessionAttributeKey(Map.Entry entry) { - this(entry.getKey(), entry.getValue()); - } - - public SessionAttributeKey(String id, UUID attributeId) { - super(id); - this.attributeId = attributeId; - } - - @Override - public UUID getAttributeId() { - return this.attributeId; - } - - @Override - public int hashCode() { - return Objects.hash(this.getClass(), this.getId(), this.attributeId); - } - - @Override - public boolean equals(Object object) { - return super.equals(object) && (object instanceof SessionAttributeKey) && this.attributeId.equals(((SessionAttributeKey) object).attributeId); - } - - @Override - public String toString() { - return String.format("%s(%s[%s])", SessionAttributeKey.class.getSimpleName(), this.getId(), this.attributeId); - } -} diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshaller.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshaller.java deleted file mode 100644 index e9420e9fc356..000000000000 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshaller.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.hotrod.session.fine; - -import java.io.IOException; - -import org.infinispan.protostream.descriptors.WireType; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; -import org.wildfly.clustering.marshalling.protostream.util.UUIDBuilder; -import org.wildfly.clustering.marshalling.protostream.util.UUIDMarshaller; -import org.wildfly.clustering.web.cache.SessionIdentifierMarshaller; - -/** - * @author Paul Ferraro - */ -public class SessionAttributeKeyMarshaller implements ProtoStreamMarshaller { - - private static final int SESSION_IDENTIFIER_INDEX = 1; - private static final int ATTRIBUTE_IDENTIFIER_INDEX = 2; - - @Override - public SessionAttributeKey readFrom(ProtoStreamReader reader) throws IOException { - String sessionId = null; - UUIDBuilder attributeId = UUIDMarshaller.INSTANCE.getBuilder(); - while (!reader.isAtEnd()) { - int tag = reader.readTag(); - int index = WireType.getTagFieldNumber(tag); - if (index == SESSION_IDENTIFIER_INDEX) { - sessionId = SessionIdentifierMarshaller.INSTANCE.readFrom(reader); - } else if (index >= ATTRIBUTE_IDENTIFIER_INDEX && index < ATTRIBUTE_IDENTIFIER_INDEX + UUIDMarshaller.INSTANCE.getFields()) { - attributeId = UUIDMarshaller.INSTANCE.readField(reader, index - ATTRIBUTE_IDENTIFIER_INDEX, attributeId); - } else { - reader.skipField(tag); - } - } - return new SessionAttributeKey(sessionId, attributeId.build()); - } - - @Override - public void writeTo(ProtoStreamWriter writer, SessionAttributeKey key) throws IOException { - writer.writeTag(SESSION_IDENTIFIER_INDEX, SessionIdentifierMarshaller.INSTANCE.getWireType()); - SessionIdentifierMarshaller.INSTANCE.writeTo(writer, key.getId()); - UUIDMarshaller.INSTANCE.writeFields(writer, ATTRIBUTE_IDENTIFIER_INDEX, key.getAttributeId()); - } - - @Override - public Class getJavaClass() { - return SessionAttributeKey.class; - } -} \ No newline at end of file diff --git a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKey.java b/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKey.java deleted file mode 100644 index daef6c117fe8..000000000000 --- a/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKey.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.clustering.web.hotrod.session.fine; - -import org.wildfly.clustering.ee.hotrod.RemoteCacheKey; - -/** - * Cache key for session attribute names. - * @author Paul Ferraro - */ -public class SessionAttributeNamesKey extends RemoteCacheKey { - - public SessionAttributeNamesKey(String id) { - super(id); - } -} diff --git a/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.coarse.proto b/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.coarse.proto deleted file mode 100644 index 41e348a4531d..000000000000 --- a/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.coarse.proto +++ /dev/null @@ -1,10 +0,0 @@ -package org.wildfly.clustering.web.hotrod.session.coarse; - -// IDs: 210 - 214 - -/** - * @TypeId(210) - */ -message SessionAttributesKey { - required bytes id = 1; -} diff --git a/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.fine.proto b/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.fine.proto deleted file mode 100644 index 8dfb6bedfa53..000000000000 --- a/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.fine.proto +++ /dev/null @@ -1,19 +0,0 @@ -package org.wildfly.clustering.web.hotrod.session.fine; - -// IDs: 220 - 224 - -/** - * @TypeId(220) - */ -message SessionAttributeNamesKey { - required bytes id = 1; -} - -/** - * @TypeId(221) - */ -message SessionAttributeKey { - required bytes id = 1; - optional sfixed64 mostSigBits = 2; - optional sfixed64 leastSigBits = 3; -} diff --git a/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.proto b/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.proto index 494cc6d6d672..005355e727df 100644 --- a/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.proto +++ b/clustering/web/hotrod/src/main/resources/org.wildfly.clustering.web.hotrod.session.proto @@ -15,3 +15,10 @@ message SessionCreationMetaDataKey { message SessionAccessMetaDataKey { required bytes id = 1; } + +/** + * @TypeId(202) + */ +message SessionAttributesKey { + required bytes id = 1; +} diff --git a/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/coarse/SessionAttributesKeyMarshallerTestCase.java b/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/SessionAttributesKeyMarshallerTestCase.java similarity index 75% rename from clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/coarse/SessionAttributesKeyMarshallerTestCase.java rename to clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/SessionAttributesKeyMarshallerTestCase.java index 89d860127824..a26e9a5f3bb5 100644 --- a/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/coarse/SessionAttributesKeyMarshallerTestCase.java +++ b/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/SessionAttributesKeyMarshallerTestCase.java @@ -3,17 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.wildfly.clustering.web.hotrod.session.coarse; +package org.wildfly.clustering.web.hotrod.session; import java.io.IOException; import org.junit.Test; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; -/** - * Unit test for {@link SessionAttributesKeyExternalizer}. - * @author Paul Ferraro - */ public class SessionAttributesKeyMarshallerTestCase { @Test diff --git a/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshallerTestCase.java b/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshallerTestCase.java deleted file mode 100644 index b5e728bb791e..000000000000 --- a/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshallerTestCase.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.hotrod.session.fine; - -import java.io.IOException; -import java.util.UUID; - -import org.junit.Test; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; - -/** - * Unit test for {@link SessionAttributeKeyResolver}. - * @author Paul Ferraro - */ -public class SessionAttributeKeyMarshallerTestCase { - - @Test - public void test() throws IOException { - SessionAttributeKey key = new SessionAttributeKey("test", UUID.randomUUID()); - ProtoStreamTesterFactory.INSTANCE.createTester().test(key); - } -} diff --git a/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKeyMarshallerTestCase.java b/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKeyMarshallerTestCase.java deleted file mode 100644 index c31e029ddb36..000000000000 --- a/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKeyMarshallerTestCase.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.hotrod.session.fine; - -import java.io.IOException; - -import org.junit.Test; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; - -/** - * Unit test for {@link SessionAttributeNamesKeyResolver}. - * @author Paul Ferraro - */ -public class SessionAttributeNamesKeyMarshallerTestCase { - - @Test - public void test() throws IOException { - SessionAttributeNamesKey key = new SessionAttributeNamesKey("test"); - ProtoStreamTesterFactory.INSTANCE.createTester().test(key); - } -} diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKey.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKey.java similarity index 84% rename from clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKey.java rename to clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKey.java index a2ec6187a766..483b8c3c4b57 100644 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKey.java +++ b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKey.java @@ -2,7 +2,7 @@ * Copyright The WildFly Authors * SPDX-License-Identifier: Apache-2.0 */ -package org.wildfly.clustering.web.infinispan.session.coarse; +package org.wildfly.clustering.web.infinispan.session; import org.wildfly.clustering.ee.infinispan.GroupedKey; diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKeyFormatter.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKeyFormatter.java similarity index 90% rename from clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKeyFormatter.java rename to clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKeyFormatter.java index eb28f8aca0b0..8c4e3c368844 100644 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKeyFormatter.java +++ b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKeyFormatter.java @@ -2,7 +2,7 @@ * Copyright The WildFly Authors * SPDX-License-Identifier: Apache-2.0 */ -package org.wildfly.clustering.web.infinispan.session.coarse; +package org.wildfly.clustering.web.infinispan.session; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.marshalling.spi.Formatter; diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionSerializationContextInitializer.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionSerializationContextInitializer.java index d49ceeec64eb..8248aa2cafca 100644 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionSerializationContextInitializer.java +++ b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/SessionSerializationContextInitializer.java @@ -22,6 +22,7 @@ public class SessionSerializationContextInitializer extends AbstractSerializatio public void registerMarshallers(SerializationContext context) { context.registerMarshaller(new SessionKeyMarshaller<>(SessionCreationMetaDataKey.class, SessionCreationMetaDataKey::new)); context.registerMarshaller(new SessionKeyMarshaller<>(SessionAccessMetaDataKey.class, SessionAccessMetaDataKey::new)); + context.registerMarshaller(new SessionKeyMarshaller<>(SessionAttributesKey.class, SessionAttributesKey::new)); context.registerMarshaller(new EnumMarshaller<>(SessionCreationMetaDataKeyFilter.class)); } } diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java deleted file mode 100644 index ee7bc7cb00b1..000000000000 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributeSerializationContextInitializer.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.infinispan.session.coarse; - -import org.infinispan.protostream.SerializationContext; -import org.infinispan.protostream.SerializationContextInitializer; -import org.kohsuke.MetaInfServices; -import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; -import org.wildfly.clustering.web.cache.SessionKeyMarshaller; - -/** - * @author Paul Ferraro - */ -@MetaInfServices(SerializationContextInitializer.class) -public class CoarseSessionAttributeSerializationContextInitializer extends AbstractSerializationContextInitializer { - - @Override - public void registerMarshallers(SerializationContext context) { - context.registerMarshaller(new SessionKeyMarshaller<>(SessionAttributesKey.class, SessionAttributesKey::new)); - } -} diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java index 66fe9d6a8e97..a94933b888a0 100644 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java +++ b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java @@ -28,10 +28,11 @@ import org.wildfly.clustering.web.cache.session.SessionAttributeActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributes; import org.wildfly.clustering.web.cache.session.SessionAttributesFactory; -import org.wildfly.clustering.web.cache.session.coarse.CoarseImmutableSessionAttributes; +import org.wildfly.clustering.web.cache.session.SimpleImmutableSessionAttributes; import org.wildfly.clustering.web.cache.session.coarse.CoarseSessionAttributes; import org.wildfly.clustering.web.infinispan.logging.InfinispanWebLogger; import org.wildfly.clustering.web.infinispan.session.InfinispanSessionAttributesFactoryConfiguration; +import org.wildfly.clustering.web.infinispan.session.SessionAttributesKey; import org.wildfly.clustering.web.infinispan.session.SessionCreationMetaDataKey; import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider; import org.wildfly.clustering.web.session.ImmutableSessionAttributes; @@ -147,7 +148,7 @@ public SessionAttributes createSessionAttributes(String id, Map @Override public ImmutableSessionAttributes createImmutableSessionAttributes(String id, Map values) { - return new CoarseImmutableSessionAttributes(values); + return new SimpleImmutableSessionAttributes(values); } private void cascadeEvict(SessionCreationMetaDataKey key) { diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesFactory.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesFactory.java index 291e89cca5f0..75d29608bc10 100644 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesFactory.java +++ b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesFactory.java @@ -6,33 +6,32 @@ package org.wildfly.clustering.web.infinispan.session.fine; import java.io.IOException; -import java.util.AbstractMap; import java.util.Map; -import java.util.TreeMap; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executor; import java.util.function.BiConsumer; import java.util.function.Function; import org.infinispan.Cache; import org.wildfly.clustering.ee.Immutability; +import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.cache.CacheProperties; +import org.wildfly.clustering.ee.infinispan.CacheComputeMutatorFactory; import org.wildfly.clustering.infinispan.listener.ListenerRegistration; import org.wildfly.clustering.infinispan.listener.PostActivateBlockingListener; import org.wildfly.clustering.infinispan.listener.PostPassivateBlockingListener; import org.wildfly.clustering.infinispan.listener.PrePassivateBlockingListener; -import org.wildfly.clustering.infinispan.listener.PrePassivateNonBlockingListener; import org.wildfly.clustering.marshalling.spi.Marshaller; import org.wildfly.clustering.web.cache.session.CompositeImmutableSession; import org.wildfly.clustering.web.cache.session.ImmutableSessionAttributeActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributeActivationNotifier; import org.wildfly.clustering.web.cache.session.SessionAttributes; import org.wildfly.clustering.web.cache.session.SessionAttributesFactory; -import org.wildfly.clustering.web.cache.session.fine.FineImmutableSessionAttributes; +import org.wildfly.clustering.web.cache.session.SimpleImmutableSessionAttributes; import org.wildfly.clustering.web.cache.session.fine.FineSessionAttributes; +import org.wildfly.clustering.web.cache.session.fine.SessionAttributeMapComputeFunction; import org.wildfly.clustering.web.infinispan.logging.InfinispanWebLogger; import org.wildfly.clustering.web.infinispan.session.InfinispanSessionAttributesFactoryConfiguration; +import org.wildfly.clustering.web.infinispan.session.SessionAttributesKey; import org.wildfly.clustering.web.infinispan.session.SessionCreationMetaDataKey; import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider; import org.wildfly.clustering.web.session.ImmutableSessionAttributes; @@ -44,46 +43,39 @@ * A separate cache entry stores the activate attribute names for the session. * @author Paul Ferraro */ -public class FineSessionAttributesFactory implements SessionAttributesFactory, Map>> { +public class FineSessionAttributesFactory implements SessionAttributesFactory> { - private final Cache> namesCache; - private final Cache> writeOnlyNamesCache; - private final Cache attributeCache; - private final Cache writeOnlyAttributeCache; - private final Cache silentAttributeCache; + private final Cache> cache; + private final Cache> writeCache; + private final Cache> silentCache; private final Marshaller marshaller; private final Immutability immutability; private final CacheProperties properties; + private final MutatorFactory> mutatorFactory; private final HttpSessionActivationListenerProvider provider; private final Function notifierFactory; - private final Executor executor; private final ListenerRegistration evictListenerRegistration; - private final ListenerRegistration evictAttributesListenerRegistration; private final ListenerRegistration prePassivateListenerRegistration; private final ListenerRegistration postActivateListenerRegistration; public FineSessionAttributesFactory(InfinispanSessionAttributesFactoryConfiguration configuration) { - this.namesCache = configuration.getCache(); - this.writeOnlyNamesCache = configuration.getWriteOnlyCache(); - this.attributeCache = configuration.getCache(); - this.writeOnlyAttributeCache = configuration.getWriteOnlyCache(); - this.silentAttributeCache = configuration.getSilentWriteCache(); + this.cache = configuration.getCache(); + this.writeCache = configuration.getWriteOnlyCache(); + this.silentCache = configuration.getSilentWriteCache(); this.marshaller = configuration.getMarshaller(); this.immutability = configuration.getImmutability(); this.properties = configuration.getCacheProperties(); + this.mutatorFactory = new CacheComputeMutatorFactory<>(this.cache, SessionAttributeMapComputeFunction::new); this.provider = configuration.getHttpSessionActivationListenerProvider(); this.notifierFactory = configuration.getActivationNotifierFactory(); - this.executor = configuration.getBlockingManager().asExecutor(this.getClass().getName()); + this.prePassivateListenerRegistration = !this.properties.isPersistent() ? new PrePassivateBlockingListener<>(this.cache, this::prePassivate).register(SessionAttributesKey.class) : null; + this.postActivateListenerRegistration = !this.properties.isPersistent() ? new PostActivateBlockingListener<>(this.cache, this::postActivate).register(SessionAttributesKey.class) : null; this.evictListenerRegistration = new PostPassivateBlockingListener<>(configuration.getCache(), this::cascadeEvict).register(SessionCreationMetaDataKey.class); - this.evictAttributesListenerRegistration = new PrePassivateNonBlockingListener<>(this.namesCache, this::cascadeEvictAttributes).register(SessionAttributeNamesKey.class); - this.prePassivateListenerRegistration = !this.properties.isPersistent() ? new PrePassivateBlockingListener<>(this.attributeCache, this::prePassivate).register(SessionAttributeKey.class) : null; - this.postActivateListenerRegistration = !this.properties.isPersistent() ? new PostActivateBlockingListener<>(this.attributeCache, this::postActivate).register(SessionAttributeKey.class) : null; } @Override public void close() { this.evictListenerRegistration.close(); - this.evictAttributesListenerRegistration.close(); if (this.prePassivateListenerRegistration != null) { this.prePassivateListenerRegistration.close(); } @@ -93,120 +85,86 @@ public void close() { } @Override - public Map.Entry, Map> createValue(String id, Void context) { - return new AbstractMap.SimpleImmutableEntry<>(new ConcurrentHashMap<>(), new ConcurrentHashMap<>()); + public Map createValue(String id, Void context) { + return new ConcurrentHashMap<>(); } @Override - public Map.Entry, Map> findValue(String id) { + public Map findValue(String id) { return this.getValue(id, true); } @Override - public Map.Entry, Map> tryValue(String id) { + public Map tryValue(String id) { return this.getValue(id, false); } - private Map.Entry, Map> getValue(String id, boolean purgeIfInvalid) { - Map names = this.namesCache.get(new SessionAttributeNamesKey(id)); - if (names == null) { - return this.createValue(id, null); - } - // Validate all attributes - Map keys = new TreeMap<>(); - for (Map.Entry entry : names.entrySet()) { - keys.put(new SessionAttributeKey(id, entry.getValue()), entry.getKey()); - } - Map values = this.attributeCache.getAdvancedCache().getAll(keys.keySet()); - // Validate attributes - Map attributes = new ConcurrentHashMap<>(); - for (Map.Entry entry : keys.entrySet()) { - SessionAttributeKey key = entry.getKey(); - V value = values.get(key); - if (value != null) { + private Map getValue(String id, boolean purgeIfInvalid) { + Map attributes = this.createValue(id, null); + Map value = this.cache.get(new SessionAttributesKey(id)); + if (value != null) { + for (Map.Entry entry : value.entrySet()) { + String attributeName = entry.getKey(); try { - attributes.put(key.getAttributeId(), this.marshaller.read(value)); - continue; + attributes.put(attributeName, this.marshaller.read(entry.getValue())); } catch (IOException e) { - InfinispanWebLogger.ROOT_LOGGER.failedToActivateSessionAttribute(e, id, entry.getValue()); + InfinispanWebLogger.ROOT_LOGGER.failedToActivateSessionAttribute(e, id, attributeName); + if (purgeIfInvalid) { + this.purge(id); + } + return null; } - } else { - InfinispanWebLogger.ROOT_LOGGER.missingSessionAttributeCacheEntry(id, entry.getValue()); } - if (purgeIfInvalid) { - this.purge(id); - } - return null; } - return new AbstractMap.SimpleImmutableEntry<>(new ConcurrentHashMap<>(names), attributes); + return attributes; } @Override public boolean remove(String id) { - return this.delete(this.writeOnlyAttributeCache, id); + return this.delete(this.writeCache, id); } @Override public boolean purge(String id) { - return this.delete(this.silentAttributeCache, id); + return this.delete(this.silentCache, id); } - private boolean delete(Cache cache, String id) { - SessionAttributeNamesKey key = new SessionAttributeNamesKey(id); - Map names = this.namesCache.remove(key); - if (names != null) { - for (UUID attributeId : names.values()) { - cache.remove(new SessionAttributeKey(id, attributeId)); - } - } + private boolean delete(Cache> cache, String id) { + cache.remove(new SessionAttributesKey(id)); return true; } @Override - public SessionAttributes createSessionAttributes(String id, Map.Entry, Map> entry, ImmutableSessionMetaData metaData, C context) { - SessionAttributeActivationNotifier notifier = this.properties.isPersistent() ? new ImmutableSessionAttributeActivationNotifier<>(this.provider, new CompositeImmutableSession(id, metaData, this.createImmutableSessionAttributes(id, entry)), context) : null; - return new FineSessionAttributes<>(this.writeOnlyNamesCache, new SessionAttributeNamesKey(id), entry.getKey(), this.writeOnlyAttributeCache, getKeyFactory(id), entry.getValue(), this.marshaller, this.immutability, this.properties, notifier); + public SessionAttributes createSessionAttributes(String id, Map attributes, ImmutableSessionMetaData metaData, C context) { + SessionAttributeActivationNotifier notifier = this.properties.isPersistent() ? new ImmutableSessionAttributeActivationNotifier<>(this.provider, new CompositeImmutableSession(id, metaData, this.createImmutableSessionAttributes(id, attributes)), context) : null; + return new FineSessionAttributes<>(new SessionAttributesKey(id), attributes, this.mutatorFactory, this.marshaller, this.immutability, this.properties, notifier); } @Override - public ImmutableSessionAttributes createImmutableSessionAttributes(String id, Map.Entry, Map> entry) { - return new FineImmutableSessionAttributes(entry.getKey(), entry.getValue()); - } - - private static Function getKeyFactory(String id) { - return new Function<>() { - @Override - public SessionAttributeKey apply(UUID attributeId) { - return new SessionAttributeKey(id, attributeId); - } - }; + public ImmutableSessionAttributes createImmutableSessionAttributes(String id, Map attributes) { + return new SimpleImmutableSessionAttributes(attributes); } private void cascadeEvict(SessionCreationMetaDataKey key) { - this.namesCache.evict(new SessionAttributeNamesKey(key.getId())); - } - - private void cascadeEvictAttributes(SessionAttributeNamesKey key, Map value) { - String sessionId = key.getId(); - for (UUID attributeId : value.values()) { - this.executor.execute(() -> this.attributeCache.evict(new SessionAttributeKey(sessionId, attributeId))); - } + this.cache.evict(new SessionAttributesKey(key.getId())); } - private void prePassivate(SessionAttributeKey key, V value) { - this.notify(SessionAttributeActivationNotifier.PRE_PASSIVATE, key, value); + private void prePassivate(SessionAttributesKey key, Map attributes) { + this.notify(SessionAttributeActivationNotifier.PRE_PASSIVATE, key, attributes); } - private void postActivate(SessionAttributeKey key, V value) { - this.notify(SessionAttributeActivationNotifier.POST_ACTIVATE, key, value); + private void postActivate(SessionAttributesKey key, Map attributes) { + this.notify(SessionAttributeActivationNotifier.POST_ACTIVATE, key, attributes); } - private void notify(BiConsumer notification, SessionAttributeKey key, V value) { + private void notify(BiConsumer notification, SessionAttributesKey key, Map attributes) { String sessionId = key.getId(); - try (SessionAttributeActivationNotifier notifier = this.notifierFactory.apply(key.getId())) { - notification.accept(notifier, this.marshaller.read(value)); - } catch (IOException e) { - InfinispanWebLogger.ROOT_LOGGER.failedToActivateSessionAttribute(e, sessionId, key.getAttributeId().toString()); + for (Map.Entry entry : attributes.entrySet()) { + try (SessionAttributeActivationNotifier notifier = this.notifierFactory.apply(key.getId())) { + notification.accept(notifier, this.marshaller.read(entry.getValue())); + } catch (IOException e) { + InfinispanWebLogger.ROOT_LOGGER.failedToActivateSessionAttribute(e, sessionId, entry.getKey()); + } } } } diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesSerializationContextInitializer.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesSerializationContextInitializer.java deleted file mode 100644 index 6d5014d45bfb..000000000000 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/FineSessionAttributesSerializationContextInitializer.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.infinispan.session.fine; - -import org.infinispan.protostream.SerializationContext; -import org.infinispan.protostream.SerializationContextInitializer; -import org.kohsuke.MetaInfServices; -import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; -import org.wildfly.clustering.web.cache.SessionKeyMarshaller; - -/** - * @author Paul Ferraro - */ -@MetaInfServices(SerializationContextInitializer.class) -public class FineSessionAttributesSerializationContextInitializer extends AbstractSerializationContextInitializer { - - @Override - public void registerMarshallers(SerializationContext context) { - context.registerMarshaller(new SessionKeyMarshaller<>(SessionAttributeNamesKey.class, SessionAttributeNamesKey::new)); - context.registerMarshaller(new SessionAttributeKeyMarshaller()); - } -} diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKey.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKey.java deleted file mode 100644 index 4f45dda29036..000000000000 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKey.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.clustering.web.infinispan.session.fine; - -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - -import org.wildfly.clustering.ee.infinispan.GroupedKey; - -/** - * Cache key for session attributes. - * @author Paul Ferraro - */ -public class SessionAttributeKey extends GroupedKey implements org.wildfly.clustering.web.cache.session.fine.SessionAttributeKey { - - private final UUID attributeId; - - public SessionAttributeKey(Map.Entry entry) { - this(entry.getKey(), entry.getValue()); - } - - public SessionAttributeKey(String sessionId, UUID attributeId) { - super(sessionId); - this.attributeId = attributeId; - } - - @Override - public UUID getAttributeId() { - return this.attributeId; - } - - @Override - public int hashCode() { - return Objects.hash(this.getClass(), this.getId(), this.attributeId); - } - - @Override - public boolean equals(Object object) { - return super.equals(object) && (object instanceof SessionAttributeKey) && this.attributeId.equals(((SessionAttributeKey) object).attributeId); - } - - @Override - public String toString() { - return String.format("%s(%s[%s])", SessionAttributeKey.class.getSimpleName(), this.getId(), this.attributeId); - } -} \ No newline at end of file diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyFormatter.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyFormatter.java deleted file mode 100644 index c8c485cfa923..000000000000 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyFormatter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.infinispan.session.fine; - -import java.util.UUID; -import java.util.function.Function; - -import org.kohsuke.MetaInfServices; -import org.wildfly.clustering.marshalling.spi.DelimitedFormatter; -import org.wildfly.clustering.marshalling.spi.Formatter; - -/** - * Formatter for a {@link SessionAttributeKey} - * @author Paul Ferraro - */ -@MetaInfServices(Formatter.class) -public class SessionAttributeKeyFormatter extends DelimitedFormatter { - - public SessionAttributeKeyFormatter() { - super(SessionAttributeKey.class, "#", new Function() { - @Override - public SessionAttributeKey apply(String[] parts) { - return new SessionAttributeKey(parts[0], UUID.fromString(parts[1])); - } - }, new Function() { - @Override - public String[] apply(SessionAttributeKey key) { - return new String[] { key.getId(), key.getAttributeId().toString() }; - } - }); - } -} \ No newline at end of file diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyMarshaller.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyMarshaller.java deleted file mode 100644 index 7d24b7fa4b00..000000000000 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyMarshaller.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.infinispan.session.fine; - -import java.io.IOException; - -import org.infinispan.protostream.descriptors.WireType; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; -import org.wildfly.clustering.marshalling.protostream.util.UUIDBuilder; -import org.wildfly.clustering.marshalling.protostream.util.UUIDMarshaller; -import org.wildfly.clustering.web.cache.SessionIdentifierMarshaller; - -public class SessionAttributeKeyMarshaller implements ProtoStreamMarshaller { - - private static final int SESSION_IDENTIFIER_INDEX = 1; - private static final int ATTRIBUTE_IDENTIFIER_INDEX = 2; - - @Override - public SessionAttributeKey readFrom(ProtoStreamReader reader) throws IOException { - String sessionId = null; - UUIDBuilder attributeIdBuilder = UUIDMarshaller.INSTANCE.getBuilder(); - while (!reader.isAtEnd()) { - int tag = reader.readTag(); - int index = WireType.getTagFieldNumber(tag); - if (index == SESSION_IDENTIFIER_INDEX) { - sessionId = SessionIdentifierMarshaller.INSTANCE.readFrom(reader); - } else if (index >= ATTRIBUTE_IDENTIFIER_INDEX && index < ATTRIBUTE_IDENTIFIER_INDEX + UUIDMarshaller.INSTANCE.getFields()) { - UUIDMarshaller.INSTANCE.readField(reader, index - ATTRIBUTE_IDENTIFIER_INDEX, attributeIdBuilder); - } else { - reader.skipField(tag); - } - } - return new SessionAttributeKey(sessionId, attributeIdBuilder.build()); - } - - @Override - public void writeTo(ProtoStreamWriter writer, SessionAttributeKey key) throws IOException { - writer.writeTag(SESSION_IDENTIFIER_INDEX, SessionIdentifierMarshaller.INSTANCE.getWireType()); - SessionIdentifierMarshaller.INSTANCE.writeTo(writer, key.getId()); - UUIDMarshaller.INSTANCE.writeFields(writer, ATTRIBUTE_IDENTIFIER_INDEX, key.getAttributeId()); - } - - @Override - public Class getJavaClass() { - return SessionAttributeKey.class; - } -} \ No newline at end of file diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKey.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKey.java deleted file mode 100644 index 0e12cbd9e67e..000000000000 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKey.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.clustering.web.infinispan.session.fine; - -import org.wildfly.clustering.ee.infinispan.GroupedKey; - -/** - * Cache key for session attribute names. - * @author Paul Ferraro - */ -public class SessionAttributeNamesKey extends GroupedKey { - - public SessionAttributeNamesKey(String id) { - super(id); - } -} diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyFormatter.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyFormatter.java deleted file mode 100644 index 5ed5ad9b0416..000000000000 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyFormatter.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.clustering.web.infinispan.session.fine; - -import org.kohsuke.MetaInfServices; -import org.wildfly.clustering.marshalling.spi.Formatter; -import org.wildfly.clustering.web.infinispan.SessionKeyFormatter; - -/** - * Formatter for {@link SessionAttributeNamesKey}. - * @author Paul Ferraro - */ -@MetaInfServices(Formatter.class) -public class SessionAttributeNamesKeyFormatter extends SessionKeyFormatter { - - public SessionAttributeNamesKeyFormatter() { - super(SessionAttributeNamesKey.class, SessionAttributeNamesKey::new); - } -} diff --git a/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.coarse.proto b/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.coarse.proto deleted file mode 100644 index 246581af7443..000000000000 --- a/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.coarse.proto +++ /dev/null @@ -1,10 +0,0 @@ -package org.wildfly.clustering.web.infinispan.session.coarse; - -// IDs: 210 - 214 - -/** - * @TypeId(210) - */ -message SessionAttributesKey { - required bytes id = 1; -} diff --git a/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.fine.proto b/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.fine.proto deleted file mode 100644 index bc0fb34b6d8e..000000000000 --- a/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.fine.proto +++ /dev/null @@ -1,19 +0,0 @@ -package org.wildfly.clustering.web.infinispan.session.fine; - -// IDs: 220 - 224 - -/** - * @TypeId(220) - */ -message SessionAttributeNamesKey { - required bytes id = 1; -} - -/** - * @TypeId(221) - */ -message SessionAttributeKey { - required bytes id = 1; - optional sfixed64 mostSigBits = 2; - optional sfixed64 leastSigBits = 3; -} diff --git a/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.proto b/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.proto index 9fa6bc8bba8e..60a9640a8438 100644 --- a/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.proto +++ b/clustering/web/infinispan/src/main/resources/org.wildfly.clustering.web.infinispan.session.proto @@ -24,3 +24,10 @@ message SessionAccessMetaDataKey { enum SessionCreationMetaDataKeyFilter { INSTANCE = 0; } + +/** + * @TypeId(203) + */ +message SessionAttributesKey { + required bytes id = 1; +} diff --git a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/KeyMapperTestCase.java b/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/KeyMapperTestCase.java index f2a584a4bde9..f1d5a6ca2ca1 100644 --- a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/KeyMapperTestCase.java +++ b/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/KeyMapperTestCase.java @@ -5,15 +5,11 @@ package org.wildfly.clustering.web.infinispan; -import java.util.UUID; - import org.junit.Test; import org.wildfly.clustering.infinispan.persistence.KeyMapperTester; import org.wildfly.clustering.web.infinispan.session.SessionAccessMetaDataKey; +import org.wildfly.clustering.web.infinispan.session.SessionAttributesKey; import org.wildfly.clustering.web.infinispan.session.SessionCreationMetaDataKey; -import org.wildfly.clustering.web.infinispan.session.coarse.SessionAttributesKey; -import org.wildfly.clustering.web.infinispan.session.fine.SessionAttributeKey; -import org.wildfly.clustering.web.infinispan.session.fine.SessionAttributeNamesKey; import org.wildfly.clustering.web.infinispan.sso.AuthenticationKey; import org.wildfly.clustering.web.infinispan.sso.coarse.CoarseSessionsKey; @@ -30,8 +26,6 @@ public void test() { tester.test(new SessionCreationMetaDataKey(id)); tester.test(new SessionAccessMetaDataKey(id)); tester.test(new SessionAttributesKey(id)); - tester.test(new SessionAttributeNamesKey(id)); - tester.test(new SessionAttributeKey(id, UUID.randomUUID())); tester.test(new AuthenticationKey(id)); tester.test(new CoarseSessionsKey(id)); diff --git a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKeyTestCase.java b/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKeyTestCase.java similarity index 91% rename from clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKeyTestCase.java rename to clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKeyTestCase.java index 6d89810fa079..f30b36a5914a 100644 --- a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/coarse/SessionAttributesKeyTestCase.java +++ b/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/SessionAttributesKeyTestCase.java @@ -2,8 +2,7 @@ * Copyright The WildFly Authors * SPDX-License-Identifier: Apache-2.0 */ - -package org.wildfly.clustering.web.infinispan.session.coarse; +package org.wildfly.clustering.web.infinispan.session; import java.io.IOException; diff --git a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyTestCase.java b/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyTestCase.java deleted file mode 100644 index ff047a3e7cf1..000000000000 --- a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeKeyTestCase.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.infinispan.session.fine; - -import java.io.IOException; -import java.util.UUID; - -import org.junit.Test; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; -import org.wildfly.clustering.marshalling.spi.FormatterTester; - -/** - * Unit test for {@link SessionAttributeKey}. - * @author Paul Ferraro - */ -public class SessionAttributeKeyTestCase { - - @Test - public void test() throws IOException { - SessionAttributeKey key = new SessionAttributeKey("ABC123", UUID.randomUUID()); - ProtoStreamTesterFactory.INSTANCE.createTester().test(key); - new FormatterTester<>(new SessionAttributeKeyFormatter()).test(key); - } -} diff --git a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyTestCase.java b/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyTestCase.java deleted file mode 100644 index c3f5b17f309b..000000000000 --- a/clustering/web/infinispan/src/test/java/org/wildfly/clustering/web/infinispan/session/fine/SessionAttributeNamesKeyTestCase.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.clustering.web.infinispan.session.fine; - -import java.io.IOException; - -import org.junit.Test; -import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; -import org.wildfly.clustering.marshalling.spi.FormatterTester; - -/** - * Unit test for {@link SessionAttributeNamesKey}. - * @author Paul Ferraro - */ -public class SessionAttributeNamesKeyTestCase { - - @Test - public void test() throws IOException { - SessionAttributeNamesKey key = new SessionAttributeNamesKey("ABC123"); - ProtoStreamTesterFactory.INSTANCE.createTester().test(key); - new FormatterTester<>(new SessionAttributeNamesKeyFormatter()).test(key); - } -} From 58929bbe9a5ed605ed4577b2c709b13a4233e0f9 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Wed, 4 Oct 2023 10:54:32 -0400 Subject: [PATCH 7/7] Cosmetic rename. --- ...finispanMutatorFactory.java => CacheMutatorFactory.java} | 6 +++--- .../ejb/infinispan/bean/InfinispanBeanGroupManager.java | 4 ++-- .../ejb/infinispan/bean/InfinispanBeanMetaDataFactory.java | 4 ++-- .../session/AbstractInfinispanSessionMetaDataFactory.java | 6 +++--- .../session/coarse/CoarseSessionAttributesFactory.java | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) rename clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/{InfinispanMutatorFactory.java => CacheMutatorFactory.java} (79%) diff --git a/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/InfinispanMutatorFactory.java b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheMutatorFactory.java similarity index 79% rename from clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/InfinispanMutatorFactory.java rename to clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheMutatorFactory.java index 19734f30b71d..ba11a52ed61c 100644 --- a/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/InfinispanMutatorFactory.java +++ b/clustering/ee/infinispan/src/main/java/org/wildfly/clustering/ee/infinispan/CacheMutatorFactory.java @@ -14,16 +14,16 @@ * Factory for creating {@link Mutator} objects for an Infinispan cache. * @author Paul Ferraro */ -public class InfinispanMutatorFactory implements MutatorFactory { +public class CacheMutatorFactory implements MutatorFactory { private final Cache cache; private final CacheProperties properties; - public InfinispanMutatorFactory(Cache cache) { + public CacheMutatorFactory(Cache cache) { this(cache, new InfinispanCacheProperties(cache.getCacheConfiguration())); } - public InfinispanMutatorFactory(Cache cache, CacheProperties properties) { + public CacheMutatorFactory(Cache cache, CacheProperties properties) { this.cache = cache; this.properties = properties; } diff --git a/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupManager.java b/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupManager.java index 7494a07e3e8d..e337fe1d870f 100644 --- a/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupManager.java +++ b/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanGroupManager.java @@ -13,7 +13,7 @@ import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.Remover; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; -import org.wildfly.clustering.ee.infinispan.InfinispanMutatorFactory; +import org.wildfly.clustering.ee.infinispan.CacheMutatorFactory; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.cache.bean.BeanGroupKey; import org.wildfly.clustering.marshalling.spi.MarshalledValue; @@ -34,7 +34,7 @@ public class InfinispanBeanGroupManager, C> impleme public InfinispanBeanGroupManager(InfinispanConfiguration configuration) { this.cache = configuration.getCache(); this.removeCache = configuration.getWriteOnlyCache(); - this.mutatorFactory = new InfinispanMutatorFactory<>(configuration.getCache()); + this.mutatorFactory = new CacheMutatorFactory<>(configuration.getCache()); } @Override diff --git a/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanMetaDataFactory.java b/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanMetaDataFactory.java index 73b7952bf253..584a919f4532 100644 --- a/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanMetaDataFactory.java +++ b/clustering/ejb/infinispan/src/main/java/org/wildfly/clustering/ejb/infinispan/bean/InfinispanBeanMetaDataFactory.java @@ -11,7 +11,7 @@ import org.wildfly.clustering.ee.Key; import org.wildfly.clustering.ee.Mutator; import org.wildfly.clustering.ee.MutatorFactory; -import org.wildfly.clustering.ee.infinispan.InfinispanMutatorFactory; +import org.wildfly.clustering.ee.infinispan.CacheMutatorFactory; import org.wildfly.clustering.ejb.bean.BeanExpiration; import org.wildfly.clustering.ejb.bean.BeanInstance; import org.wildfly.clustering.ejb.bean.BeanMetaData; @@ -50,7 +50,7 @@ public InfinispanBeanMetaDataFactory(InfinispanBeanMetaDataFactoryConfiguration this.expiration = configuration.getExpiration(); boolean scheduledExpiration = (this.expiration != null) && !this.expiration.getTimeout().isZero(); this.accessMetaDataCache = scheduledExpiration ? configuration.getCache() : null; - this.mutatorFactory = (this.accessMetaDataCache != null) ? new InfinispanMutatorFactory<>(this.accessMetaDataCache) : null; + this.mutatorFactory = (this.accessMetaDataCache != null) ? new CacheMutatorFactory<>(this.accessMetaDataCache) : null; this.beanName = configuration.getBeanName(); } diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/AbstractInfinispanSessionMetaDataFactory.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/AbstractInfinispanSessionMetaDataFactory.java index 75d094f03038..5a7c14c6460d 100644 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/AbstractInfinispanSessionMetaDataFactory.java +++ b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/AbstractInfinispanSessionMetaDataFactory.java @@ -21,7 +21,7 @@ import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.cache.CacheProperties; import org.wildfly.clustering.ee.infinispan.InfinispanConfiguration; -import org.wildfly.clustering.ee.infinispan.InfinispanMutatorFactory; +import org.wildfly.clustering.ee.infinispan.CacheMutatorFactory; import org.wildfly.clustering.infinispan.listener.ListenerRegistration; import org.wildfly.clustering.infinispan.listener.PostPassivateBlockingListener; import org.wildfly.clustering.web.cache.session.CompositeSessionMetaData; @@ -66,9 +66,9 @@ public AbstractInfinispanSessionMetaDataFactory(InfinispanConfiguration configur this.creationMetaDataTryLockCache = configuration.getTryLockCache(); this.properties = configuration.getCacheProperties(); this.creationMetaDataCache = configuration.getCache(); - this.creationMetaDataMutatorFactory = new InfinispanMutatorFactory<>(this.creationMetaDataCache, this.properties); + this.creationMetaDataMutatorFactory = new CacheMutatorFactory<>(this.creationMetaDataCache, this.properties); this.accessMetaDataCache = configuration.getCache(); - this.accessMetaDataMutatorFactory = new InfinispanMutatorFactory<>(this.accessMetaDataCache, this.properties); + this.accessMetaDataMutatorFactory = new CacheMutatorFactory<>(this.accessMetaDataCache, this.properties); this.evictListenerRegistration = new PostPassivateBlockingListener<>(this.creationMetaDataCache, this::cascadeEvict).register(SessionCreationMetaDataKey.class); } diff --git a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java index a94933b888a0..a9fb7790d7da 100644 --- a/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java +++ b/clustering/web/infinispan/src/main/java/org/wildfly/clustering/web/infinispan/session/coarse/CoarseSessionAttributesFactory.java @@ -16,7 +16,7 @@ import org.wildfly.clustering.ee.Mutator; import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.cache.CacheProperties; -import org.wildfly.clustering.ee.infinispan.InfinispanMutatorFactory; +import org.wildfly.clustering.ee.infinispan.CacheMutatorFactory; import org.wildfly.clustering.infinispan.listener.ListenerRegistration; import org.wildfly.clustering.infinispan.listener.PostActivateBlockingListener; import org.wildfly.clustering.infinispan.listener.PostPassivateBlockingListener; @@ -64,7 +64,7 @@ public CoarseSessionAttributesFactory(InfinispanSessionAttributesFactoryConfigur this.marshaller = configuration.getMarshaller(); this.immutability = configuration.getImmutability(); this.properties = configuration.getCacheProperties(); - this.mutatorFactory = new InfinispanMutatorFactory<>(this.cache, this.properties); + this.mutatorFactory = new CacheMutatorFactory<>(this.cache, this.properties); this.provider = configuration.getHttpSessionActivationListenerProvider(); this.notifierFactory = configuration.getActivationNotifierFactory(); this.prePassivateListenerRegistration = !this.properties.isPersistent() ? new PrePassivateBlockingListener<>(this.cache, this::prePassivate).register(SessionAttributesKey.class) : null;