use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.
the class DistributableSession method getAttribute.
@Override
public Object getAttribute(String name) {
Session<LocalSessionContext> session = this.entry.getKey();
validate(session);
try (BatchContext context = this.manager.getSessionManager().getBatcher().resumeBatch(this.batch)) {
if (CachedAuthenticatedSessionHandler.ATTRIBUTE_NAME.equals(name)) {
AuthenticatedSession auth = (AuthenticatedSession) session.getAttributes().getAttribute(name);
return (auth != null) ? auth : session.getLocalContext().getAuthenticatedSession();
}
return session.getAttributes().getAttribute(name);
}
}
use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.
the class DistributableSessionManagerFactory method createSessionManager.
@Override
public io.undertow.server.session.SessionManager createSessionManager(final Deployment deployment) {
DeploymentInfo info = deployment.getDeploymentInfo();
boolean statisticsEnabled = info.getMetricsCollector() != null;
RecordableInactiveSessionStatistics inactiveSessionStatistics = statisticsEnabled ? new RecordableInactiveSessionStatistics() : null;
IdentifierFactory<String> factory = new IdentifierFactoryAdapter(info.getSessionIdGenerator());
LocalContextFactory<LocalSessionContext> localContextFactory = new LocalSessionContextFactory();
SessionListeners listeners = new SessionListeners();
SessionExpirationListener expirationListener = new UndertowSessionExpirationListener(deployment, listeners);
SessionManagerConfiguration<LocalSessionContext> configuration = new SessionManagerConfiguration<LocalSessionContext>() {
@Override
public ServletContext getServletContext() {
return deployment.getServletContext();
}
@Override
public IdentifierFactory<String> getIdentifierFactory() {
return factory;
}
@Override
public SessionExpirationListener getExpirationListener() {
return expirationListener;
}
@Override
public LocalContextFactory<LocalSessionContext> getLocalContextFactory() {
return localContextFactory;
}
@Override
public Recordable<ImmutableSession> getInactiveSessionRecorder() {
return inactiveSessionStatistics;
}
};
SessionManager<LocalSessionContext, Batch> manager = this.factory.createSessionManager(configuration);
Batcher<Batch> batcher = manager.getBatcher();
info.addThreadSetupAction(new ThreadSetupHandler() {
@Override
public <T, C> Action<T, C> create(Action<T, C> action) {
return new Action<T, C>() {
@Override
public T call(HttpServerExchange exchange, C context) throws Exception {
Batch batch = batcher.suspendBatch();
try (BatchContext ctx = batcher.resumeBatch(batch)) {
return action.call(exchange, context);
}
}
};
}
});
RecordableSessionManagerStatistics statistics = (inactiveSessionStatistics != null) ? new DistributableSessionManagerStatistics(manager, inactiveSessionStatistics) : null;
return new DistributableSessionManager(info.getDeploymentName(), manager, listeners, statistics);
}
use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.
the class DistributableSessionTestCase method setMaxInactiveInterval.
@Test
public void setMaxInactiveInterval() {
int interval = 3600;
this.validate(session -> session.setMaxInactiveInterval(interval));
SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
Batcher<Batch> batcher = mock(Batcher.class);
BatchContext context = mock(BatchContext.class);
SessionMetaData metaData = mock(SessionMetaData.class);
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
when(this.session.getMetaData()).thenReturn(metaData);
this.adapter.setMaxInactiveInterval(interval);
verify(metaData).setMaxInactiveInterval(Duration.ofSeconds(interval));
verify(context).close();
}
use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.
the class DistributableSessionTestCase method setNullAttribute.
@Test
public void setNullAttribute() {
String name = "name";
Object value = null;
this.validate(session -> session.setAttribute(name, value));
SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
Batcher<Batch> batcher = mock(Batcher.class);
BatchContext context = mock(BatchContext.class);
SessionAttributes attributes = mock(SessionAttributes.class);
SessionListener listener = mock(SessionListener.class);
SessionListeners listeners = new SessionListeners();
listeners.addSessionListener(listener);
Object expected = new Object();
when(this.session.getAttributes()).thenReturn(attributes);
when(attributes.removeAttribute(name)).thenReturn(expected);
when(this.manager.getSessionListeners()).thenReturn(listeners);
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
Object result = this.adapter.setAttribute(name, value);
assertSame(expected, result);
verify(listener, never()).attributeAdded(this.adapter, name, value);
verify(listener, never()).attributeUpdated(same(this.adapter), same(name), same(value), any());
verify(listener).attributeRemoved(this.adapter, name, expected);
verify(context).close();
}
use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.
the class DistributableSessionTestCase method setNewAttribute.
@Test
public void setNewAttribute() {
String name = "name";
Integer value = Integer.valueOf(1);
this.validate(session -> session.setAttribute(name, value));
SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
Batcher<Batch> batcher = mock(Batcher.class);
BatchContext context = mock(BatchContext.class);
SessionAttributes attributes = mock(SessionAttributes.class);
SessionListener listener = mock(SessionListener.class);
SessionListeners listeners = new SessionListeners();
listeners.addSessionListener(listener);
Object expected = null;
when(this.session.getAttributes()).thenReturn(attributes);
when(attributes.setAttribute(name, value)).thenReturn(expected);
when(this.manager.getSessionListeners()).thenReturn(listeners);
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
Object result = this.adapter.setAttribute(name, value);
assertSame(expected, result);
verify(listener).attributeAdded(this.adapter, name, value);
verify(listener, never()).attributeUpdated(same(this.adapter), same(name), same(value), any());
verify(listener, never()).attributeRemoved(same(this.adapter), same(name), any());
verify(context).close();
}
Aggregations