org.springframework.session.events.SessionDeletedEvent Java Examples

The following examples show how to use org.springframework.session.events.SessionDeletedEvent. 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: FixedMapSessionRepository.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 6 votes vote down vote up
private void deleteAndFireEvent(final String id, boolean expired)
{
	final ExpiringSession deletedSession = sessions.remove(id);

	// Fire event
	if (deletedSession != null)
	{
		if (expired)
		{
			applicationEventPublisher.publishEvent(new SessionExpiredEvent(this, id));
		}
		else
		{
			applicationEventPublisher.publishEvent(new SessionDeletedEvent(this, id));
		}
	}
}
 
Example #2
Source File: SessionEventHazelcastIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Test
void deletedSessionTest() throws InterruptedException {
	S sessionToSave = this.repository.createSession();

	this.repository.save(sessionToSave);

	assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
	assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
			.isInstanceOf(SessionCreatedEvent.class);
	this.registry.clear();

	this.repository.deleteById(sessionToSave.getId());

	assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
	assertThat(this.registry.<SessionDeletedEvent>getEvent(sessionToSave.getId()))
			.isInstanceOf(SessionDeletedEvent.class);

	assertThat(this.repository.findById(sessionToSave.getId())).isNull();
}
 
Example #3
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 #4
Source File: WebSocketRegistryListenerTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	MockitoAnnotations.initMocks(this);
	String sessionId = "session-id";
	MapSession session = new MapSession(sessionId);

	this.attributes = new HashMap<>();
	SessionRepositoryMessageInterceptor.setSessionId(this.attributes, sessionId);

	given(this.wsSession.getAttributes()).willReturn(this.attributes);
	given(this.wsSession.getPrincipal()).willReturn(this.principal);
	given(this.wsSession.getId()).willReturn("wsSession-id");

	given(this.wsSession2.getAttributes()).willReturn(this.attributes);
	given(this.wsSession2.getPrincipal()).willReturn(this.principal);
	given(this.wsSession2.getId()).willReturn("wsSession-id2");

	Map<String, Object> headers = new HashMap<>();
	headers.put(SimpMessageHeaderAccessor.SESSION_ATTRIBUTES, this.attributes);
	given(this.message.getHeaders()).willReturn(new MessageHeaders(headers));

	this.listener = new WebSocketRegistryListener();
	this.connect = new SessionConnectEvent(this.listener, this.wsSession);
	this.connect2 = new SessionConnectEvent(this.listener, this.wsSession2);
	this.disconnect = new SessionDisconnectEvent(this.listener, this.message, this.wsSession.getId(),
			CloseStatus.NORMAL);
	this.deleted = new SessionDeletedEvent(this.listener, session);
	this.expired = new SessionExpiredEvent(this.listener, session);
}
 
Example #5
Source File: HazelcastIndexedSessionRepository.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public void entryRemoved(EntryEvent<String, MapSession> event) {
	MapSession session = event.getOldValue();
	if (session != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Session deleted with id: " + session.getId());
		}
		this.eventPublisher.publishEvent(new SessionDeletedEvent(this, session));
	}
}
 
Example #6
Source File: RedisIndexedSessionRepository.java    From spring-session with Apache License 2.0 4 votes vote down vote up
private void handleDeleted(RedisSession session) {
	publishEvent(new SessionDeletedEvent(this, session));
}