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.
Implementation Class:
com.tangosol.examples.contacts.LoaderExample in java/src
cache.putAll(mapBatch);
Implementation Class:
LoaderExample in namespace Tangosol.Examples.Contacts in dotnet/src/contacts
cache.InsertAll(dictBatch);
Implementation Class:
LoaderExample in namespace coherence::examples in cpp/contacts
hCache->putAll(hMapBatch);
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.
Implementation Class:
com.tangosol.examples.contacts.QueryExample in java/src
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.
Implementation Class:
com.tangosol.examples.contacts.ObserverExample in java/src
ContactChangeListener is a class that extends the MapListener type using Coherence extend macro.
class ContactChangeListener
: public class_spec<ContactChangeListener,
extends <MapListener> >
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.
Implementation Class:
com.tangosol.examples.contacts.ProcessorExample in java/src
Helper Class:
com.tangosol.examples.contacts.OfficeUpdater in java/src
Apply the OfficeUpdater on all contacts who live in MA. The OfficeUpdater is a class that implements the InvocableMap.EntryProcessor interface by extending AbstractProcessor.
cache.invokeAll(new EqualsFilter("getHomeAddress.getState", "MA"), new OfficeUpdater(addrWork));
Implementation Class:
ProcessorExample in namespace Tangosol.Examples.Contacts in dotnet/src/contacts
Helper Class:
OfficeUpdater in namespace Tangosol.Examples.Contacts in dotnet/src/contacts
Apply the OfficeUpdater on all contacts who live in MA. The OfficeUpdater is a class that implements the IEntryProcessor interface by extending AbstractProcessor.
cache.InvokeAll(new EqualsFilter("getHomeAddress.getState", "MA"), new OfficeUpdater(addrWork));
Implementation Class:
ProcessorExample in namespace coherence::examples in cpp/contacts
Helper Class:
OfficeUpdater in namespace coherence::examples in cpp/contacts
The OfficeUpdater is a class that extends the UpdaterProcessor type.
class OfficeUpdater
: public class_spec<OfficeUpdater,
extends<UpdaterProcessor>,
implements<PortableObject> >
Apply the OfficeUpdater on all contacts who live in MA.
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.