Skip to content

Commit 6a6d60d

Browse files
committed
Improve session event handling
Closes gh-984
1 parent b2cb3f6 commit 6a6d60d

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

spring-session/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -518,27 +518,29 @@ public void onMessage(Message message, byte[] pattern) {
518518

519519
RedisSession session = getSession(sessionId, true);
520520

521+
if (session == null) {
522+
logger.warn("Unable to publish SessionDestroyedEvent for session "
523+
+ sessionId);
524+
}
525+
521526
if (logger.isDebugEnabled()) {
522527
logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
523528
}
524529

525530
cleanupPrincipalIndex(session);
526531

527532
if (isDeleted) {
528-
handleDeleted(sessionId, session);
533+
handleDeleted(session);
529534
}
530535
else {
531-
handleExpired(sessionId, session);
536+
handleExpired(session);
532537
}
533538

534539
return;
535540
}
536541
}
537542

538543
private void cleanupPrincipalIndex(RedisSession session) {
539-
if (session == null) {
540-
return;
541-
}
542544
String sessionId = session.getId();
543545
String principal = PRINCIPAL_NAME_RESOLVER.resolvePrincipal(session);
544546
if (principal != null) {
@@ -553,22 +555,12 @@ public void handleCreated(Map<Object, Object> loaded, String channel) {
553555
publishEvent(new SessionCreatedEvent(this, session));
554556
}
555557

556-
private void handleDeleted(String sessionId, RedisSession session) {
557-
if (session == null) {
558-
publishEvent(new SessionDeletedEvent(this, sessionId));
559-
}
560-
else {
561-
publishEvent(new SessionDeletedEvent(this, session));
562-
}
558+
private void handleDeleted(RedisSession session) {
559+
publishEvent(new SessionDeletedEvent(this, session));
563560
}
564561

565-
private void handleExpired(String sessionId, RedisSession session) {
566-
if (session == null) {
567-
publishEvent(new SessionExpiredEvent(this, sessionId));
568-
}
569-
else {
570-
publishEvent(new SessionExpiredEvent(this, session));
571-
}
562+
private void handleExpired(RedisSession session) {
563+
publishEvent(new SessionExpiredEvent(this, session));
572564
}
573565

574566
private void publishEvent(ApplicationEvent event) {

0 commit comments

Comments
 (0)