Play! Hazelcast Module


License

License

unknown
Categories

Categories

Maven Build Tools Hazelcast Application Layer Libs Distributed Applications
GroupId

GroupId

com.google.code.maven-play-plugin.org.playframework.modules.hazelcast
ArtifactId

ArtifactId

play-hazelcast
Last Version

Last Version

0.6
Release Date

Release Date

Type

Type

jar
Description

Description

Play! Hazelcast Module
Play! Hazelcast Module
Source Code Management

Source Code Management

https://github.com/marcuspocus/hazelcast

Download play-hazelcast

How to add to project

<!-- https://jarcasting.com/artifacts/com.google.code.maven-play-plugin.org.playframework.modules.hazelcast/play-hazelcast/ -->
<dependency>
    <groupId>com.google.code.maven-play-plugin.org.playframework.modules.hazelcast</groupId>
    <artifactId>play-hazelcast</artifactId>
    <version>0.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.google.code.maven-play-plugin.org.playframework.modules.hazelcast/play-hazelcast/
implementation 'com.google.code.maven-play-plugin.org.playframework.modules.hazelcast:play-hazelcast:0.6'
// https://jarcasting.com/artifacts/com.google.code.maven-play-plugin.org.playframework.modules.hazelcast/play-hazelcast/
implementation ("com.google.code.maven-play-plugin.org.playframework.modules.hazelcast:play-hazelcast:0.6")
'com.google.code.maven-play-plugin.org.playframework.modules.hazelcast:play-hazelcast:jar:0.6'
<dependency org="com.google.code.maven-play-plugin.org.playframework.modules.hazelcast" name="play-hazelcast" rev="0.6">
  <artifact name="play-hazelcast" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.google.code.maven-play-plugin.org.playframework.modules.hazelcast', module='play-hazelcast', version='0.6')
)
libraryDependencies += "com.google.code.maven-play-plugin.org.playframework.modules.hazelcast" % "play-hazelcast" % "0.6"
[com.google.code.maven-play-plugin.org.playframework.modules.hazelcast/play-hazelcast "0.6"]

Dependencies

compile (1)

Group / Artifact Type Version
com.hazelcast : hazelcast-client jar 2.0.2

provided (1)

Group / Artifact Type Version
com.google.code.maven-play-plugin.org.playframework : play jar 1.2

Project Modules

There are no modules declared in this project.

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)
module.hazelcast=${play.path}/modules/hazelcast-[version]
  • The Play 1.2.x way (in dependencies.yml)
require:
	- play -> hazelcast [version]

Parameters

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

hazelcast.disabled=true

The value defaults to false.

hazelcast.configFile=conf/hazelcast-dev.xml

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")
  • Cache.xxx()
  • Etc…

See Play Framework Cache Documentation for CacheFor("1h") and provided Play! Cache.xxx() 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
    hibernate.cache.region.factory_class=com.hazelcast.hibernate.HazelcastCacheRegionFactory
    hibernate.cache.use_query_cache=false
    hibernate.cache.use_minimal_puts=true
    hibernate.cache.use_second_level_cache=true
    hibernate.cache.region_prefix=myApp
    hibernate.cache.use_structured_entries=true
  • dependencies.yml
    # Application dependencies
    require:
    - play
    - play -> hazelcast 0.4
    - com.hazelcast -> hazelcast-hibernate 1.9.4.4
  • Entity class annotation
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "model")
  • hazelcast.xml – add following map definition
    <map name="myApp.model">
    <backup-count>1</backup-count>
    <time-to-live-seconds>0</time-to-live-seconds>
    <max-idle-seconds>3600</max-idle-seconds>
    <eviction-policy>LRU</eviction-policy>
    <max-size policy="cluster_wide_map_size">10000</max-size>
    <eviction-percentage>25</eviction-percentage>
    </map>

Roadmap

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…

Versions

Version
0.6