Skip to content

Session creation with pre-specified id. #1545

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

Closed
wants to merge 6 commits into from

Conversation

zapp88
Copy link

@zapp88 zapp88 commented Nov 12, 2019

This pull request address specific use-case of creating session with pre-specified id.

While standard SessionRepository interfaces provides means of creating session via createSession() - it does noting to let you control the 'id' creation process. All known to me implementation of SessionRepository (Redis,Hazelcast,Jdbc) fallback to calling MapSession and what is peculiar MapSession supports creating session object with externally defined id - via its secondary construtor - new MapSession(id).

However all implementations (Redis,Hazelcast,Jdbc) fallback to using the default construtor which in its default bahaviour calls UUID.randomUUID().toString(). While this provides necessary uniqueness to id (provied low probability of UUID ever repeating) it leaves us without controll over this process.

There are quite a few business casses when internaly created id would not be desired :

  1. UUID randomnes not meeting business criteria
  2. Integration with existing session managment systems where id creation is delegated to external system

We don't want to break any existing functionality (keeping SessionRepository as clean as possible) - here comes CreateWithIdSessionRepository - it expands default implementation with ability to create session with pre-specified id via S createSession(@Nullable String id);
the same way FindByIndexNameSessionRepository expands session repository with ability to find session with principal/indexName.

I took upon myself implementing this interfaces in 3 most common used implementations (Redis,Hazelcast,Jdbc) since it does not break any existing functionality while still providing benefit on controlling this process by adhering to proper interface.

There are no reasons it could not be supported in other available implementations.

PS. Sorry for my english. English is not my primary language.
If you have any suggestions on how i could improve my approach or would like to ask me a question - feel free to contact me. My email - [email protected]

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 12, 2019
@zapp88
Copy link
Author

zapp88 commented Nov 12, 2019

While i'm aware of MR: #204 . Original author is inactive for last 5 years, and there are merge conflicts - which i don't think he will resolve any time soon. This feature is on general backlog since 30 Jan. And while this MR does things differently (not-strategy approach) it provides sollution that does not collide with future strategy-way of handling things.

@zapp88
Copy link
Author

zapp88 commented Nov 14, 2019

I've added second MR : #1547 if this one is not an acceptable way of handling things.

@zapp88 zapp88 changed the title Session creation with pre-specified id. WIP:Session creation with pre-specified id. Nov 14, 2019
@zapp88 zapp88 changed the title WIP:Session creation with pre-specified id. Session creation with pre-specified id. Nov 14, 2019
@ldmara
Copy link

ldmara commented Feb 27, 2020

Are there any plans to have this kind of feature in the release version? Integration with existing session management systems where id creation is delegated to external system is a very useful feature.


@Override
public RedisSession createSession(final String id) {
MapSession cached = Optional.ofNullable(id).map(MapSession::new).orElse(new MapSession());
Copy link

Choose a reason for hiding this comment

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

It's better to use .orElseGet(MapSession::new) to avoid creating an unnecessary object if id is provided.

}

@Override
public RedisSession createSession(final String id) {
Copy link

Choose a reason for hiding this comment

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

final is here redundant, it's not used in other methods.

@SMakhrov
Copy link

@zapp88 hi!
Thank you so much for this PR! When it will be merged? I'm really need in this feature.

@danparisi
Copy link

I'd also like to have this feature place. When is it going to be merged?

}

@Override
public HazelcastSession createSession(final String id) {
Copy link

Choose a reason for hiding this comment

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

please make the HazelcastSession public, so that can override

@marcusdacoregio
Copy link
Contributor

Closing in favor of #2286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants