Search in sources :

Example 1 with ImmutableSessionAttributes

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

use of org.wildfly.clustering.web.session.ImmutableSessionAttributes in project wildfly by wildfly.

the class CompositeSessionFactoryTestCase method createImmutableSession.

@Test
public void createImmutableSession() {
    Map.Entry<CompositeSessionMetaDataEntry<Object>, Object> entry = mock(Map.Entry.class);
    SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
    SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
    CompositeSessionMetaDataEntry<Object> metaDataValue = new CompositeSessionMetaDataEntry<>(creationMetaData, accessMetaData, null);
    Object attributesValue = new Object();
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    String id = "id";
    when(entry.getKey()).thenReturn(metaDataValue);
    when(entry.getValue()).thenReturn(attributesValue);
    when(this.metaDataFactory.createImmutableSessionMetaData(id, metaDataValue)).thenReturn(metaData);
    when(this.attributesFactory.createImmutableSessionAttributes(id, attributesValue)).thenReturn(attributes);
    ImmutableSession result = this.factory.createImmutableSession(id, entry);
    assertSame(id, result.getId());
    assertSame(metaData, result.getMetaData());
    assertSame(attributes, result.getAttributes());
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Map(java.util.Map) Test(org.junit.Test)

Example 3 with ImmutableSessionAttributes

use of org.wildfly.clustering.web.session.ImmutableSessionAttributes in project wildfly by wildfly.

the class InfinispanSessionFactoryTestCase method createImmutableSession.

@Test
public void createImmutableSession() {
    Map.Entry<InfinispanSessionMetaData<Object>, Object> entry = mock(Map.Entry.class);
    SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
    SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
    InfinispanSessionMetaData<Object> metaDataValue = new InfinispanSessionMetaData<>(creationMetaData, accessMetaData, null);
    Object attributesValue = new Object();
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    String id = "id";
    when(entry.getKey()).thenReturn(metaDataValue);
    when(entry.getValue()).thenReturn(attributesValue);
    when(this.metaDataFactory.createImmutableSessionMetaData(id, metaDataValue)).thenReturn(metaData);
    when(this.attributesFactory.createImmutableSessionAttributes(id, attributesValue)).thenReturn(attributes);
    ImmutableSession result = this.factory.createImmutableSession(id, entry);
    assertSame(id, result.getId());
    assertSame(metaData, result.getMetaData());
    assertSame(attributes, result.getAttributes());
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ImmutableSessionAttributes

use of org.wildfly.clustering.web.session.ImmutableSessionAttributes in project wildfly by wildfly.

the class ImmutableSessionFactory method createImmutableSession.

default ImmutableSession createImmutableSession(String id, Map.Entry<MV, AV> entry) {
    ImmutableSessionMetaData metaData = this.getMetaDataFactory().createImmutableSessionMetaData(id, entry.getKey());
    ImmutableSessionAttributes attributes = this.getAttributesFactory().createImmutableSessionAttributes(id, entry.getValue());
    return this.createImmutableSession(id, metaData, attributes);
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData)

Example 5 with ImmutableSessionAttributes

use of org.wildfly.clustering.web.session.ImmutableSessionAttributes in project wildfly by wildfly.

the class ExpiredSessionRemover method remove.

@Override
public boolean remove(String id) {
    MV metaDataValue = this.factory.getMetaDataFactory().tryValue(id);
    if (metaDataValue != null) {
        ImmutableSessionMetaData metaData = this.factory.getMetaDataFactory().createImmutableSessionMetaData(id, metaDataValue);
        if (metaData.isExpired()) {
            AV attributesValue = this.factory.getAttributesFactory().findValue(id);
            if (attributesValue != null) {
                ImmutableSessionAttributes attributes = this.factory.getAttributesFactory().createImmutableSessionAttributes(id, attributesValue);
                ImmutableSession session = this.factory.createImmutableSession(id, metaData, attributes);
                InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s has expired.", id);
                for (SessionExpirationListener listener : this.listeners) {
                    listener.sessionExpired(session);
                }
            }
            return this.factory.remove(id);
        }
        InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s is not yet expired.", id);
    } else {
        InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s was not found or is currently in use.", id);
    }
    return false;
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData)

Aggregations

ImmutableSessionAttributes (org.wildfly.clustering.web.session.ImmutableSessionAttributes)12 ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)9 Test (org.junit.Test)7 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)7 Map (java.util.Map)4 Batch (org.wildfly.clustering.ee.Batch)4 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)4 Session (io.undertow.server.session.Session)2 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)1 SessionConfig (io.undertow.server.session.SessionConfig)1 SessionListener (io.undertow.server.session.SessionListener)1 SessionListeners (io.undertow.server.session.SessionListeners)1 Deployment (io.undertow.servlet.api.Deployment)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 UUID (java.util.UUID)1 ClientCacheEntryExpired (org.infinispan.client.hotrod.annotation.ClientCacheEntryExpired)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 Registration (org.wildfly.clustering.Registration)1 BatchContext (org.wildfly.clustering.ee.BatchContext)1