Running Hazelcast in multiple WARs within Tomcat and configuration isolation

745 views
Skip to first unread message

Jeff Trimm

unread,
Jun 14, 2010, 10:02:25 AM6/14/10
to Hazelcast
I am initializing Hazelcast with a custom config file as below:

public static HazelcastInstance
newHazelcastInstanceFromXmlString(final String
hazelcastXmlStringConfig) {
if (!StringUtils.isEmpty(hazelcastXmlStringConfig)) {
InputStream in = null;
try {
in = new
ByteArrayInputStream(hazelcastXmlStringConfig.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("A fatal error has
occurred in the bytestream marshalling of the Hazelcast string
config.");
}
return Hazelcast.newHazelcastInstance(new
XmlConfigBuilder(in).build());
} else {
throw new IllegalArgumentException("The Hazelcast config
file path has not been set.");
}
}


How isolated is Hazelcast and a specific Hazelcast configuration
within the WAR classloader in a Tomcat instance? We have use cases
where multiple WAR's within a Tomcat instance (where a WAR would be a
particular web service in this use case) would have completely
independent Hazelcast configurations (different clusters, different
Map caches, etc.). IE. the desire would be to initialize Hazelcast
like above with a different config XML for each WAR. Is this possible
with Hazelcast?

Also, in this use case, if running multiple different Hazelcast
instances (one in each of multiple WAR's) what is the expected
behavior when doing a Hazelcast.shutdown() vs.
Hazelcast.shutdownAll() ? Would the ServletContextListener want to
call Hazelcast.shutdown() when stopping/reloading a WAR or
Hazelcast.shutdownAll()? Thanks!

-Jeff

Mehmet Dogan

unread,
Jun 14, 2010, 11:34:37 AM6/14/10
to haze...@googlegroups.com
Yes possible. You can configure different Hazelcast instances in a single JVM with completely different/independent configurations. 
There are just few classloader-static references, but they do not break the isolation. 
If you are using latest distro, you can use one of these shorthands;

Hazelcast.newHazelcastInstance(new ClasspathXmlConfig("foo/bar/hazelcast1.xml"))
Hazelcast.newHazelcastInstance(new FileSystemXmlConfig("/foo/bar/hazelcast2.xml"))
Hazelcast.newHazelcastInstance(new UrlXmlConfig(url))
Hazelcast.newHazelcastInstance(new InMemoryXmlConfig(xmlString))

These also applies to your Tomcat scenario. 
Hazelcast.shutdown always shuts down the 'default instance'.
HazelcastInstance always shuts down just calling instance.

If your hazelcast.jar in server classpath, Hazelcast.shutdownAll() shuts down all instances in Tomcat (JVM) (including default one),  
If your hazelcast.jar in web-application classpath, Hazelcast.shutdownAll() shuts down all instances started from that web-application (including default one).
 


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.


Jeff Trimm

unread,
Jun 14, 2010, 2:19:42 PM6/14/10
to Hazelcast
Fantastic... BTW, is Hazelcast 1.8.5-SNAPSHOT available from a public
maven repo?

-Jeff

Talip Ozturk

unread,
Jun 14, 2010, 5:38:49 PM6/14/10
to haze...@googlegroups.com
Public maven repo doesn't accept SNAPSHOTs but you can download it from
http://www.hazelcast.com/downloads.jsp

twitter @oztalip

nagaraj L M

unread,
Dec 15, 2013, 1:57:10 PM12/15/13
to haze...@googlegroups.com
Good explaination,but how to add jar to tomcat classpath and how to use those in webapp....?
Reply all
Reply to author
Forward
0 new messages