Hazelcast in DX 7.2 1
Hazelcast
How to share Java objects in a cluster
Hazelcast in DX 7.2 2
DX 7.2Sharing objects across servers
1
Hazelcast in DX 7.2 3
1 Why do we want to share objects?
• Replicated object = Highly Available object
o No Single Point of Failure
o Servers can be restarted and shutdown without data loss
• Better load balancing
o Load Balancer redirects traffic to the less busy server,
and not to the one containing the data
• Because we need it!
o Prevents race conditions between servers
o Some features simply need to share data cluster-wide
Hazelcast in DX 7.2 4
1 Why do we want to share objects?
Sticky Session Stateless
VS
Hazelcast in DX 7.2 5
What are the solutions?
1• Externalize objects to a dedicated backend
• Synchronize objects across the cluster
Digital Experience Manager offers out of the box support for both!
Hazelcast in DX 7.2 6
What are the solutions?
1
VS
Offloaded objects Synchronized objects
Hazelcast in DX 7.2 7
1Pros & Cons
• Externalized objects to a dedicated backend:
- No development required for some objects (user sessions...)
- Specific development required when storing custom objects
- More complex architecture (additional servers)
- Highly scalable
• Synchronized objects across the cluster:
- Needs to be taken into account in the code
- No architecture change required
- Very granular: specific objects can be synchronized while others aren’t
- Very efficient with few servers, won’t scale to hundreds of nodes
Hazelcast in DX 7.2 8
1Hazelcast
“The Leading Open Source In-Memory Data Grid”
There is much more to Hazelcast than what we are going to talk about today:
Hazelcast is Open Source under Apache license (we love open source!)
Hazelcast in DX 7.2 9
1Hazelcast in Digital Experience Manager
7.2
• Hazelcast 3.7.3 is available out of the box in Digital Experience
Manager 7.2
• Available as a service: no custom integration required (Use it in less
than 5 minutes)
• Hazelcast is masterless: killing a server won’t alter the service
Hazelcast in DX 7.2 10
1Hazelcast server discovery
How do servers know about each other?
• Multicast
• TCP
• EC2 Cloud
DX 7.2 uses the TCP option. Everything is done for you and you can
start using the service without worrying about the server discovery.
Hazelcast in DX 7.2 11
1DX 7.2 server architecture with Hazelcast
Hazelcast in DX 7.2 12
1Hazelcast usages in 7.2
Hazelcast is already widely used inside Digital Experience Manager 7.2:
• Clustered module deployment: shared module states across
the cluster
• Oauth authentification modules: authentication token shared
across the cluster to authenticate users on all servers at once
• More custom modules we haven’t heard of!
Hazelcast in DX 7.2 13
Technical Implementation
2
Hazelcast in DX 7.2 14
2Hazelcast architecture
• Hazelcast uses TCP communication to replicate the objects
• Hazelcast is event-based
• Hazelcast handles concurrent access to objects out of the box
• Hazelcast is instantiated by DX and exposed as an OSGi Service
Any DX 7.2 module can import Hazelcast’s OSGi service and start using it right away.
Hazelcast in DX 7.2 15
How to use Hazelcast in DX7.2
Hazelcast in DX 7.2 16
2OSGi Services
<osgi:reference id="com.hazelcast.core.HazelcastInstance" interface="com.hazelcast.core.HazelcastInstance"/>
<bean id="HazelcastExampleAction” class="org.jahia.modules.hazelcastexample.beans.HazelcastExampleBean">
<property name="hazelcastInstance" ref="com.hazelcast.core.HazelcastInstance"/>
</bean>
Spring file declaration:
Imports the Hazelcast OSGi Service and injects it in a Spring Bean.
Hazelcast in DX 7.2 17
2Simple shared object declaration
Java class declaration:
public class HazelcastExampleBean {
}
First access to the getMap(String) method will instantiate the shared object
private HazelcastInstance hazelcastInstance;
public void setHazelcastInstance(HazelcastInstance hi) {
this.hazelcastInstance = hi;
}
public HazelcastExampleBean () {
Map<Integer, String> sharedData = hazelcastInstance.getMap("sharedObject");
sharedData.put(sharedData.size()+1, “myContent”);
}
Hazelcast in DX 7.2 18
2That’s all. All the heavy lifting is handled internally by DX 7.2
Of course, there is much more to Hazelcast than sharing objects. If you want to know more,
more documentation is available at
http://docs.hazelcast.org/docs/3.7/manual/html-single/index.html
Hazelcast in DX 7.2 19
2Distributed Events
• Membership Listener for cluster membership events.
• Distributed Object Listener for distributed object creation and destroy events.
• Migration Listener for partition migration start and complete events.
• Partition Lost Listener for partition lost events.
• Lifecycle Listener for HazelcastInstance lifecycle events.
• Entry Listener for IMap and MultiMap entry events.
• Item Listener for IQueue, ISet and IList item events.
• Message Listener for ITopic message events.
• Client Listener for client connection events.
Event distribution is a big part of Hazelcast. Even though you might not use
them at the beginning, listening to events might come in handy someday.
Hazelcast in DX 7.2 20
2Configuration fine tuning
The configuration is stored in
/digital-factory-
data/karaf/etc/hazelcast.xml
Hazelcast in DX 7.2 21
2Performances
• Hazelcast is designed to play well under high read and write load
• Network performance is a key aspect of Hazelcast’s perfs
If you are designing a highly demanding application with lots of
accesses, load performance testing is a key aspect of the project.
Hazelcast in DX 7.2 22
THE END!THANKS FOR
LISTENING