Documentation for the Hazelcast module
This module is a
dropinreplacement for EhCacheImpl or MemcachedImpl from Play.
It allow your application to have a clustered cache when you can’t install a memcached server on your platform.
It’s also a great free open source In-Memory Data Grid
See Hazelcast Documentation for more details.
Installing Hazelcast Module
To install Hazelcast Plugin module, you do like every other Play Modules:
play install hazelcast[-version]
Using Hazelcast Module in your application (Dependency management)
There is two way to use the module
- The Play 1.x way (in application.conf)
- The Play 1.2.x way (in dependencies.yml)
require: - play -> hazelcast [version]
You can disable the module in your application by using a parameter in
The value defaults to false.
You can specify the configuration file to be used. The value defaults to conf/hazelcast.xml
Using standard Play! Framework Cache Mechanisms
All the standard Play annotations or methods work seamlessly with Hazelcast instead of EhCache or Memcached.
See Play Framework Cache Documentation for
CacheFor("1h")and provided Play!
Using features from Hazelcast
Using @Inject to inject an instance of Hazelcast in your controller
@Inject private static HazelcastInstance hazel;
Injecting the default ExecutorService
@Inject private static ExecutorService executor;
Using @Named to inject a named resource
@Named("MyQueue") private static Queue myQueue;
Hazelcast clustered services
- Distributed Queues (Entries are consumed by one and only one JVM)
- Distributed Topics (Entries are consumed by all JVM)
- Distributed Events
- Distributed AtomicNumber provider
- Distributed ExecutorService
- Distributed ID Generator (ID are UNIQUE in all cluster nodes)
- Distributed List (to share a list in the cluster between many JVM)
- Distributed Lock (to apply a lock on an object and share between JVM)
- Distributed Set
- Distributed Map/MultiMap (Maps are shared between JMV, MultiMap allow for multiple values for the same key)
- Distributed Transaction (affect transactions on clustered objects, not database!)
Configuration file hazelcast.xml
You can modify hazelcast.xml to your need to create more Queues or Map and modify the default ExecutorService parameters. Just copy the hazelcast.xml file from the module conf directory to your application conf directory. This is also the file that allow you to change from multicast to TCPIP static cluster definition.
Hazelcast Object type that can be retreived via @@Named@ annotation
Hazelcast Object type that can by retreived via @@Inject@ annotation
Method directly accessible on
1 Use this to get a Transaction object then you can
rollback() operations on cluster.
2 Use this to lock an object across the cluster.
3 Use this if you absolutly NEED to directly get the Default Hazelcast instance.
Hibernate second level cache configuration
# Application dependencies
- play -> hazelcast 0.4
- com.hazelcast -> hazelcast-hibernate 18.104.22.168
- Entity class annotation
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = “model”)
- hazelcast.xml – add following map definition
I’d like to see some basic Play! features use Hazel capabilities: