-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #6752 - Extensible DefaultSessionCache map implementation #6758
Issue #6752 - Extensible DefaultSessionCache map implementation #6758
Conversation
@prenagha an additional constructor to this PR could be added to allow for some late construction of the map. But I'm not sure if it's worth the effort. /**
* @param manager The SessionHandler related to this SessionCache
* @param sessionMapSupplier The supplier of the session map implementation to use (to allow for late binding)
*/
public DefaultSessionCache(SessionHandler manager, java.util.function.Supplier<ConcurrentMap<String,Session>> sessionMapSupplier)
{
this(manager, sessionMapSupplier.get());
} which would allow your example to work like ... public class SessionExpiringNearCache extends DefaultSessionCache {
public SessionNearCache(SessionHandler manager) {
super(manager, () -> Caffeine.newBuilder()
.expireAfterAccess(15, TimeUnit.MINUTES)
.build());
}
} or just use the DefaultSessionCache directly, no extends ... DefaultSessionCache sessionCache = new DefaultSessionCache(sessionHandler,
() -> Caffeine.newBuilder().expireAfterAccess(15, TimeUnit.MINUTES).build()); or (if using jgroups for example) DefaultSessionCache sessionCache = new DefaultSessionCache(sessionHandler, new ReplicatedHashMap<>(jgroupsChannel)); |
@joakime Constructor approach looks good. Not sure if you all ever do null checking, but might be a good idea to add to the constructor that takes the map
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you get rid of the "this", I'll approve this.
{ | ||
super(manager); | ||
this._sessions = sessionMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._sessions = sessionMap; | |
_sessions = sessionMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so whilst we are picking nits... the field and argument names should both be the same. either _sessions = sessions
or _sessionMap = sessionMap
. Since the field is protected, it is kind of part of the class contract, so I guess it can't be renamed.
@joakime I'm definitely not interested in making the constructor any more complicated than just simply passing in an arg of type ConcurrentMap because it is just not worth it. But I am interested in either the addition of the Objects.requireNonNull check in the constructor, or a null check in the doStart() method (good catch @prenagha). |
{ | ||
this(manager, new ConcurrentHashMap<>()); | ||
} | ||
|
||
/** | ||
* @param manager The SessionHandler related to this SessionCache | ||
* @param sessionMap The session map implementation to use | ||
*/ | ||
public DefaultSessionCache(SessionHandler manager, ConcurrentMap<String, Session> sessionMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other option to avoid null issues is:
{ | |
this(manager, new ConcurrentHashMap<>()); | |
} | |
/** | |
* @param manager The SessionHandler related to this SessionCache | |
* @param sessionMap The session map implementation to use | |
*/ | |
public DefaultSessionCache(SessionHandler manager, ConcurrentMap<String, Session> sessionMap) | |
{ | |
this(manager, null); | |
} | |
/** | |
* @param manager The SessionHandler related to this SessionCache | |
* @param sessionMap The session map implementation to use | |
*/ | |
protected DefaultSessionCache(SessionHandler manager, ConcurrentMap<String, Session> sessionMap) | |
{ | |
super(manager); | |
_sessions = sessionMap == null ? new ConcurrentHashMap() : sessionMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also make this constructor protected
@joakime is this ready for re-review yet? |
how is this still conflicting?? |
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Addressing changes requested from review Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
bff69b3
to
8991b7f
Compare
@janbartel this PR is ready for a review |
@Override | ||
protected void doStart() throws Exception | ||
{ | ||
Objects.requireNonNull(_sessions, "Session Map may not be null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check shouldn't be necessary: _sessions
is final
&& the constructor at line 51 ensures a non-null map && the other constructor at line 61 rejects nulls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just removed the entire doStart()
More changes requested from review Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Alternate approach to PR #6753 from @prenagha
Closes #6752
Signed-off-by: Joakim Erdfelt joakim.erdfelt@gmail.com