Search in sources :

Example 1 with Key

use of org.wildfly.clustering.ee.Key in project wildfly by wildfly.

the class AffinityIdentifierFactoryTestCase method init.

@Before
public void init() throws Exception {
    EmbeddedCacheManager manager = mock(EmbeddedCacheManager.class);
    try (AutoCloseable test = MockitoAnnotations.openMocks(this)) {
        when(this.affinityFactory.createService(same(this.cache), this.capturedGenerator.capture())).thenReturn(this.affinity);
        when(this.cache.getCacheManager()).thenReturn(manager);
        when(manager.getAddress()).thenReturn(this.localAddress);
        this.subject = new AffinityIdentifierFactory<>(this.factory, this.cache, this.affinityFactory);
        KeyGenerator<Key<UUID>> generator = this.capturedGenerator.getValue();
        assertSame(generator, this.subject);
        UUID expected = UUID.randomUUID();
        when(this.factory.get()).thenReturn(expected);
        Key<UUID> result = generator.getKey();
        assertSame(expected, result.getId());
    }
}
Also used : EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) UUID(java.util.UUID) Key(org.wildfly.clustering.ee.Key) GroupedKey(org.wildfly.clustering.ee.infinispan.GroupedKey) Before(org.junit.Before)

Example 2 with Key

use of org.wildfly.clustering.ee.Key in project wildfly by wildfly.

the class HotRodSessionMetaDataFactory method findValue.

@Override
public CompositeSessionMetaDataEntry<L> findValue(String id) {
    SessionCreationMetaDataKey creationMetaDataKey = new SessionCreationMetaDataKey(id);
    SessionAccessMetaDataKey accessMetaDataKey = new SessionAccessMetaDataKey(id);
    Set<Key<String>> keys = new HashSet<>(3);
    keys.add(creationMetaDataKey);
    keys.add(accessMetaDataKey);
    // Use bulk read
    Map<Key<String>, Object> entries = this.cache.getAll(keys);
    @SuppressWarnings("unchecked") SessionCreationMetaDataEntry<L> creationMetaDataEntry = (SessionCreationMetaDataEntry<L>) entries.get(creationMetaDataKey);
    SessionAccessMetaData accessMetaData = (SessionAccessMetaData) entries.get(accessMetaDataKey);
    if ((creationMetaDataEntry != null) && (accessMetaData != null)) {
        return new CompositeSessionMetaDataEntry<>(creationMetaDataEntry, accessMetaData);
    }
    return null;
}
Also used : MutableSessionAccessMetaData(org.wildfly.clustering.web.cache.session.MutableSessionAccessMetaData) SimpleSessionAccessMetaData(org.wildfly.clustering.web.cache.session.SimpleSessionAccessMetaData) SessionAccessMetaData(org.wildfly.clustering.web.cache.session.SessionAccessMetaData) Key(org.wildfly.clustering.ee.Key) CompositeSessionMetaDataEntry(org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry) HashSet(java.util.HashSet) SessionCreationMetaDataEntry(org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry)

Example 3 with Key

use of org.wildfly.clustering.ee.Key in project wildfly by wildfly.

the class AbstractInfinispanSessionMetaDataFactory method createValue.

@Override
public CompositeSessionMetaDataEntry<L> createValue(String id, Void context) {
    Map<Key<String>, Object> entries = new HashMap<>(3);
    SessionCreationMetaDataEntry<L> creationMetaDataEntry = new SessionCreationMetaDataEntry<>(new SimpleSessionCreationMetaData());
    entries.put(new SessionCreationMetaDataKey(id), creationMetaDataEntry);
    SessionAccessMetaData accessMetaData = new SimpleSessionAccessMetaData();
    entries.put(new SessionAccessMetaDataKey(id), accessMetaData);
    this.writeCache.putAll(entries);
    return new CompositeSessionMetaDataEntry<>(creationMetaDataEntry, accessMetaData);
}
Also used : HashMap(java.util.HashMap) SimpleSessionAccessMetaData(org.wildfly.clustering.web.cache.session.SimpleSessionAccessMetaData) SimpleSessionCreationMetaData(org.wildfly.clustering.web.cache.session.SimpleSessionCreationMetaData) MutableSessionAccessMetaData(org.wildfly.clustering.web.cache.session.MutableSessionAccessMetaData) SimpleSessionAccessMetaData(org.wildfly.clustering.web.cache.session.SimpleSessionAccessMetaData) SessionAccessMetaData(org.wildfly.clustering.web.cache.session.SessionAccessMetaData) Key(org.wildfly.clustering.ee.Key) CompositeSessionMetaDataEntry(org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry) SessionCreationMetaDataEntry(org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry)

Example 4 with Key

use of org.wildfly.clustering.ee.Key in project wildfly by wildfly.

the class InfinispanSessionMetaDataFactory method apply.

@Override
public CompositeSessionMetaDataEntry<L> apply(String id, Set<Flag> flags) {
    SessionCreationMetaDataKey creationMetaDataKey = new SessionCreationMetaDataKey(id);
    SessionAccessMetaDataKey accessMetaDataKey = new SessionAccessMetaDataKey(id);
    Set<Key<String>> keys = new HashSet<>(3);
    keys.add(creationMetaDataKey);
    keys.add(accessMetaDataKey);
    // Use bulk read
    Map<Key<String>, Object> entries = this.cache.getAdvancedCache().withFlags(flags).getAll(keys);
    @SuppressWarnings("unchecked") SessionCreationMetaDataEntry<L> creationMetaDataEntry = (SessionCreationMetaDataEntry<L>) entries.get(creationMetaDataKey);
    SessionAccessMetaData accessMetaData = (SessionAccessMetaData) entries.get(accessMetaDataKey);
    if ((creationMetaDataEntry != null) && (accessMetaData != null)) {
        return new CompositeSessionMetaDataEntry<>(creationMetaDataEntry, accessMetaData);
    }
    if (flags.isEmpty() && ((creationMetaDataEntry != null) || (accessMetaData != null))) {
        this.purge(id);
    }
    return null;
}
Also used : SessionAccessMetaData(org.wildfly.clustering.web.cache.session.SessionAccessMetaData) Key(org.wildfly.clustering.ee.Key) CompositeSessionMetaDataEntry(org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry) HashSet(java.util.HashSet) SessionCreationMetaDataEntry(org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry)

Example 5 with Key

use of org.wildfly.clustering.ee.Key in project wildfly by wildfly.

the class InfinispanSessionManager method stop.

@Override
public void stop() {
    if (!this.properties.isPersistent()) {
        PersistenceConfiguration persistence = this.cache.getCacheConfiguration().persistence();
        // Don't passivate sessions on stop if we will purge the store on startup
        if (persistence.passivation() && !persistence.stores().stream().allMatch(StoreConfiguration::purgeOnStartup)) {
            try (Stream<Key<String>> stream = this.cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_LOAD, Flag.SKIP_LOCKING).keySet().stream()) {
                stream.filter(SessionCreationMetaDataKeyFilter.INSTANCE).forEach(this.cache::evict);
            }
        }
    }
    this.expirationRegistration.close();
    if (this.recorder != null) {
        this.cache.removeListener(this);
    }
    this.identifierFactory.stop();
    this.contextRegistration.close();
}
Also used : PersistenceConfiguration(org.infinispan.configuration.cache.PersistenceConfiguration) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) Key(org.wildfly.clustering.ee.Key)

Aggregations

Key (org.wildfly.clustering.ee.Key)5 CompositeSessionMetaDataEntry (org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry)3 SessionAccessMetaData (org.wildfly.clustering.web.cache.session.SessionAccessMetaData)3 SessionCreationMetaDataEntry (org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry)3 HashSet (java.util.HashSet)2 MutableSessionAccessMetaData (org.wildfly.clustering.web.cache.session.MutableSessionAccessMetaData)2 SimpleSessionAccessMetaData (org.wildfly.clustering.web.cache.session.SimpleSessionAccessMetaData)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 PersistenceConfiguration (org.infinispan.configuration.cache.PersistenceConfiguration)1 StoreConfiguration (org.infinispan.configuration.cache.StoreConfiguration)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 Before (org.junit.Before)1 GroupedKey (org.wildfly.clustering.ee.infinispan.GroupedKey)1 SimpleSessionCreationMetaData (org.wildfly.clustering.web.cache.session.SimpleSessionCreationMetaData)1