Developing Oracle Coherence Applications Oracle Weblogic Server
Developing Oracle Coherence Applications Oracle Weblogic Server
Developing Oracle Coherence Applications Oracle Weblogic Server
14c (14.1.1.0.0)
F18281-04
February 2022
Oracle Fusion Middleware Developing Oracle Coherence Applications for Oracle WebLogic Server, 14c
(14.1.1.0.0)
F18281-04
This software and related documentation are provided under a license agreement containing restrictions on
use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your
license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license,
transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse
engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is
prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If
you find any errors, please report them to us in writing.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on
behalf of the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software,
any programs embedded, installed or activated on delivered hardware, and modifications of such programs)
and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end
users are "commercial computer software" or "commercial computer software documentation" pursuant to the
applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use,
reproduction, duplication, release, display, disclosure, modification, preparation of derivative works, and/or
adaptation of i) Oracle programs (including any operating system, integrated software, any programs
embedded, installed or activated on delivered hardware, and modifications of such programs), ii) Oracle
computer documentation and/or iii) other Oracle data, is subject to the rights and limitations specified in the
license contained in the applicable contract. The terms governing the U.S. Government’s use of Oracle cloud
services are defined by the applicable contract for such services. No other rights are granted to the U.S.
Government.
This software or hardware is developed for general use in a variety of information management applications.
It is not developed or intended for use in any inherently dangerous applications, including applications that
may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you
shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its
safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this
software or hardware in dangerous applications.
Oracle, Java, and MySQL are registered trademarks of Oracle and/or its affiliates. Other names may be
trademarks of their respective owners.
Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are
used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc,
and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered
trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products,
and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly
disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise
set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be
responsible for any loss, costs, or damages incurred due to your access to or use of third-party content,
products, or services, except as set forth in an applicable agreement between you and Oracle.
Contents
Preface
Documentation Accessibility v
Conventions v
2 Getting Started
Introduction to Coherence Applications 2-1
Typical Uses for Coherence 2-1
Understanding Coherence Application Configuration Files 2-2
Packaging and Deployment Overview 2-3
Main Tasks for Creating Coherence Applications 2-3
Task One: Create a Coherence Application Directory Structure 2-3
Task Two: Include the Coherence Application's Artifacts 2-3
Task Three: Package the Coherence Application for Deployment 2-5
iii
Accessing and Retrieving Relational Data 3-7
Specifying the Eclipse Persistence Provider 3-7
Packaging a Persistence Unit 3-7
Using Coherence for Session Management 3-8
Creating Extend Clients in WebLogic Server 3-8
Using a JCache Cache in WebLogic Server 3-8
iv
Preface
This preface describes the document accessibility features and conventions that are used in
this guide—Developing Oracle Coherence Applications for Oracle WebLogic Server.
Documentation Accessibility
For information about Oracle's commitment to accessibility, visit the Oracle Accessibility
Program website at http://www.oracle.com/pls/topic/lookup?ctx=acc&id=docacc.
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface elements associated with an
action, or terms defined in text or the glossary.
italic Italic type indicates book titles, emphasis, or placeholder variables for which
you supply particular values.
monospace Monospace type indicates commands within a paragraph, URLs, code in
examples, text that appears on the screen, or text that you enter.
v
1
Introduction and Roadmap
This chapter describes the contents and organization of this guide—Developing Oracle
Coherence Applications for Oracle WebLogic Server.
This chapter includes the following sections:
• Document Scope and Audience
• Guide to This Document
• Related Documentation
• New and Changed Features in This Release
1-1
Chapter 1
Related Documentation
Related Documentation
For additional information, see the following Oracle Coherence and Oracle WebLogic
Server documents:
Oracle Coherence
• Developing Applications with Oracle Coherence
• Developing Remote Clients for Oracle Coherence
• Administering HTTP Session Management with Oracle Coherence*Web
• Oracle Coherence Integration Guide
• Managing Oracle Coherence
• Securing Oracle Coherence
1-2
2
Getting Started
This chapter introduces Coherence applications for WebLogic Server and provides an
overview of creating and packaging Coherence Applications.
This chapter includes the following sections:
• Introduction to Coherence Applications
• Typical Uses for Coherence
• Understanding Coherence Application Configuration Files
• Packaging and Deployment Overview
• Main Tasks for Creating Coherence Applications
2-1
Chapter 2
Understanding Coherence Application Configuration Files
2-2
Chapter 2
Packaging and Deployment Overview
A standalone GAR is deployed to all managed Coherence servers in a Coherence data tier. A
GAR must also be packaged within a EAR and deployed to all managed Coherence servers
that reside in an application tier. See Deploying Coherence Applications in WebLogic Server.
2-3
Chapter 2
Main Tasks for Creating Coherence Applications
1. Place the Coherence application class files in the root of the staging directory in
the appropriate package structure. For example:
MyCohApp/
com/
myco/
MyClass.class
MySerializer.class
lib/
META-INF/
2-4
Chapter 2
Main Tasks for Creating Coherence Applications
3. Copy the GAR and package it within an enterprise application directory structure. See
Developing Applications for Oracle WebLogic Server for details on developing EAR. For
example:
MyEAR/
META-INF/
application.xml
weblogic-application.xml
MyWAR.war
MyEJB.jar
MyCohApp.gar
The weblogic-application.xml file must contain a module reference for the GAR. For
example:
<weblogic-application>
<module>
<name>MyCohApp</name>
<type>GAR</type>
<path>MyCohApp.gar</path>
</module>
</weblogic-application>
2-5
3
Creating Coherence Applications for
WebLogic Server
Coherence caches can be accessed using dependency injection and JNDI. Coherence
applications can be packaged as a Grid ARchive (GAR).
This chapter includes the following sections:
• Packaging Coherence Applications
• Creating a Coherence Application Deployment Descriptor
• Using JNDI to Override Configuration
• Defining a Data Cache
• Accessing a Data Cache
• Using the Coherence API
• Using a Coherence Application Lifecycle Listener
• Accessing and Retrieving Relational Data
• Using Coherence for Session Management
• Creating Extend Clients in WebLogic Server
• Using a JCache Cache in WebLogic Server
A GAR module includes the artifacts that comprise a Coherence application. The /META-INF
directory contains the deployment descriptor for the Coherence application (cohererence-
application.xml). The presence of the deployment descriptor indicates a valid GAR. An
additional subdirectory, the /lib directory, is used for storing dependency JAR files.
Compiled Java classes that make up a Coherence application (entry processors,
aggregators, filters, and so on) are placed in the root directory in the appropriate Java
package structure.
A GAR module can also contain a cache configuration file (coherence-cache-config.xml)
and a Portable Object Format (POF) serialization configuration file (pof-config.xml). The
location of these files is defined within the Coherence application deployment descriptor.
Typically, the files are placed in the /META-INF directory; however, they can be located
anywhere in the GAR relative to the root or even at a URL-accessible network location.
3-1
Chapter 3
Packaging Coherence Applications
Note:
• If the configuration files are not found at runtime, then the default
configuration files that are included in the coherence.jar, which is
located in the system classpath, are used.
• If the configuration files are located in the root directory of the GAR, then
they must not use the default file names; otherwise, the configuration
files that are included in the coherence.jar file are found first and the
configuration files in the GAR are never loaded.
The entire directory, once staged, is bundled into a GAR file using the jar command.
GAR files are deployed as standalone archives to managed Coherence servers that
are configured to store cached data.
Client applications that rely on the caches and resources in a GAR module must be
packaged within an EAR that includes the dependent GAR. An EAR cannot contain
multiple GAR modules. Multiple GAR modules must be merged into a single GAR.
That is, a GAR must contain one application deployment descriptor, one cache
configuration file, and one POF configuration file.
3-2
Chapter 3
Creating a Coherence Application Deployment Descriptor
For a detailed reference of all the available elements in the descriptor, see coherence-
application.xml Deployment Descriptor Elements. The following is an example of a
Coherence deployment descriptor that declares a cache configuration file and a POF
configuration file that is located in the META-INF directory of the GAR.
<?xml version="1.0"?>
<coherence-application
xmlns="http://xmlns.oracle.com/coherence/coherence-application">
<cache-configuration-ref>META-INF/coherence-cache-config.xml
</cache-configuration-ref>
<pof-configuration-ref>META-INF/pof-config.xml</pof-configuration-ref>
</coherence-application>
3-3
Chapter 3
Defining a Data Cache
<pof-configuration-ref>META-INF/pof-config.xml</pof-configuration-ref>
</coherence-application>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>myCache</cache-name>
<scheme-name>distributed</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<distributed-scheme>
<scheme-name>distributed</scheme-name>
<service-name>DistributedService</service-name>
<backing-map-scheme>
<local-scheme/>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>
</caching-schemes>
</cache-config>
Coherence does not support the use of a replicated cache scheme if a GAR module is
used in multiple EAR modules (packaged either individually or as a shared GAR) on a
managed Coherence server. An alternative is to use a near cache instead of a
replicated cache.
3-4
Chapter 3
Using the Coherence API
Example 3-3 illustrates using dependency injection to get a cache named myCache. See
Developing Applications for Oracle WebLogic Server for details on JavaEE annotations and
dependency injection.
Example 3-3 Obtaining a Cache Resource by Dependency Injection
...
@Resource(mappedName="MyCache")
com.tangosol.net.NamedCache nc;
...
Note:
The <res-auth> and <res-sharing-scope> elements do not appear in the example.
The <res-auth> element is ignored because currently no resource sign-on is
performed to access data caches. The <res-sharing-scope> element is ignored
because data caches are sharable by default and this behavior cannot be
overridden.
The following example performs a JNDI lookup to get a NamedCache reference that is defined
in Example 3-4:
try {
Context ctx = new InitialContext();
cache = (NamedCache) ctx.lookup("java:comp/env/coherence/myCache");
cache.put(key, value);
}
catch (NamingException ne)
3-5
Chapter 3
Using a Coherence Application Lifecycle Listener
3-6
Chapter 3
Accessing and Retrieving Relational Data
3-7
Chapter 3
Using Coherence for Session Management
Note:
Persistence files cannot be placed in a WAR file. Any persistence files
placed in the WAR file will not be found at runtime. Coherence only has
access to the application classloader.
Unlike the application tier, the Coherence data tier only requires the deployment of a
GAR. For the data tier, include the persistence unit JAR within the /lib directory of the
GAR. For example:
MyCohApp/
lib/
MyPersistence.jar
META-INF/
coherence-application.xml
coherence-cache-config.xml
pof-config.xml
com/myco/
MyClass.class
3-8
Chapter 3
Using a JCache Cache in WebLogic Server
2. Edit the cache configuration file that is referenced in the coherence-application.xml file
to include either the JCache namespace or JCacheExtend namespace. For example:
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
xmlns:jcache="class://com.tangosol.coherence.jcache.JCacheNamespace"
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-
config
coherence-cache-config.xsd">
...
3. Use the JCahe API to create and use a JCache cache. For example within a servlet:
try {
cache = mgr.getCache(cacheName, ContactId.class, Contact.class);
}
catch (IllegalStateException e) {
if (cache == null) {
PartitionedCacheConfiguration config = new
PartitionedCacheConfiguration<ContactId, Contact>();
config.setTypes(ContactId.class, Contact.class);
config.setStatisticsEnabled(true);
config.setManagementEnabled(true);
cache = mgr.createCache(cacheName, config);
}
return cache;
}
3-9
4
Deploying Coherence Applications in
WebLogic Server
To manage Coherence servers in a WebLogic Server domain, you must deploy Coherence
applications packaged as a Grid ARchive (GAR).
See Packaging Coherence Applications for details on creating a GAR.
This chapter includes the following sections:
• Understanding Coherence Deployment Tiers
• Deploying Applications to Managed Coherence Servers
• Deploying Coherence Applications as Shared Libraries
• Referencing Shared Libraries from a Coherence Application
• Performing a Rolling Redeploy
• Loading Coherence From the Application Classloader
• Securing Coherence Applications in WebLogic Server
4-1
Chapter 4
Deploying Coherence Applications as Shared Libraries
Administration Console, the Oracle WebLogic Scripting Tool (WLST), the WebLogic
Server Deployer class, and the WebLogic Server <wldeploy> ANT target.
Note:
Production redeployment of an EAR containing a GAR is only supported for
storage-disabled cluster clients. In addition, any changes to the code in the
GAR must be backward compatible with the existing deployment. For
example, entity classes that are changing must implement the Evolvable
interface. See Deploying Applications to Oracle WebLogic Server.
GAR modules should be deployed as standalone modules and also as part of an EAR.
The following list describes how GAR modules are deployed in a WebLogic Server
domain that uses Coherence tiers. See Administering Clusters for Oracle WebLogic
Server.
• Data Tier – Deploy a standalone GAR to each managed Coherence server of the
data tier. If the data tier is setup as a WebLogic Server cluster, deploy the GAR to
the cluster and have the module copied to each managed Coherence server.
• Application Tier – Deploy the EAR that contains both the client implementation
(Web Application, EJB, and so on) and the GAR to each managed Coherence
server in the cluster. If the application tier is setup as a WebLogic Server cluster,
deploy the EAR to the cluster and have the module copied to each managed
Coherence server.
• Proxy Tier – Deploy the standalone GAR to each managed Coherence server of
the proxy tier. The cache configuration file packaged in the GAR must include a
proxy service definition. If the application tier is setup as a WebLogic Server
cluster, deploy the GAR to the cluster and have the module copied to each
managed Coherence server.
• Extend Client Tier – Deploy the EAR that contains the extend client
implementation (Web Application, EJB, and so on) as well as the GAR to each
managed server that hosts the extend client. The client's cache configuration file
must include a remote cache service definition that defines the address of a proxy
server. If the extend client tier is setup as a WebLogic Server cluster, deploy the
EAR to the cluster and the WebLogic deployment infrastructure copies the module
to each managed Coherence server.
4-2
Chapter 4
Referencing Shared Libraries from a Coherence Application
The above configuration works in single-tier domain where both the application tier and data
tier are on a single managed Coherence server. However, in a multi-tiered domain, additional
configuration is required to ensure that a GAR that is deployed as a shared library results in
storage-enabled members starting as expected.
To deploy a GAR as shared library in multi-tiered domain:
1. Edit the cache configuration file in the GAR and explicitly set the <scope-name> element
to the GAR name. For details about configuring the scope name, see Administering
Oracle Coherence.
For example, if the GAR is named ExampleGAR.gar, the <scope-name> element is defined
as follows:
<cache-config>
<defaults>
<scope-name>ExampleGAR</scope-name>
</defaults>
...
2. Deploy the GAR to the application (storage-disabled) tier as a shared library and specify
the GAR name as the application name. For example, if the GAR is named
ExampleGAR.gar, then the GAR name is specified as ExampleGAR.
3. Edit the weblogic-application.xml deployment descriptor in the EAR and include a
reference for the GAR. For example:
<weblogic-application>
<library-ref>
<library-name>ExampleGAR</library-name>
</library-ref>
</weblogic-application>
4-3
Chapter 4
Performing a Rolling Redeploy
For a detailed reference of the available elements in the descriptor, see weblogic-coh-
app.xml Deployment Descriptor Elements. For example:
<?xml version="1.0"?>
<weblogic-coh-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-coh-app">
<library-ref>
<library-name>mySharedLibrary</library-name>
<specification-version>2.0</specification-version>
<implementation-version>8.1beta</implementation-version>
<exact-match>false</exact-match>
</library-ref>
</weblogic-coh-app>
Note:
To ensure there is no persistence or write-through cache data loss during a
simultaneous redeployment of GAR modules to all managed Coherence
servers, you can leverage the service suspend feature. A service is
considered suspended only after all the data is fully written, including active
persistence mode, asynchronous persistence tasks, entries in the write-
behind queue of a read-write backing map, and other asynchronous
operations. Outstanding operations are completed and no new operations
are allowed against the suspended services. Thus, for a controlled complete
redeploy of GAR modules to all managed Coherence servers, Oracle
recommends executing the Coherence ClusterMBean operation
suspendService("impactedService") which suspends each service with
potential asynchronous operations gracefully before undeploying GAR
modules from all managed Coherence servers.
A rolling redeploy is a technique for updating a GAR across a WebLogic Server cluster
by individually redeploying the GAR on each managed Coherence server and cycling
through all servers. A rolling redeploy allows cached data to be redistributed while the
GAR is redeployed. Only in-memory cache data is otherwise lost if a GAR is
redeployed to all cache servers simultaneously.
Note:
Always check the StatusHA metric on the partitioned service between server-
targeted deployments to ensure MACHINE_SAFE status. See Managing Oracle
Coherence for details on this metric.
4-4
Chapter 4
Loading Coherence From the Application Classloader
The full path and name to the GAR file must match exactly the path and name that was used
to originally deploy the GAR. If a different path or name is used, then a -1, -2, or, -1 and -2 is
appended to the GAR name and the rolling redeploy will not work correctly. In addition, if the
GAR was originally deployed using the upload=true option, then you must redeploy using the
upload=true option; otherwise, the rolling redeploy will not work correctly.
WLST
deploy('MyCohApp', '/myapps/MyCohApp.gar', 'server1', specifiedTargetsOnly='true')
weblogic.Deployer
java weblogic.Deployer -adminurl t3://localhost:7001 -username username -password
password -targets ms3 -deploy -name MyCohApp /myapps/MyCohApp.gar -specifiedtargetsonly
<prefer-application-resources>
<resource-name>com.tangosol.*</resource-name>
4-5
Chapter 4
Securing Coherence Applications in WebLogic Server
<resource-name>com.oracle.common.*</resource-name>
<resource-name>coherence-*.xml</resource-name>
<resource-name>coherence-*.xsd</resource-name>
<resource-name>tangosol-*.xml</resource-name>
<resource-name>tangosol.properties</resource-name>
<resource-name>tangosol.cer</resource-name>
<resource-name>tangosol.dat</resource-name>
<resource-name>internal-txn-cache-config.xml</resource-name>
<resource-name>txn-pof-config.xml</resource-name>
<resource-name>pof-config.xml</resource-name>
<resource-name>management-config.xml</resource-name>
<resource-name>processor-dictionary.xml</resource-name>
<resource-name>reports/*</resource-name>
</prefer-application-resources>
</container-descriptor>
4-6
A
coherence-application.xml Deployment
Descriptor Elements
This appendix provides a complete reference for the elements in the Coherence application
deployment descriptor coherence-application.xml.
This appendix includes the following sections:
• coherence-application.xml Namespace Declaration and Schema Location
• application-lifecycle-listener
• cache-configuration-ref
• coherence-application
• configurable-cache-factory-config
• init-params
• pof-configuration-ref
application-lifecycle-listener
The application-lifecycle-listener elements specify the fully qualified name of a class or the
initialization parameter that is required by the implementation.
The application-lifecycle-listener element specifies the fully qualified name of a class
that implements the com.tangosol.application.LifeCycleListener interface. The class
allows custom processing before and after the creation and destruction of Coherence cache
and clustered services.
A-1
Appendix A
cache-configuration-ref
The following table describes the elements you can define within an application-
lifecycle-listener element.
cache-configuration-ref
The cache-configuration-ref element specifies the name and location of a
Coherence cache configuration file. The location of the file is relative to the root
directory within a Coherence Grid Archive (GAR). A URL may also be specified. If the
file is not found, or if this element is not specified, then the predefined cache
configuration file (coherence-cache-config.xml) that is located in the coherence.jar
library on the system classpath is used by default.
Note:
If the configuration file is located in the root directory of the GAR, then it must
not use the default file name (coherence-cache-config.xml); otherwise, the
configuration file that is included in the coherence.jar file which is located in
the system classpath is found first and the configuration file in the GAR is
never loaded. An alternative to renaming the file is to place the configuration
file in the META-INF directory of the GAR.
coherence-application
The coherence-application element is the root element of the Coherence application
deployment descriptor.
The following table describes the elements you can define within a coherence-
application element.
A-2
Appendix A
configurable-cache-factory-config
configurable-cache-factory-config
The configurable-cache-factory-config element specifies the fully qualified name of a
class that implements the com.tangosol.net.ConfigurableCacheFactory interface. The
default implementation is the com.tangosol.net.ExtensibleConfigurableCacheFactory
class.
Using a custom ConfigurableCacheFactory implementation is an advanced use case and is
typically used to allow applications that are scoped by different class loaders to use separate
cache configuration files.
The following table describes the elements you can define within a configurable-cache-
factory-config element.
init-params
The init-params element specifies an initialization parameter. Any number of init-params
elements may be defined.
The following table describes the elements you can define within an init-params element.
A-3
Appendix A
pof-configuration-ref
pof-configuration-ref
The pof-configuration-ref element specifies the name and location of a Coherence
POF configuration file. The location of the file is relative to the root directory within a
Coherence Grid Archive (GAR). A URL may also be specified. If the file is not found,
or if this element is not specified, then the predefined POF configuration file (pof-
config.xml) that is located in the coherence.jar library on the system classpath is
used by default.
Note:
If the configuration file is located in the root directory of the GAR, then it must
not use the default file name (pof-config.xml); otherwise, the configuration
file that is included in the coherence.jar file which is located in the system
classpath is found first and the configuration file in the GAR is never loaded.
An alternative to renaming the file is to place the configuration file in the
META-INF directory of the GAR.
A-4
B
weblogic-coh-app.xml Deployment Descriptor
Elements
This appendix provides a complete reference for the elements in the WebLogic Coherence
application deployment descriptor weblogic-coh-app.xml.
weblogic-coh-app
The weblogic-coh-app element is the root element of the WebLogic Coherence application
deployment descriptor.
The following table describes the elements you can define within a weblogic-coh-app
element.
library-ref
The library-ref element specifies a shared library module that is intended to be used as a
library in a Coherence application.
The following table describes the elements you can define within a library-ref element.
B-1
Appendix B
library-ref
B-2