For some reason there's a classLoader problem when using embedded Hazelcast. I saw this being mentioned by Steve several times on Hazelcast forums in older version. It's probably due to the fact that Hazelcast is loaded by felix, correct?
A workaround is to use the hazelcast classloader when summoning the cache. This helps a bit because instead of
PortableFactory[-23] is already registered! com.hazelcast.mapreduce.impl.MapReducePortableHook$1@2d51402b -> com.hazelcast.mapreduce.impl.MapReducePortableHook$1@1aba6664
the hazelcast alone works.
This is the workaround
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(Hazelcast.class.getClassLoader());
HazelcastInstance theInstance = Hazelcast.newHazelcastInstance(hazelcastConfig);
Thread.currentThread().setContextClassLoader(classLoader);
However, when I do the workaround my application classed like my own POJOs or subzero are not on the correct classpath
Factory method 'getHazelcastInstance' threw exception; nested exception is com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: info.jerrinot.subzero.Serializer not found by com.hazelcas
t [26]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5985)
at com.sun.enterprise.web.WebModule.start(WebModule.java:692)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
I would like to make this work using embedded hazelcast or turn off the embedded version completely! I don't know how, though. When I use the admin console and set enabled and dynamic options to false it doesn't help. The dynamic option is always set to true :(
How to successfully turn off the embedded Hazelcast and use the one provided in my war application file? This way I will be using the version I want, which is 3.7.4. Then I expect no class loader problem. I verified this on Websphere and it's working.
Second possible solution... how to make hazelcast see my own classed in its classloader?
a very personal and possibly inappropriate note:
Payara + Hazelcast + SubZero in a single stack. That's music to my ears! :)
I think that a solution for #759 would be a solution for this issue too.
The embedded Hazelcast should be disabled by default on Payara Server. You can have problems because the classloader prefers embedded Hazelcast classes rather than the classes in your application (the default behavior). You can prioritize the classes in your app over the ones in the server - see the Payara classloading documentation.
You might be able to use SubZero with the embedded Hazelcast, if you drop the SubZero library into the domain, into the domain_dir/lib directory. It will then be loaded by the server classloader on the same level as embedded Hazelcast.
Also, if subzero .jar have proper OSGi manifest, you can deploy it as OSGi application to have same effect like dropping into domain_dir/lib, but with less file locks on Windows.
It probably would hava worked to add subzero into domain/lib but what actually worked for me was
<class-loader delegate="false" />
and now Payara uses my own libs first, which is what I wanted. Thanks!
Most helpful comment
It probably would hava worked to add subzero into domain/lib but what actually worked for me was
and now Payara uses my own libs first, which is what I wanted. Thanks!