org.springframework.session.events.AbstractSessionEvent Java Examples

The following examples show how to use org.springframework.session.events.AbstractSessionEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SessionEventHttpSessionListenerAdapter.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
	if (this.listeners.isEmpty()) {
		return;
	}

	HttpSessionEvent httpSessionEvent = createHttpSessionEvent(event);

	for (HttpSessionListener listener : this.listeners) {
		if (event instanceof SessionDestroyedEvent) {
			listener.sessionDestroyed(httpSessionEvent);
		}
		else if (event instanceof SessionCreatedEvent) {
			listener.sessionCreated(httpSessionEvent);
		}
	}
}
 
Example #2
Source File: SessionEventsListener.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
    if (event instanceof SessionCreatedEvent) {
        sessionCreatedEvents++;
    }
    if (event instanceof SessionDeletedEvent) {
        sessionDeletedEvents++;
    }
    if (event instanceof SessionExpiredEvent) {
        sessionExpiredEvents++;
    }
}
 
Example #3
Source File: SessionEventRegistry.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
	String sessionId = event.getSessionId();
	this.events.put(sessionId, event);
	Object lock = getLock(sessionId);
	synchronized (lock) {
		lock.notifyAll();
	}
}
 
Example #4
Source File: SessionEventRegistry.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <E extends AbstractSessionEvent> E waitForEvent(String sessionId) throws InterruptedException {
	Object lock = getLock(sessionId);
	synchronized (lock) {
		if (!this.events.containsKey(sessionId)) {
			lock.wait(10000);
		}
	}
	return (E) this.events.get(sessionId);
}
 
Example #5
Source File: SessionEventRegistry.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(AbstractSessionEvent event) {
	String sessionId = event.getSessionId();
	this.events.put(sessionId, event);
	Object lock = getLock(sessionId);
	synchronized (lock) {
		lock.notifyAll();
	}
}
 
Example #6
Source File: SessionEventRegistry.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <E extends AbstractSessionEvent> E waitForEvent(String sessionId) throws InterruptedException {
	Object lock = getLock(sessionId);
	synchronized (lock) {
		if (!this.events.containsKey(sessionId)) {
			lock.wait(10000);
		}
	}
	return (E) this.events.get(sessionId);
}
 
Example #7
Source File: SessionExpirationIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Test
public void sessionExpirationIsCorrect() {

	Session session = this.sessionRepository.createSession();

	assertThat(session).isNotNull();
	assertThat(session.getId()).isNotBlank();
	assertThat(session.isExpired()).isFalse();

	this.sessionRepository.save(session);

	Session savedSession = this.sessionRepository.findById(session.getId());

	assertThat(savedSession).isEqualTo(session);

	// Clear any existing Session event
	this.sessionEventListener.getSessionEvent();

	AbstractSessionEvent sessionEvent =
		this.sessionEventListener.waitForSessionEvent(TimeUnit.SECONDS.toMillis(2));

	assertThat(sessionEvent).isNotNull();
	assertThat(sessionEvent.getSessionId()).isEqualTo(savedSession.getId());
	assertThat(this.sessionRepository.findById(savedSession.getId())).isNull();
}
 
Example #8
Source File: SessionExpirationIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
public void onApplicationEvent(AbstractSessionEvent event) {
	this.sessionEvent = event;
}
 
Example #9
Source File: SessionEventHttpSessionListenerAdapter.java    From spring-session with Apache License 2.0 4 votes vote down vote up
private HttpSessionEvent createHttpSessionEvent(AbstractSessionEvent event) {
	Session session = event.getSession();
	HttpSession httpSession = new HttpSessionAdapter<>(session, this.context);
	return new HttpSessionEvent(httpSession);
}
 
Example #10
Source File: SessionEventRegistry.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
<E extends AbstractSessionEvent> E getEvent(String sessionId) throws InterruptedException {
	return (E) waitForEvent(sessionId);
}
 
Example #11
Source File: SessionEventRegistry.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <E extends AbstractSessionEvent> E getEvent(String sessionId) throws InterruptedException {
	return (E) waitForEvent(sessionId);
}
 
Example #12
Source File: SessionExpirationIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 3 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends AbstractSessionEvent> T getSessionEvent() {

	T sessionEvent = (T) this.sessionEvent;

	this.sessionEvent = null;

	return sessionEvent;
}
 
Example #13
Source File: SessionExpirationIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 2 votes vote down vote up
public <T extends AbstractSessionEvent> T waitForSessionEvent(long duration) {

			waitOn(() -> SessionEventListener.this.sessionEvent != null, duration);

			return getSessionEvent();
		}