Search in sources :

Example 1 with CompositeSessionMetaDataEntry

use of org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry in project wildfly by wildfly.

the class HotRodSessionFactory method expired.

@ClientCacheEntryExpired
public void expired(ClientCacheEntryCustomEvent<byte[]> event) {
    RemoteCache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache = this.creationMetaDataCache;
    RemoteCache<SessionAccessMetaDataKey, SessionAccessMetaData> accessMetaDataCache = this.accessMetaDataCache;
    ImmutableSessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> metaDataFactory = this.metaDataFactory;
    ImmutableSessionAttributesFactory<V> attributesFactory = this.attributesFactory;
    Remover<String> attributesRemover = this.attributesRemover;
    Collection<SessionExpirationListener> listeners = this.listeners;
    boolean nearCacheEnabled = this.nearCacheEnabled;
    Runnable task = new Runnable() {

        @Override
        public void run() {
            ByteBuffer buffer = ByteBuffer.wrap(event.getEventData());
            byte[] key = new byte[UnsignedNumeric.readUnsignedInt(buffer)];
            buffer.get(key);
            byte[] value = buffer.remaining() > 0 ? new byte[UnsignedNumeric.readUnsignedInt(buffer)] : null;
            if (value != null) {
                buffer.get(value);
            }
            Marshaller marshaller = creationMetaDataCache.getRemoteCacheManager().getConfiguration().marshaller();
            String id = null;
            try {
                SessionCreationMetaDataKey creationKey = (SessionCreationMetaDataKey) marshaller.objectFromByteBuffer(key);
                id = creationKey.getId();
                @SuppressWarnings("unchecked") SessionCreationMetaDataEntry<L> creationEntry = (value != null) ? (SessionCreationMetaDataEntry<L>) marshaller.objectFromByteBuffer(value) : new SessionCreationMetaDataEntry<>(new SimpleSessionCreationMetaData(Instant.EPOCH));
                // Ensure entry is removed from near cache
                if (nearCacheEnabled) {
                    creationMetaDataCache.withFlags(Flag.SKIP_LISTENER_NOTIFICATION).remove(creationKey);
                }
                SessionAccessMetaData accessMetaData = accessMetaDataCache.withFlags(Flag.FORCE_RETURN_VALUE).remove(new SessionAccessMetaDataKey(id));
                if (accessMetaData != null) {
                    V attributesValue = attributesFactory.findValue(id);
                    if (attributesValue != null) {
                        ImmutableSessionMetaData metaData = metaDataFactory.createImmutableSessionMetaData(id, new CompositeSessionMetaDataEntry<>(creationEntry, accessMetaData));
                        ImmutableSessionAttributes attributes = attributesFactory.createImmutableSessionAttributes(id, attributesValue);
                        ImmutableSession session = HotRodSessionFactory.this.createImmutableSession(id, metaData, attributes);
                        Logger.ROOT_LOGGER.tracef("Session %s has expired.", id);
                        for (SessionExpirationListener listener : listeners) {
                            listener.sessionExpired(session);
                        }
                        attributesRemover.remove(id);
                    }
                }
            } catch (IOException | ClassNotFoundException e) {
                Logger.ROOT_LOGGER.failedToExpireSession(e, id);
            }
        }
    };
    this.executor.submit(task);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) CompositeSessionMetaDataEntry(org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry) Marshaller(org.infinispan.commons.marshall.Marshaller) ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) IOException(java.io.IOException) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) ByteBuffer(java.nio.ByteBuffer) SimpleSessionCreationMetaData(org.wildfly.clustering.web.cache.session.SimpleSessionCreationMetaData) SessionAccessMetaData(org.wildfly.clustering.web.cache.session.SessionAccessMetaData) SessionCreationMetaDataEntry(org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry) ClientCacheEntryExpired(org.infinispan.client.hotrod.annotation.ClientCacheEntryExpired)

Example 2 with CompositeSessionMetaDataEntry

use of org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry 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 CompositeSessionMetaDataEntry

use of org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry 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 CompositeSessionMetaDataEntry

use of org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry 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 CompositeSessionMetaDataEntry

use of org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry in project wildfly by wildfly.

the class HotRodSessionMetaDataFactory method createValue.

@Override
public CompositeSessionMetaDataEntry<L> createValue(String id, Void context) {
    SessionCreationMetaDataEntry<L> creationMetaDataEntry = new SessionCreationMetaDataEntry<>(new SimpleSessionCreationMetaData());
    SessionAccessMetaData accessMetaData = new SimpleSessionAccessMetaData();
    this.creationMetaDataMutatorFactory.createMutator(new SessionCreationMetaDataKey(id), creationMetaDataEntry).mutate();
    this.accessMetaDataMutatorFactory.createMutator(new SessionAccessMetaDataKey(id), accessMetaData).mutate();
    return new CompositeSessionMetaDataEntry<>(creationMetaDataEntry, accessMetaData);
}
Also used : 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) CompositeSessionMetaDataEntry(org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry) SessionCreationMetaDataEntry(org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry)

Aggregations

CompositeSessionMetaDataEntry (org.wildfly.clustering.web.cache.session.CompositeSessionMetaDataEntry)5 SessionAccessMetaData (org.wildfly.clustering.web.cache.session.SessionAccessMetaData)5 SessionCreationMetaDataEntry (org.wildfly.clustering.web.cache.session.SessionCreationMetaDataEntry)5 Key (org.wildfly.clustering.ee.Key)3 MutableSessionAccessMetaData (org.wildfly.clustering.web.cache.session.MutableSessionAccessMetaData)3 SimpleSessionAccessMetaData (org.wildfly.clustering.web.cache.session.SimpleSessionAccessMetaData)3 SimpleSessionCreationMetaData (org.wildfly.clustering.web.cache.session.SimpleSessionCreationMetaData)3 HashSet (java.util.HashSet)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 ClientCacheEntryExpired (org.infinispan.client.hotrod.annotation.ClientCacheEntryExpired)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)1 ImmutableSessionAttributes (org.wildfly.clustering.web.session.ImmutableSessionAttributes)1 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)1 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)1