Skip to content
Hazelcast is a dropin replacement for the Play! Framework cache. Hazelcast provide also some other services like Clustered Executors, Maps, AtomicNumbers, Topics, Queues, etc...
Java CSS HTML Python
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


Documentation for the Hazelcast module

This module is a dropin replacement 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)
	- play -> hazelcast [version]


You can disable the module in your application by usinga parameter in application.conf:


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.

  • CacheFor("1h")
  • Etc…

See Play Framework Cache Documentation for CacheFor("1h") and provided Play! usage.

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

  • Queue
  • Topic
  • AtomicNumber
  • ExecutorService
  • Set
  • Map
  • MultiMap
  • IdGenerator

Hazelcast Object type that can by retreived via @Inject annotation

  • Transaction
  • ExecutorService
  • PartitionService
  • Event

Method directly accessible on HazelcastPlugin class

  • HazelcastPlugin.getTransaction() 1
  • HazelcastPlugin.getLock(Object o) 2
  • HazelcastPlugin.getHazel() 3

1 Use this to get a Transaction object then you can begin() or commit() or rollback() operations on cluster.

2 Use this to lock an object across the cluster.

3 Use this if you absolutely NEED to directly get the Default Hazelcast instance.

Hibernate second level cache configuration

  • application.conf
  • dependencies.yml
    # Application dependencies
    - play
    - play -> hazelcast 0.4
    - com.hazelcast -> hazelcast-hibernate
  • Entity class annotation
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "model")
  • hazelcast.xml – add following map definition
    <map name="myApp.model">
    <max-size policy="cluster_wide_map_size">10000</max-size>


I’d like to see some basic Play! features use Hazel capabilities:

  • Play! Jobs could use Hazelcast ExecutorService automaticaly
  • Integrating Hazelcast with my other upcoming module Camel for EIP
  • Etc…
You can’t perform that action at this time.