PK
]'Doa, mimetypeapplication/epub+zipPK ]'D iTunesMetadata.plistS
This exercise illustrates how you can simplify Java expressions that use aggregations and filters by using the Coherence createFilter
and createExtractor
factory methods in the QueryHelper
class.
In Chapter 5, "Loading Data Into a Cache," you created a file, QueryExample.java
, that used a variety of filters, such as AlwaysFilter
, LikeFilter
, and EqualsFilter
, to pull and aggregate information from the cache. The file also created indexes on the data by using a variety of specialized ValueExtractors
: ChainedExtractors
, KeyExtractors
, and ReflectionExtractors
. This created some verbose Java statements. These statements can be simplified by using the QueryHelper
API.
This chapter contains the following sections:
To simplify filter and extractor statements, and the way in which you interact with the Coherence caches, Coherence provides the QueryHelper
API. QueryHelper
(com.tangosol.util.QueryHelper
) is a utility class that provides a set of createFilter
and createExtractor
factory methods that can build instances of Filter
and ValueExtractor
. The methods in the class accept a String data type that specifies the creation of rich Filters in a format that is familiar to anyone who understands SQL WHERE
clauses.
For example, the following statement uses createFilter(String s)
to construct a filter for employees who live in Massachusetts but work in another state.
.. QueryHelper.createFilter("homeAddress.state = 'MA' and workAddress.state !='MA'") ...
This statement is more simple and easier to read than the equivalent filter and extractor statement using the Coherence API:
new AndFilter(new EqualsFilter("getHomeAddress.getState", "MA"), new NotEqualsFilter("getWorkAddress.getState", "MA"))
For more information, see the Javadoc for the QueryHelper
API. For information on the syntax of the WHERE
clause within the Coherence Query Language, see "Using Coherence Query Language" in Oracle Fusion Middleware Developing Applications with Oracle Coherence.
This section describes how you can simplify the indexes, cache calls, and aggregations in the QueryExample.java
file that you created in the previous chapter.
Import the QueryHelper
API into the QueryExample.java
file as a static class.
import static com.tangosol.util.QueryHelper.*;
Comment out the imports for the ChainedExtractor
, KeyExtractor
, and ReflectionExtractor
classes.
Comment out the imports for the AlwaysFilter
, AndFilter
, EqualsFilter
, GreaterFilter
, LikeFilter
, and NotEqualsFilter
classes.
In the cache.addIndex
statements, replace instances of ReflectionExtractor
with createExtractor
from the QueryHelper API.
Table 6-1 lists the ReflectionExtractor
instances and their createExtractor
equivalents.
Table 6-1 ReflectionExtractors and Their Equivalent createExtractor Statements
Replace This ReflectionExtractor Statement ... | With the Equivalent createExtractor Statement ... |
---|---|
|
|
|
|
|
|
|
|
Replace the calls to the *Filter
methods in the setResults
statements with calls to createFilter
with the appropriate Coherence Query Language.
Table 6-2 lists the *Filter
instances and their createFilter
equivalents.
Table 6-2 *Filter Statements and Their Equivalent createFilter Statements in Queries
Replace This *Filter Statement ... | With the Equivalent createFilter Statement ... |
---|---|
|
|
|
|
|
|
|
|
|
|
Replace the calls to the *Filter
methods in the aggregate
statements with calls to createFilter
with the appropriate Coherence Query Language.
Table 6-3 lists the *Filter
instances and their createFilter
equivalents.
Table 6-3 Filter Statements and Their Equivalent createFilter Statements in Aggregations
Replace This *Filter Statement ... | With the Equivalent createFilter Statement ... |
---|---|
|
|
|
|
|
|
|
|
When you are finished with the code replacements, QueryExample.java
looks similar to Example 6-1.
Example 6-1 Edited QueryExample File
package com.oracle.handson; import com.tangosol.net.CacheFactory; import com.tangosol.net.NamedCache; import com.tangosol.util.Filter; import static com.tangosol.util.QueryHelper.*; import com.tangosol.util.aggregator.Count; // import com.tangosol.util.extractor.ChainedExtractor; // import com.tangosol.util.extractor.KeyExtractor; // import com.tangosol.util.extractor.ReflectionExtractor; // import com.tangosol.util.aggregator.Count; import com.tangosol.util.aggregator.DoubleAverage; import com.tangosol.util.aggregator.LongMax; import com.tangosol.util.aggregator.LongMin; // import com.tangosol.util.filter.AlwaysFilter; // import com.tangosol.util.filter.AndFilter; // import com.tangosol.util.filter.EqualsFilter; // import com.tangosol.util.filter.GreaterFilter; // import com.tangosol.util.filter.LikeFilter; // import com.tangosol.util.filter.NotEqualsFilter; import java.util.Iterator; import java.util.Set; /** * QueryExample runs sample queries for contacts. * */ public class QueryExample{ // ----- QueryExample methods --------------------------------------- public static void main(String[] args) { NamedCache cache = CacheFactory.getCache("ContactsCache"); query(cache); } /** * Perform the example queries * */ public static void query(NamedCache cache) { // Add indexes to make queries more efficient // ReflectionExtractor reflectAddrHome = // new ReflectionExtractor("getHomeAddress"); // Add an index for the age // cache.addIndex(new ReflectionExtractor("getAge"), true, null); cache.addIndex(createExtractor("age"), true, null); // Add index for state within home address // cache.addIndex(new ChainedExtractor(reflectAddrHome, // new ReflectionExtractor("getState")), true, null); cache.addIndex(createExtractor("homeAddress.state"), false, null); // Add index for state within work address // cache.addIndex(new ChainedExtractor( // new ReflectionExtractor("getWorkAddress"), // new ReflectionExtractor("getState")), true, null); cache.addIndex(createExtractor("workAddress.state"),false, null); // Add index for city within home address // cache.addIndex(new ChainedExtractor(reflectAddrHome, // new ReflectionExtractor("getCity")), true, null); cache.addIndex(createExtractor("homeAddress.city"), true, null); // Find all contacts who live in Massachusetts // Set setResults = cache.entrySet(new EqualsFilter( // "getHomeAddress.getState", "MA")); Set setResults = cache.entrySet(createFilter("homeAddress.state = 'MA'")); printResults("MA Residents", setResults); // Find all contacts who live in Massachusetts and work elsewhere // setResults = cache.entrySet(new AndFilter( // new EqualsFilter("getHomeAddress.getState", "MA"), // new NotEqualsFilter("getWorkAddress.getState", "MA"))); setResults = cache.entrySet(createFilter("homeAddress.state is 'MA' and workAddress is not 'MA'")); printResults("MA Residents, Work Elsewhere", setResults); // Find all contacts whose city name begins with 'S' // setResults = cache.entrySet(new LikeFilter("getHomeAddress.getCity", // "S%")); setResults = cache.entrySet(createFilter("homeAddress.city like 'S%'")); printResults("City Begins with S", setResults); final int nAge = 42; Object[] aEnv = new Object[] {new Integer(nAge)}; // Find all contacts who are older than nAge // setResults = cache.entrySet(new GreaterFilter("getAge", nAge)); setResults = cache.entrySet(createFilter("age > ?1",aEnv)); printResults("Age > " + nAge, setResults); // Find all contacts with last name beginning with 'S' that live // in Massachusetts. Uses both key and value in the query. // setResults = cache.entrySet(new AndFilter( // new LikeFilter(new KeyExtractor("getLastName"), "S%", // (char) 0, false), // new EqualsFilter("getHomeAddress.getState", "MA"))); setResults = cache.entrySet(createFilter("key(lastName) like 'S%' and homeAddress.state = 'MA'")); setResults = cache.entrySet(createFilter("key().lastName like 'S%' and homeAddress.state = 'MA'")); printResults("Last Name Begins with S and State Is MA", setResults); // Count contacts who are older than nAge // System.out.println("count > " + nAge + ": "+ // cache.aggregate(new GreaterFilter("getAge", nAge), new Count())); System.out.println("count > " + nAge + ": " + cache.aggregate( createFilter("age > ?1", aEnv), new Count())); // Find minimum age // System.out.println("min age: " + cache.aggregate(AlwaysFilter.INSTANCE, new LongMin("getAge"))); Filter always = createFilter("true"); System.out.println("min age: " + cache.aggregate(always, new LongMin("getAge"))); // Calculate average age // System.out.println("avg age: " + cache.aggregate(AlwaysFilter.INSTANCE, new DoubleAverage("getAge"))); System.out.println("avg age: " + cache.aggregate(always, new DoubleAverage("getAge"))); // Find maximum age // System.out.println("max age: " + // cache.aggregate(AlwaysFilter.INSTANCE, new LongMax("getAge"))); System.out.println("max age: " + cache.aggregate(always, new LongMax("getAge"))); System.out.println("------QueryLanguageExample completed------"); } /** * Print results of the query * * @param sTitle the title that describes the results * @param setResults a set of query results */ private static void printResults(String sTitle, Set setResults) { System.out.println(sTitle); for (Iterator iter = setResults.iterator(); iter.hasNext(); ) { System.out.println(iter.next()); } } }
To rerun the query example:
Stop any running cache servers. See "Stopping Cache Servers" for more information.
Restart the ContactsCacheServer
.
Run the DataGenerator
, LoaderExample
, and QueryExample
files.
After printing all of the contact information in the cache, it displays the results of the queries. The results should look similar to the following examples.
Note: The |
Example 6-2 illustrates the output of the MA Residents filter.
Example 6-2 Output of the MA Residents Filter
...
MA Residents
ConverterEntry{Key="John Hwdrrls", Value="John Hwdrrls
Addresses
Home: 369 Beacon St.
Fetggv, MA 24372
US
Work: Yoyodyne Propulsion Systems
330 Lectroid Rd.
Grover's Mill, NE 84499
US
Telephone Numbers
work: +11 88 331 2307913
home: +11 64 86 2489621
Birth Date: 1976-12-29"}
...
Example 6-3 illustrates the output of the MA Residents, Work Elsewhere filter.
Example 6-3 Output of the MA Residents, Work Elsewhere Filter
...
MA Residents, Work Elsewhere
ConverterEntry{Key="John Hwdrrls", Value="John Hwdrrls
Addresses
Home: 369 Beacon St.
Fetggv, MA 24372
US
Work: Yoyodyne Propulsion Systems
330 Lectroid Rd.
Grover's Mill, NE 84499
US
Telephone Numbers
work: +11 88 331 2307913
home: +11 64 86 2489621
Birth Date: 1976-12-29"}
...
Example 6-4 illustrates the output of the City Begins with S filter.
Example 6-4 Output of the City Begins with S Filter
...
City Begins with S
ConverterEntry{Key="John Pzek", Value="John Pzek
Addresses
Home: 309 Beacon St.
Saqrgy, OH 81353
US
Work: Yoyodyne Propulsion Systems
330 Lectroid Rd.
Grover's Mill, CT 78117
US
Telephone Numbers
work: +11 28 790 2035988
home: +11 61 470 7634708
Birth Date: 1971-12-31"}
...
Example 6-5 illustrates the output of the age greater than 42 filter.
Example 6-5 Output of the Age Greater than 42 Filter
...
Age > 42
ConverterEntry{Key="John Gddurqqziy", Value="John Gddurqqziy
Addresses
Home: 613 Beacon St.
Cxyskdo, DE 28968
US
Work: Yoyodyne Propulsion Systems
330 Lectroid Rd.
Grover's Mill, SD 07959
US
Telephone Numbers
work: +11 31 768 5136041
home: +11 87 22 3851589
Birth Date: 1958-01-03"}
...
Example 6-6 illustrates the output of the Last Name Begins with S and State is MA filter and the output of the aggregators.
Example 6-6 Output of the State and Age Aggregators
Last Name Begins with S and State Is MA
ConverterEntry{Key="John Syaqlojl", Value="John SyaqlojlAddressesHome: 810 Beacon St.Rgtaljwph, MA 07471USWork: 200 Newbury St.Yoyodyne, Ltd.Boston, MA 02116USTelephone Numberswork: +11 37 18 1767648home: +11 98 155 1073866Birth Date: 1974-12-30"} ...count > 42: 446
min age: 22
avg age: 41.126
max age: 61
The following topics introduce the new and changed features of Oracle Coherence and other significant changes that are described in this guide, and provides pointers to additional information. This document is the new edition of the formerly titled Oracle Coherence Tutorial for Oracle Coherence.
Oracle Coherence 12c (12.1.2) includes the following new and changed features for this document.
Tutorial for Live Events, which shows you how to use the Coherence Live Events framework. This framework allows your applications to react to operations performed in the data grid. The framework uses an event-based model where events represent observable occurrences of cluster operations. The supported events include partitioned service, cache, and application events. See Chapter 11, "Working with Live Events."
An appendix has been added describing the basic features, security, and events examples that are delivered with the Coherence distribution in the examples.zip file. These examples (in the Java, C++, and .NET languages) are designed to be built and run on the command line. See Appendix A, "Coherence Examples in the examples.zip File."
For 12c (12.1.2), this guide has been updated in several ways. Following are the sections that have been added or changed.
Revised all of the tutorials in the guide to use Coherence 12c (12.1.2).
Revised the Coherence and JPA tutorial to use EclipseLink 2.4.x, TopLink Grid 12c (12.1.2), and the Java Persistence 2.0 files. See Chapter 8, "Using JPA with Coherence."
Revised the tutorial to create and configure an Oracle Coherence cache in Eclipse to use EclipseLink 2.4.x, TopLink Grid 12c (12.1.2), and the Java Persistence 2.0 files. See Chapter 9, "Interacting with the Cache and the Database."
Revised the session caching and managed WebLogic Servers tutorial to use WebLogic Server 12c (12.1.2). See Chapter 12, "Caching Sessions with Managed WebLogic Servers."
The Coherence distribution provides a collection of example code in the examples.zip
file. These examples demonstrate how to use basic Coherence functionality, security, and events features in all supported languages (Java, .NET, and C++). The examples are organized as collections of code that show how to use one or more features. They also provide a single common way (per language) to build and run all examples.
This appendix has the following sections:
There are a number of differences between the examples in the examples.zip
file described in this appendix and the examples that are presented in the main body of the tutorial:
The examples in the examples.zip
must be built and run from the command line. The tutorial uses an IDE to compile and run the code.
The examples in the examples.zip
file demonstrate how to use basic Coherence functionality and security features in all supported languages (Java, .NET, and C++). The tutorial covers only Java implementations.
The Java examples in the examples.zip
file are only a subset of the Java examples presented in the tutorial.
The Java code files in the examples.zip
file are similar, but not identical to, the files used in the tutorial. In many instances, the code in the tutorial has been simplified for demonstration purposes.
The Coherence Basic Features Examples include the following:
Table A-1 Coherence Basic Features Examples
Example Name | Description |
---|---|
Basic Data Access |
"Getting", "putting" and "removing" data from the Coherence Data Grid. See Section A.5.3, "Basic Data Access Example." |
Data Loading |
Loading example data into the Coherence Data Grid. See Section A.5.4, "Loader Example." |
Parallel Querying |
Querying the Coherence Data Grid including the use of indexes. See Section A.5.5, "Query Example." |
Observable |
Listening for changes to data in the Coherence Data Grid. See Section A.5.6, "Observer Example." |
Processing |
Co-locating data processing with the data itself in the Coherence Data Grid. See Section A.5.7, "Processor Example." |
Query Language |
How to use the Coherence Query Language. See Section A.5.5, "Query Example." |
The Coherence Security Examples include the following:
Table A-2 Coherence Security Examples
Example Name | Description |
---|---|
Password Example |
Requiring a password to access Coherence. See Section A.6.2, "Password Example." |
Access Control Example |
Simplified role based access control. See Section A.6.3, "Access Control Example." |
Password Identity Transformer |
Creates a custom security token that contains the required password and then adds a list of Principal names. See Section A.6.4, "Password Identity Transformer." |
Password Identity Asserter |
Asserts that the security token contains the required password and then constructs a Subject based on a list of Principal names. See Section A.6.5, "Password Identity Asserter." |
Entitled Cache Service |
Wraps a cache service for access control. See Section A.6.6, "Entitled Cache Service." |
Entitled Invocation Service |
Wraps an invocation service for access control. See Section A.6.7, "Entitled Invocation Service." |
Entitled Named Cache |
Wraps a named cache for access control. See Section A.6.8, "Entitled Named Cache." |
The Coherence Live Events Examples are available for the Java platform only. They include the following:
Table A-3 Coherence Live Events Examples
Example Name | Description |
---|---|
EventsExamples |
Illustrates various features within Live Events, such as providing mean elapsed times split by event type, the different semantics in throwing exceptions in pre-events compared to post-events, and logging of partition movement when enabled. See Section A.7.2, "EventsExamples." |
TimedTraceInterceptor |
Provides timings between pre- and post-commit events for different types of events. See Section A.7.3, "TimedTraceInterceptor." |
CantankerousInterceptor |
Responds with runtime exceptions at either pre- or post-commit time, based on the type of key being inserted. See Section A.7.4, "CantankerousInterceptor." |
RedistributionInterceptor |
Logs partition events when enabled. See Section A.7.5, "RedistributionInterceptor." |
RedistributionInvocable |
Defines three actionable states that will be executed on various members of the cluster. The states are enable logging performed by the RedistributionInterceptor, disable logging, or terminate the JVM that the invocable (RedistributionInvocable) is executed on. See Section A.7.6, "RedistributionInvocable." |
LazyProcessor |
Creates a superficial delay between the processing of events. See Section A.7.7, "LazyProcessor." |
You can obtain the examples.zip
file by performing a full Coherence installation with the coherence_
version.jar
or wls_
version.jar
installer file. The Coherence examples appear as an installation option in the Oracle Universal Installer.
If you have already installed Coherence but without the examples, you can obtain the examples.zip
file by running the coherence_quick_supp_
version.jar
supplemental installer file. The supplemental installer contains only API documentation and examples.
Note that the coherence_quick_
version.jar
quick installer file does not install the examples or API documentation.
Unzip the contents of the examples.zip
file into an examples
directory.
Note: You must build and run the Java example even for .NET and C++. This is because the cache server runs in Java. |
This section contains the following information:
This section contains the following information:
To build the example, you must have Coherence version 3.7 or later and a Java development kit (JDK) 1.6 or later. Ensure that the following environment variables are set.
Environment Variable | Description |
---|---|
|
Make sure that the |
|
Make sure that the |
The directory structure described below is relative to the examples
directory.
Table A-4 Directory Structure for Java
Directory Name | Description |
---|---|
|
Scripts for building and executing the example. There are two sets of scripts. Scripts with no file extension are bash scripts. Scripts with a
|
|
All example source. The examples are in the |
|
The class files output from a build. This directory will not exist until the build script is executed. |
|
The common Coherence configuration files required by the examples. |
|
If an example has configuration that is required instead of the common configuration, it will have its own directory. The security example uses configuration files from |
|
Coherence libraries used for compiling and running the example. |
Execute the build script with the name of the example collection, for example: bin/build
contacts
, bin/build
security
, or bin/build
events
.
The script will build the POF package files and then the files for the particular example. On Windows, change directories to the /bin
directory then run the scripts.
This section contains the following information:
To build the example, you must have Coherence version 3.7 or later for .NET and Visual Studio 2008 or later or Visual Studio 2008 Express or later.
To run the example, you will need the Java version of Coherence 3.7 or later and a Java development kit (JDK) 1.6 or greater. The Java version is required because the Coherence*Extend proxy and cache servers require Java. Also, the examples depend on Java example classes that must be built before running the proxy and cache server. See the Java example readme.txt
file for instructions on how to build and run. Note that the Java run-proxy
script must be executed; the Java run-cache-server
is optional because the proxy is storage enabled.
The directory structure described below is relative to the examples
directory.
Table A-5 Directory Structure for .NET
Directory Name | Description |
---|---|
dotnet\src |
All example source. The examples are in the The examples are in the Visual Studio 2008 examples solution. Each example has its own Visual Studio 2008 project in the The Coherence configuration files required by the example. |
|
The common Coherence configuration files required by the examples. |
|
If an example has configuration that is required instead of the common configuration, it will have its own directory. The security example uses configuration files from |
Open the examples project from the examples\dotnet\src\contacts.csproj
directory with Visual Studio
When installing Coherence 3.7 for the .NET Framework, the installer registers the coherence.dll
library with the assembly registry. The included Visual Studio projects have a reference to coherence.dll
in the default location. If another version of the library is desired, or it was not installed in the default location, the Coherence reference can be overridden when configuring the reference, be sure to set the local
copy
attribute to true
. This setting will copy and register the correct coherence.dll
in the bin\debug
directory.
After the desired Coherence 3.7 for .NET is configured, in Visual Studio select Build then Build Solution from the menu, Build Solution (F6), etc., to build the solution.
The build for the contacts
example will copy resource\contacts.csv
to the build output directory (examples\dotnet\src\bin\Debug
).
This section contains the following information:
To run the examples, you will need the Java version of Coherence 3.7 or later and a Java development kit (JDK) 1.6 or greater. The Java version is required because the Coherence*Extend proxy and cache servers require Java. Also, the examples depend on Java example classes that must be built before running the proxy and cache server. See the Java examples readme.txt
for instructions on how to build and run. Note that the Java run-proxy
script must be executed; the Java run-cache-server
is optional because the proxy is storage enabled.
Ensure that the following environment variables are set:
Environment Variable | Description |
---|---|
|
Make sure that the |
|
Make sure that the |
|
Make sure that the |
The directory structure described below is relative to the examples
directory.
Table A-6 Directory Structure for C++
Directory Name | Description |
---|---|
|
Scripts for building and executing the examples. Scripts with no file extension are bash scripts. Scripts with a |
|
All example source organized under the |
|
The |
|
The |
|
The d ata model is represented in this directory plus any classes that are serialized. The rationale is to show how to utilize an already existing data model and expose it in Coherence. The model classes do not contain any Coherence-specific code to prove this point. However, there is a serializer that is associated with each model type. For example the The generated output will be in the form of a dynamic library. |
|
The common Coherence configuration files required by the examples. |
|
If an example has configuration that is required instead of the common configuration, it will have its own directory. The security example uses configuration files from |
|
The object files output from a build. This directory will not exist until the build script is executed. |
|
Contains the Coherence header files. |
|
Contains the Coherence library. |
This section contains the following information:
Build Instructions for C++ on Windows
Open a development environment command prompt. This should have been installed with Visual Studio or the platform SDK. Go to the C++ examples
directory and type bin\build.cmd <
example name
>
. This will build both the pof
(model) and the example
executable. For example, bin\build.cmd
contacts
or bin\build.cmd
security
The model will put the pof.lib
and pof.dll
file under cpp\pof\out
. These are needed for building and running the contacts
and security
examples.
The executable contacts.exe
will be generated in cpp\contacts\out
directory. The executable security.exe
will be generated in cpp\security\out
directory.
To run the contacts
example, type bin\run.cmd contacts
after starting a proxy server, java\bin\run-proxy
, and an additional cache server java\bin\run-cache-server
.
As an alternative, in any command window you can cd
to the C++ bin
directory and run vcvars32.bat
before trying to build the examples. With a default install of Visual Studio, the bin
directory is C:\Program Files\Mircorsoft
Visual
Studio
9.0\vc\bin
. Follow the previous instructions for running the build
script.
Build Instructions for C++ on Linux/Mac and Solaris
Open a command shell. Go to the C++ examples
directory and type bin/build <
example name
>
. This will build both the pof
(model) and the contacts
examples executable.
The model dynamic library and lib
file will be put in cpp/pof/out
. These are needed for building and running the contacts
and security
examples.
The executable contacts, will be generated in cpp/contacts/out
or cpp/security/out
.
Note: The Coherence examples are distributed as source, so they must first be built. See Section A.3, "How to Build the Examples." |
This section contains the following information:
This section contains the following information:
To run the examples, you must have Coherence version 3.7 and a Java development kit (JDK) 1.6 or greater.
Environment Variable | Description |
---|---|
|
Make sure that the |
|
Make sure that the |
The directory structure described below is relative to the examples
directory, the directory into which the examples were unzipped.
Table A-7 Directory Structure for Java
Directory Name | Description |
---|---|
|
Scripts for building and executing examples. There are two sets of scripts. Scripts with no file extension are bash scripts. Scripts with a
|
|
The class files output from a build. This directory will not exist until the build script is executed. |
|
The common Coherence configuration files required by the examples. |
|
If an example has configuration that is required instead of the common configuration, it will have its own directory. The |
|
Coherence libraries used for compiling and running the examples. |
|
The data file used for the contacts |
Execute the run
script. There are two parts to running the example.
contacts example
Start one or more cache servers: bin/run-cache-server
. Each execution will start a cache server cluster node. To add additional nodes, execute the command in a new command shell.
In a new command shell, run with the name of the example: bin/run contacts
. The Driver.main
method will run through the features of the example with output going to the command window (stdout
).
Starting with Coherence 3.7, an example of the new Query Language feature was added. This example shows how to configure and use a simple helper class FilterFactory
using the Coherence InvocationService
.
security example
The security
example requires Coherence*Extend, which uses a proxy.
Start a proxy: bin/run-proxy security
.
Optionally, start one or more cache servers as described in the contacts
example. The proxy is storage-enabled, so it will act as both a proxy and a cache server node.
In a new command shell, run with the name of the example: bin/run security
. The Driver.main
method will run through the features of the example with output going to the command window (stdout
).
events example
Start one or more cache servers: bin/run-cache-server
. Each execution will start a cache server cluster node. To add additional nodes, execute the command in a new command shell.
In a new command shell, run with the name of the example: bin/run events
. The Driver.main
method will run through the features of the example with output going to the command window (stdout
).
This section contains the following information:
To run the examples, you must have Coherence version 3.7 or later for .NET and Visual Studio 2008 or later. To run the examples, you will also need to build the Java examples. The Java version is required because the Coherence*Extend proxy and cache servers require Java.
Also, the examples depend on Java example classes that must be built before running the proxy and cache server.
The directory structure described below is relative to the "examples
" directory.
The following sections contain instructions for running the contacts
and security
examples.
contacts
Following the Java instructions, start a proxy server (run-proxy
) and zero or more cache servers (run-cache-server
).
From Visual Studio, start the contacts
project without debugging or execute the contacts.exe
produced from the build in a command shell. The Driver.Main
method will run through the features of the example with the output going to the command window (stdout).
Starting with Coherence 3.7, a new example of the new Query Language feature was integrated. This example shows how configure and use a simple helper class "FilterFactory
" using the Coherence InvocationService
.
security
Following the java readme.txt instructions, start a proxy server (java/bin/run-proxy security
) and zero or more cache servers.
From Visual Studio, start the security project without debugging or execute the contacts.exe
produced from the build in a command shell. The Driver.Main
method will run through the features of the example with the output going to the command window (stdout).
This section contains the following information:
To build the examples, you must have the appropriate C++ library of Coherence version 3.7. Also you must have a C++ development environment. To run the examples, you will also need to build the Java examples. The Java version is required because the Coherence*Extend proxy and cache servers require Java. Also, the examples depend on Java example classes that must be built before running the proxy and cache server.
Environment Variable | Description |
---|---|
|
Make sure that the |
The supported C++ compilers are:
Windows —Microsoft Visual C++ Express/Studio 2008 or later or the equivalent Platform SDK.
Linux—g++ 4.0
Mac—g++ 4.0
The directory structure described below is relative to the examples
directory.
Table A-9 Directory Structure for C++
Directory Name | Description |
---|---|
|
Scripts for building and executing the examples. Scripts with no file extension are bash scripts. Scripts with a
|
|
All example source organized under the |
|
The object files output from a build. This directory will not exist until the build script is executed. |
|
The data file used for the contacts LoaderExample: contacts.csv. |
|
Contains the |
|
Contains the |
|
Contains the |
|
Contains the Coherence header files. |
|
Contains the Coherence library. |
Execute the run
scripts. There are two parts to running the example. From within new command shells:
contacts example
Start one proxy server: java/bin/run-proxy contacts
.
Optionally, start one or more cache servers: bin/run-cache-server
. Each execution will start a cache server cluster node. To add additional nodes, execute the command in a new command shell.
In a new command shell, execute run with the name of the example:
Running the contacts Example on Windows:
Type bin\run.cmd
contacts
Running the contacts Example on Linux/Mac and Solaris:
Type bin/run
contacts
The Driver.main
method will run through the features of the example with output going to the command window (stdout
).
Starting with Coherence 3.7, an example of the new Query Language feature was added. This example shows how to configure and use a simple helper class FilterFactory
using the Coherence InvocationService
.
security example
Start one proxy server: java/bin/run-proxy security
.
Optionally, start one or more cache servers: bin/run-cache-server
. Each execution will start a cache server cluster node. To add additional nodes, execute the command in a new command shell.
In a new command shell, execute run
with the name of the example:
Running the security Example on Windows:
Type bin\run.cmd
security
Running the security Example on Linux/Mac and Solaris:
Type bin/run
security
The Driver.main
method will run through the features of the example with output going to the command window (stdout
).
The Coherence basic features examples are a collection of examples that show how to use the basic features of Coherence using a simplified contact information tracker and includes:
Basic Data Access—"Getting", "putting" and "removing" data from the Coherence Data Grid. See Section A.5.3, "Basic Data Access Example."
Data Loading—Loading example data into the Coherence Data Grid. See Section A.5.4, "Loader Example."
Parallel Querying —Querying the Coherence Data Grid including the use of indexes. See Section A.5.5, "Query Example."
Observable—Listening for changes to data in the Coherence Data Grid. See Section A.5.6, "Observer Example."
Processing—Co-locating data processing with the data itself in the Coherence Data Grid. See Section A.5.7, "Processor Example."
Query Language—How to use the new 3.6 Coherence Query Language. See Section A.5.8, "Query Language."
This example set uses example data represented by these Data Model classes.
Table A-10 Data Model Classes for the Features Examples
Name | Description |
---|---|
|
Address information |
|
Contact information (includes addresses and phone numbers) |
|
The key (contact name) to the contact information |
|
Phone number |
This example set also ships with a contacts.csv
file which is a comma-delimited value file containing sample Contacts
information.
Review the following information:
Review the information on the Driver implementation found in Section A.5.2, "Understanding the Features Driver File."
The Driver file has a static main
method that executes all the Contacts examples in the following order:
LoaderExample
QueryExample
QueryLanguageExample
ObserverExample
BasicExample
ProcessorExample
The Driver file is implemented in each of the three programming languages supported by Coherence.
Language | Implementation Class |
---|---|
Java |
|
.NET |
Driver in namespace |
C++ |
Driver in namespace |
Please refer to this example set's examples.zip
file for more details on each of the examples outlined below.