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

Fix for context classloader issue #58

Merged
merged 2 commits into from
Mar 8, 2019

Conversation

alparslanavci
Copy link
Contributor

Fixes #55.

This fix moves the initialization of the Hazelcast member instance on P2P mode to the startup of HazelcastSessionManager in order to access the context classloader. Please note that there might be still an issue if the context classloader changes dynamically, since Hazelcast doesn't allow to update the classloader after the initialization of the instance.

@alparslanavci alparslanavci requested a review from mesutcelik March 7, 2019 16:04
@@ -1,3 +1,7 @@
/*
* Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.

Choose a reason for hiding this comment

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

Can you please update to 2019?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checkstyle's class header is set as 2016, I needed to keep it as it is to make it pass from the checks. I will send another PR for updating all headers.

instance = Hazelcast.getOrCreateHazelcastInstance(P2PLifecycleListener.getConfig());
}
instance = HazelcastInstanceFactory.
getHazelcastInstance(getContainer().getLoader().getClassLoader(), isClientOnly(), getHazelcastInstanceName());

Choose a reason for hiding this comment

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

is this WebAppClassloader that is returned?

Choose a reason for hiding this comment

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

I mean by getContainer().getLoader().getClassLoader()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I double checked.

*/
Config config = P2PLifecycleListener.getConfig();
config.setClassLoader(classLoader);
instance = Hazelcast.getOrCreateHazelcastInstance(config);

Choose a reason for hiding this comment

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

if instanceName is null then is there any advantage using Hazelcast.getOrCreateHazelcastInstance? Can't we just start an instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is still possibility for the Hazelcast instance to be up and running even that the instanceName is null. If the instance name is set in the Hazelcast config, then the instanceName variable will be null but there will be still a running Hazelcast instance.

Choose a reason for hiding this comment

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

I see this is too confusing. We really need to check why we have a separate hazelcastInstanceName apart from hazelcast configuration... READMe is not clear too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is because we have a SessionManager.DEFAULT_INSTANCE_NAME to bring back the existing instance, if the user doesn't set up a instance name in the config. Yes, it is a bit confusing, I can try to clarify in the readme.

/*
Note that Hazelcast instance can only set a classloader during the initialization. If the context classloader
changes after the initialization of the Hazelcast instance, it cannot be changed for the Hazelcast instance.
*/

Choose a reason for hiding this comment

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

so does that mean that if there is hazelcast instance in the VM and classloader is not somehow set to WebAppClassloader then there will be an issue.

We might need to clarify this in the readme.... Also isn't this comment for instanceName != null branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that means if there is Hazelcast instance in the VM and classloader is not set to WebAppClassloader then there will be an issue.

If instanceName != null, Hazelcast instance should be already up and running, thus you cannot change the classloader. So; yes, it is also the same case for that branch. But I didn't put the comment there since we don't even try to set the classloader over there.

Copy link

@mesutcelik mesutcelik left a comment

Choose a reason for hiding this comment

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

👍 It would be good to update README based on comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClassNotFoundException when deserializing session
2 participants