DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > A Look at the Hazelcast IBM Dynacache Provider

A Look at the Hazelcast IBM Dynacache Provider

This glimpse of the Hazelcast Dynacache Provider shows how you can use this solution for caching within and throughout distributed JEE systems.

Mesut Çelik user avatar by
Mesut Çelik
·
Mar. 13, 17 · Java Zone · Tutorial
Like (1)
Save
Tweet
6.98K Views

Join the DZone community and get the full member experience.

Join For Free

IBM has a cache abstraction called Dynacache in Websphere Application Server (WAS) distributions. That abstraction is handy if you want to use a configurable built-in cache solution in your JEE application deployed into WAS environment.

The following is the basic retrieval of a built-in Dynacache provider via JNDI:

private static DistributedObjectCache cache = retrieveDynacache();
static DistributedObjectCache retrieveDynacache() {
    try {
        InitialContext ic = new InitialContext();
        return (DistributedObjectCache) ic.lookup("services/cache/distributedmap");
    } catch (NamingException e) {
        // catch the exception
    }
}


IBM Dynacache is used internally to improve the performance of WAS deployments. Here are the list of features available to boost performance.

Hazelcast Dynacache Provider

IBM WAS has two Dynacache providers:

  1. Default Provider
  2. eXtreme Scale Dynacache Provider

The Default Provider is the one that ships with IBM WAS and has limited capabilities. It only provides an in-process caching solution. If you are in a distributed environment, you may want to use a distributed caching solution. IBM has a solution to that — with its eXtreme Scale Dynacache Provider. In case you have an eXtreme Scale cluster, you can store your caches across the eXtreme Scale cluster.

Besides those solutions, Hazelcast has developed its own Dynacache Provider for users interested in keeping their cache data in Hazelcast Clusters. Hazelcast Dynacache Provider has been released as OSS under Apache 2.0 License.

Configuring in WAS Liberty Profile

Download and install WebSphere Liberty version 16.0.0.3 from here. From this point on, I will refer to the directory you have installed WebSphere Liberty as $LIBERTY_HOME.

Install the Hazelcast Dynacache plugin from the GitHub releases page and install it to Liberty as follows:

$LIBERTY_HOME/bin/featureManager install hazelcast-dynacache-0.2.esa


Create a server named server1:

$LIBERTY_HOME/bin/server create server1


Open up $LIBERTY_HOME/usr/servers/server1/server.xml in your text editor and replace its content with the following:

<server>
    <featureManager>
        <feature>servlet-3.1</feature>
        <feature>distributedMap-1.0</feature>
        <feature>webCache-1.0</feature>
        <!-- hazelcast-dynacache depends on this -->
        <feature>javaee-7.0</feature>
        <feature>usr:hazelcast-dynacache</feature>
    </featureManager>
    <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080">
        <tcpOptions soReuseAddr="true"/>
    </httpEndpoint>
    <logging traceSpecification="com.hazelcast.*=finest=enabled"
        traceFileName="trace.log" maxFileSize="20"
        maxFiles="20" traceFormat="BASIC"/>
</server>


Using Hazelcast Cache Provider

Clone Hazelcast Code Samples repository from GitHub and build a Dynacache Client project:

git clone https://github.com/hazelcast/hazelcast-code-samples.git ch hazelcast-code-samples/hazelcast-integration/dynacache mvn clean package


Copy the resulting WAR file under the dropins folder of the Liberty server we had created:

cp target/dynacache-client-0.1-SNAPSHOT.war $LIBERTY_HOME/usr/servers/server1/dropins/dynacache-client.war


Add the following to a file named jvm.options under $LIBERTY_HOME/usr/servers/server1/

-Dhazelcast.osgi.start=true
-Dhazelcast.client.config=<path to hazelcast-code-samples dir>/hazelcast-integration/dynacache/hz-client.xml


Next, we start a Hazelcast 3.8 cluster with the default configuration (which starts up a member on port 5701).

Start the WebSphere Liberty server:

$LIBERTY_HOME/bin/server start server1


Navigate to http://localhost:9080/dynacache-client on your browser and you will see the following output:

PutResult: the value
the key => the value
the key 2 => the value 2
Invalidation took place...
the key => null
the key2 => the value 2
SomeClass{field1='field 1', field2='field2updated'}


Note that our web application has no direct dependency on Hazelcast. It doesn’t contain hazelcast.jar. It uses the com.ibm.websphere.cache.DistributedMap interface of Dynacache to retrieve the underlying Hazelcast IMap.

Conclusion

If you have a JEE application that is using the Dynacache API, you can simply switch to a Hazelcast Dynacache provider to use Hazelcast as a distributed caching solution. Hazelcast Dynacache Provider currently supports the Hazelcast Client/Server topology, but you can always ask for feature requests by submitting a GitHub issue.

Hazelcast

Published at DZone with permission of Mesut Çelik. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 4 Careers for People with Coding Backgrounds
  • Dynamically Provisioning Persistent Volumes with Kubernetes
  • What's the Difference Between Static Class vs. Singleton Patterns in C#?
  • RestTemplate vs. WebClient

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo