The "Basic Coherence Features Examples"Is a collection of examples that show how to use the basic features of Coherence using a simplified contact information tracker and includes:
This Example Set
Running the Example SetFist, review the following information: |
|
Second, review the information on the Driver implementation found here:
The Driver
Has a static main method that executes all the Contacts examples in the following order:
- LoaderExample
- QueryExample
- ObserverExample
- BasicExample
- ProcessorExample
Is implemented in each of the three programming languages supported by Coherence:
| Language | Implementation Class |
|---|---|
| Java | com.tangosol.examples.contacts.Driver in java/src |
| .NET | Driver in namespace Tangosol.Examples.Contacts in dotnet/src/contacts |
| CPP | Driver in namespace coherence::examples in cpp/contacts |
| Please refer to this example set's source code for more details on each of the examples outlined below. |
Basic Data Access Example
This example shows the most basic data access features of Coherence including getting, putting and removing data.
The example Output (due to Observer Example):
entry inserted: John Nocyefqgqo Addresses Home: 1500 Boylston St. null Obopnof, NM 88824 US Work: 8 Yawkey Way null Ssedhvmdeq, OR 84217 US Phone Numbers work: +11 0 707 3776578 Birth Date: 1971-12-31 entry deleted: John Nocyefqgqo Addresses Home: 1500 Boylston St. null Obopnof, NM 88824 US Work: 8 Yawkey Way null Ssedhvmdeq, OR 84217 US Phone Numbers work: +11 0 707 3776578 Birth Date: 1971-12-31
Loader Example
This example loads contacts into the cache from a file or stream.
It demonstrates the most effective way of inserting data into a cache using bulk inserts. This will allow for minimizing the number of network roundtrips between the application and the cache.
Example output:
.........Added 10000 entries to cache
Query Example
QueryExample runs sample queries for contacts.
The purpose of this example is to show how to create Extractors on cache data and how to create a KeyExtractor for the cache keys. It also illustrates how to use the indexes to filter the dataset in order to efficiently create a matching set. Finally, the example demonstrates how to use some of the built-in cache aggregators to do simple computational tasks on the cache data. A subset of the code is shown below.
The example output is large due to 10,000 contacts and several queries. A sample of the query for Massachusetts residents:
MA Residents
ConverterEntry{Key="John Scqngqda", Value="John Scqngqda
Addresses
Home: 265 Beacon St.
Oaskxm, MA 88259
US
Work: Yoyodyne Propulsion Systems
330 Lectroid Rd.
Grover's Mill, OK 95744
US
Phone Numbers
work: +11 88 903 8991283
home: +11 98 553 5878221
Birth Date: 1960-01-03"}
Observer Example
ObserverExample demonstrates how to use a MapListener to monitor cache events such as when cache data has been inserted, updated, and removed. A subset of the code is shown below.
There is no immediate output when this example is run. The registered listener outputs the entry when it is inserted, updated, and deleted. For an update, it outputs both the old value and the new value. The changes to entries are caused by running the Basic Data Access Example and the Processor Example, so the output happens when those examples are run.
Processor Example
ProcessorExample demonstrates how to use a processor to modify a set of data in the cache. In the code sample that follows, all Contacts who live in MA will have their work address updated.
The example Output (due to Observer Example) is large due to the number of contacts. A sample of output:
entry updated old value: John Keau Addresses Home: 443 Beacon St. Ophvowvw, MA 06539 US Work: Yoyodyne Propulsion Systems 330 Lectroid Rd. Grover's Mill, FL 86812 US Phone Numbers work: +11 8 919 9456102 home: +11 25 759 588823 Birth Date: 1968-12-31 new value: John Keau Addresses Home: 443 Beacon St. Ophvowvw, MA 06539 US Work: 200 Newbury St. Yoyodyne, Ltd. Boston, MA 02116 US Phone Numbers work: +11 8 919 9456102 home: +11 25 759 588823 entry updated old value: John Lbggblkd Addresses Home: 929 Beacon St. Trwylbmf, MA 50358 US Work: Yoyodyne Propulsion Systems 330 Lectroid Rd. Grover's Mill, AZ 19164 US Phone Numbers work: +11 60 699 203810 home: +11 34 149 5018157 Birth Date: 1964-01-02 new value: John Lbggblkd Addresses Home: 929 Beacon St. Trwylbmf, MA 50358 US Work: 200 Newbury St. Yoyodyne, Ltd. Boston, MA 02116 US Phone Numbers work: +11 60 699 203810 home: +11 34 149 5018157 Birth Date: 1964-01-02 Birth Date: 1968-12-31
Data Generator
| Implementation Class: | com.tangosol.examples.contacts.DataGenerator in java/src |
|---|
The DataGenerator has a static main method that generates random Contact information and stores the results in a
comma separated value file. This class was used to generate the contacts.csv that is packaged with the contacts examples and is included in case more sample data is needed.
It is implemented only in Java.