calling Oracle Coherence cache with Servlet

Hello all now then i was posted on to one of the projects in my organization which deals with large amount of data in the financial sector so the project has to be scaled in its performance and we started using “Oracle Coherence” as in memory cache, now in this post i want to discuss a small scenario how to install “Oracle Coherence R12” and use it.

What is Oracle Coherence ?
Oracle Coherence is the industry leading in-memory data grid solution that enables organizations to predictably scale mission-critical applications by providing fast access to frequently used data. As data volumes and customer expectations increase, driven by the “internet of things”, social, mobile, cloud and always-connected devices, so does the need to handle more data in real-time, offload over-burdened shared data services and provide availability guarantees.

Before starting this tutorial, you should:
1.Have access to or have installed the following software:

a. Oracle Coherence R12 for Java (or later)(Download)
b. Oracle WebLogic Server 11gR5 for Windows (Download)
c. Eclipse 3.8 (Juno) for Windows. please visit eclipse site for respective dowload.
Inside the eclipse please install the Weblogic version 11g or laterst.

Step1: Select File > New > Dynamic Web Project.
t20101

Step2:The Dynamic Runtime Module version automatically updates to 2.5 and the Configuration is set to Default Configuration for Oracle WebLogic Server 10gR3.No further configuration is needed. Click Finish.
t20105

Step3:the project structure should look as below.
prj_structure

Now its time to write the configuration and logic:
coherence-config.xml

<?xml version="1.0"?>

<!DOCTYPE cache-config SYSTEM "cache-config.dtd">

<cache-config>
	<caching-scheme-mapping>
		<cache-mapping>
			<cache-name>hello-example</cache-name>
			<scheme-name>distributed</scheme-name>
		</cache-mapping>
	</caching-scheme-mapping>

	<caching-schemes>
		<distributed-scheme>
			<scheme-name>distributed</scheme-name>
			<service-name>DistributedCache</service-name>
			<backing-map-scheme>
				<local-scheme />
			</backing-map-scheme>
			<autostart>true</autostart>
		</distributed-scheme>
	</caching-schemes>
</cache-config>

tangosol-coherence-override.xml

<?xml version='1.0'?>
 
<!DOCTYPE coherence SYSTEM "coherence.dtd">

<coherence>
	<cluster-config>
		<member-identity>
			<cluster-name>my-coherance-cluster</cluster-name>
		</member-identity>

		<multicast-listener>
			<address>224.12.1.0</address>
			<port>12100</port>
			<time-to-live>60</time-to-live>
		</multicast-listener>
	</cluster-config>

	<configurable-cache-factory-config>
		<init-params>
			<init-param>
				<param-type>java.lang.String</param-type>
				<param-value system-property="tangosol.coherence.cacheconfig">
					coherence-config.xml</param-value>
			</init-param>
		</init-params>
	</configurable-cache-factory-config>
</coherence>

coherance_put.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
	
<%@ page
	import="com.tangosol.net.CacheFactory,com.tangosol.net.NamedCache"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%
		String key = "k2";
		String value = "Hello World!";

		CacheFactory.ensureCluster();
		NamedCache cache = CacheFactory.getCache("hello-example");

		cache.put(key, value);

	%>
</body>
</html>

coherance_get.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
	
<%@ page
	import="com.tangosol.net.CacheFactory,com.tangosol.net.NamedCache"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%
		CacheFactory.ensureCluster();
		NamedCache cache = CacheFactory.getCache("hello-example");

		out.println((String) cache.get("k2"));
	%>
</body>
</html>

When the code is run on weblogic server and run the urls you should see the following o/p:

coherance_put

coherance_get

Happy Coherence 🙂
courtesy: http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/coherence/obe34coherence_wls/coherence_wls_eclipse_setup/coherence_wls_eclipse_setup.htm

Will be posting when ever i get chance with new topic and content.

Advertisements

One thought on “calling Oracle Coherence cache with Servlet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s