本文整理汇总了Java中io.undertow.server.session.SessionListener类的典型用法代码示例。如果您正苦于以下问题:Java SessionListener类的具体用法?Java SessionListener怎么用?Java SessionListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SessionListener类属于io.undertow.server.session包,在下文中一共展示了SessionListener类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stop
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Override
public void stop() {
for (Map.Entry<String, SessionImpl> session : sessions.entrySet()) {
session.getValue().destroy();
sessionListeners.sessionDestroyed(session.getValue(), null, SessionListener.SessionDestroyedReason.UNDEPLOY);
}
sessions.clear();
this.cacheManager.stop();
}
示例2: run
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Override
public void run() {
worker.execute(new Runnable() {
@Override
public void run() {
long currentTime = System.currentTimeMillis();
if(currentTime >= expireTime) {
invalidate(null, SessionListener.SessionDestroyedReason.TIMEOUT);
} else {
timerCancelKey = executor.executeAfter(cancelTask, expireTime - currentTime, TimeUnit.MILLISECONDS);
}
}
});
}
示例3: invalidate
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Override
public void invalidate(final HttpServerExchange exchange) {
invalidate(exchange, SessionListener.SessionDestroyedReason.INVALIDATED);
if(exchange != null) {
exchange.removeAttachment(sessionManager.NEW_SESSION);
}
}
示例4: configureSessionManager
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
protected void configureSessionManager(SessionManager sessionManager , List<Class<?>> annotatedSessionListeners ){
SessionListenerMounter mounter = new SessionListenerMounterImpl();
for (Class<?> annotatedClass : annotatedSessionListeners) {
SessionListener sl = mounter.mount(annotatedClass);
if(sl != null){
sessionManager.registerSessionListener( sl);
}
}
}
示例5: doesCreateSessionListenerAndInvokeOnCreateAnnotatedMethodsOnSessionCreation
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Test
public void doesCreateSessionListenerAndInvokeOnCreateAnnotatedMethodsOnSessionCreation(){
SessionListener sl = mounter.mount(TestSessionListener.class);
sl.sessionCreated( mock(Session.class) , NULL_EXCHANGE );
assertSame( 1 , TestSessionListener.onCreateCallCounter );
assertSame( 0 , TestSessionListener.onDestroyCallCounter );
}
示例6: doesCreateSessionListenerAndInvokeOnDestroyAnnotatedMethodsOnSessionDestruction
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Test
public void doesCreateSessionListenerAndInvokeOnDestroyAnnotatedMethodsOnSessionDestruction(){
SessionListener sl = mounter.mount(TestSessionListener.class);
sl.sessionDestroyed( mock(Session.class) , NULL_EXCHANGE , SessionDestroyedReason.TIMEOUT );
assertSame( 1 , TestSessionListener.onDestroyCallCounter );
assertSame( 0 , TestSessionListener.onCreateCallCounter );
}
示例7: addSessionListener
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
public DeploymentInfo addSessionListener(SessionListener sessionListener) {
this.sessionListeners.add(sessionListener);
return this;
}
示例8: getSessionListeners
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
public List<SessionListener> getSessionListeners() {
return Collections.unmodifiableList(sessionListeners);
}
示例9: createSession
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Override
public Session createSession(final HttpServerExchange serverExchange, final SessionConfig config) {
if (evictionQueue != null) {
if(expireOldestUnusedSessionOnMax) {
while (sessions.size() >= maxSize && !evictionQueue.isEmpty()) {
String key = evictionQueue.poll();
UndertowLogger.REQUEST_LOGGER.debugf("Removing session %s as max size has been hit", key);
SessionImpl toRemove = sessions.get(key);
if (toRemove != null) {
toRemove.invalidate(null, SessionListener.SessionDestroyedReason.TIMEOUT); //todo: better reason
}
}
} else if(sessions.size() >= maxSize) {
if(statisticsEnabled) {
rejectedSessionCount.incrementAndGet();
}
throw UndertowMessages.MESSAGES.tooManySessions(maxSize);
}
}
if (config == null) {
throw UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig();
}
String sessionID = config.findSessionId(serverExchange);
int count = 0;
while (sessionID == null) {
sessionID = sessionIdGenerator.createSessionId();
if(sessions.containsKey(sessionID)) {
sessionID = null;
}
if(count++ == 100) {
//this should never happen
//but we guard against pathalogical session id generators to prevent an infinite loop
throw UndertowMessages.MESSAGES.couldNotGenerateUniqueSessionId();
}
}
Object evictionToken;
if (evictionQueue != null) {
evictionToken = evictionQueue.offerLastAndReturnToken(sessionID);
} else {
evictionToken = null;
}
if(statisticsEnabled) {
createdSessionCount.incrementAndGet();
}
final SessionImpl session;
if (sessions.containsKey(sessionID)) {
SessionImpl session1 = sessions.get(sessionID);
session = new SessionImpl(this, session1.sessionId, config, serverExchange.getIoThread(), serverExchange.getConnection().getWorker(), session1.evictionToken, defaultSessionTimeout, session1.attributes);
} else {
session = new SessionImpl(this, sessionID, config, serverExchange.getIoThread(), serverExchange.getConnection().getWorker(), evictionToken, defaultSessionTimeout);
}
sessions.put(sessionID, session);
config.setSessionId(serverExchange, session.getId());
session.lastAccessed = System.currentTimeMillis();
session.bumpTimeout();
sessionListeners.sessionCreated(session, serverExchange);
serverExchange.putAttachment(NEW_SESSION, session);
return session;
}
示例10: registerSessionListener
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Override
public synchronized void registerSessionListener(final SessionListener listener) {
sessionListeners.addSessionListener(listener);
}
示例11: removeSessionListener
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Override
public synchronized void removeSessionListener(final SessionListener listener) {
sessionListeners.removeSessionListener(listener);
}
示例12: doesCreateASessionListenerFromAGenericClass
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
@Test
public void doesCreateASessionListenerFromAGenericClass(){
SessionListener sl = mounter.mount(TestSessionListener.class);
assertNotNull(sl);
}
示例13: mount
import io.undertow.server.session.SessionListener; //导入依赖的package包/类
SessionListener mount(Class<?> annotatedClass);