I have two tomcat servers in my local machine and "n" wars at each server.
I want to have just One Instance of Hazelcast by server, but i just get 1 instance by WAR, also using a Singleton Wrapper because this singletton is "attached" to WAR Classloader....
Any easy way to do this ?
One Hazelcast instance by Tomcat Server (want to use the same approach in Oracle Weblogic), and a shared hazelcast instance along all war into the same server. Just one node by JVM
Those Hazelcast instances joining to one and just one cluster.
One thing i don't get sense it is that if i create a HazelCast Instance in one WAR, and try to get in another one , this is null..being the same process (JVM ...) .
Something like this:
@Slf4j
public class MyCustomHazelCastManager {
public static void debugInstances() {
Set<HazelcastInstance> debugginIsntances = Hazelcast.getAllHazelcastInstances();
log.debug("Current Instances:" + debugginIsntances.size());;
for (HazelcastInstance i : debugginIsntances ) {
log.debug(i.getName());
}
}
public static HazelcastInstance getInstance() {
log.debug("MyCustomHazelCastManager.getInstance() for {}" , ManagementFactory.getRuntimeMXBean().getName());
HazelcastInstance instance =
Hazelcast.getHazelcastInstanceByName(ManagementFactory.getRuntimeMXBean().getName());
if (instance == null) {
Config config = new Config();
log.debug("RuntimeProcess ID :" +ManagementFactory.getRuntimeMXBean().getName());
config.setInstanceName(ManagementFactory.getRuntimeMXBean().getName());
instance = Hazelcast.newHazelcastInstance(config);
log.debug("Create Hazelcast instance with name:"+ ManagementFactory.getRuntimeMXBean().getName() );
} else {
System.out.println("\n\n Warning ! there is one instance with name :{}"+ManagementFactory.getRuntimeMXBean().getName());
}
return instance;
}
}
Why doesn't work Hazelcast.getHazelcastInstanceByName() ??????
UPDATED:
If HazelCast library is put on Tomcat Classpath, (lib directory for example) works fine.
So , I have deduced that for get a Hazelcast instance is used the active process and the classloader used by Hazelcast objects. If in a different WARs deployed on Tomcat (on the same virtual machine ), having this wars different Hazelcast libraries ( by WAR ) Hazelcast will attempt to create new instances, even if it is the same process