Skip to content
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

Merged
merged 3 commits into from Sep 15, 2021

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Sep 9, 2021

Alternate approach to PR #6753 from @prenagha

Closes #6752

Signed-off-by: Joakim Erdfelt joakim.erdfelt@gmail.com

@joakime
Copy link
Contributor Author

joakime commented Sep 9, 2021

@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));

@prenagha
Copy link
Contributor

prenagha commented Sep 9, 2021

@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

Objects.requireNonNull(sessionMap, "Session Map is required");

Copy link
Contributor

@janbartel janbartel left a 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this._sessions = sessionMap;
_sessions = sessionMap;

Copy link
Contributor

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.

Jetty 10.0.7/11.0.7 FROZEN automation moved this from In progress to Review in progress Sep 10, 2021
@janbartel
Copy link
Contributor

@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).

Comment on lines 49 to 57
{
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)
Copy link
Contributor

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:

Suggested change
{
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;

Copy link
Contributor

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

@janbartel
Copy link
Contributor

@joakime is this ready for re-review yet?

@joakime
Copy link
Contributor Author

joakime commented Sep 15, 2021

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>
@joakime joakime force-pushed the jetty-10.0.x-extensible-default-session-cache branch from bff69b3 to 8991b7f Compare September 15, 2021 01:24
@joakime
Copy link
Contributor Author

joakime commented Sep 15, 2021

@janbartel this PR is ready for a review

@Override
protected void doStart() throws Exception
{
Objects.requireNonNull(_sessions, "Session Map may not be null");
Copy link
Contributor

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.

Copy link
Contributor Author

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>
Jetty 10.0.7/11.0.7 FROZEN automation moved this from Review in progress to Reviewer approved Sep 15, 2021
@joakime joakime merged commit 51f6a58 into jetty-10.0.x Sep 15, 2021
Jetty 10.0.7/11.0.7 FROZEN automation moved this from Reviewer approved to Done Sep 15, 2021
@joakime joakime deleted the jetty-10.0.x-extensible-default-session-cache branch September 15, 2021 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

DefaultSessionCache more extensible using ConcurrentMap
4 participants