use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.
the class InfinispanSessionManager method passivated.
@CacheEntryPassivated
public void passivated(CacheEntryPassivatedEvent<SessionCreationMetaDataKey, ?> event) {
if (event.isPre() && !this.properties.isPersistent()) {
String id = event.getKey().getValue();
InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s will be passivated", id);
Map.Entry<MV, AV> value = this.factory.findValue(id);
if (value != null) {
ImmutableSession session = this.factory.createImmutableSession(id, value);
this.triggerPrePassivationEvents(session);
}
}
}
use of org.wildfly.clustering.web.session.ImmutableSession 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);
}
use of org.wildfly.clustering.web.session.ImmutableSession 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());
}
use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.
the class HotRodSessionManager method findSession.
@Override
public Session<LC> findSession(String id) {
Map.Entry<MV, AV> entry = this.factory.findValue(id);
if (entry == null) {
Logger.ROOT_LOGGER.tracef("Session %s not found", id);
return null;
}
ImmutableSession session = this.factory.createImmutableSession(id, entry);
if (session.getMetaData().isExpired()) {
Logger.ROOT_LOGGER.tracef("Session %s was found, but has expired", id);
this.expirationListener.sessionExpired(session);
this.factory.remove(id);
return null;
}
return new ValidSession<>(this.factory.createSession(id, entry, this.context), this.closeTask);
}
use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.
the class InfinispanSessionManager method findSession.
@Override
public Session<LC> findSession(String id) {
Map.Entry<MV, AV> value = this.factory.findValue(id);
if (value == null) {
InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s not found", id);
return null;
}
ImmutableSession session = this.factory.createImmutableSession(id, value);
if (session.getMetaData().isExpired()) {
InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s was found, but has expired", id);
this.expirationListener.sessionExpired(session);
this.factory.remove(id);
return null;
}
this.expirationScheduler.cancel(id);
return new ValidSession<>(this.factory.createSession(id, value, this.context), this.closeTask);
}
Aggregations