Oracle Coherence for C++ API


KeyAssociatedFilter Class Reference

#include <coherence/util/filter/KeyAssociatedFilter.hpp>

Inherits Object, PortableObject, and Filter.

List of all members.

Detailed Description

Filter which limits the scope of another filter according to the key association information.

This filter is intended to be used to optimize queries for partitioned caches that utilize any of the key association algorithms (by implementing either coherence::net::partition::KeyAssociator or coherence::net::cache::KeyAssociation) to ensure placement of all associated entries in the same distributed cache partition (and therefore in the same storage-enabled cluster node). Using the KeyAssociatedFilter will instruct the distributed cache to apply the wrapped filter only to the entries stored at the cache service node that owns the specified host key.

Note 1: This filter must be the outermost filter and cannot be used as a part of any composite filter (AndFilter, OrFilter, etc.)

For example, consider two classes called Parent and Child that are stored in separate caches using ParentKey and ChildKey objects respectively. The Parent and Child classes have a getId method that returns a Long value that uniquely identifies the object. Similarly, the ParentKey and ChildKey classes have a getId method that uniquely identifies the corresponding cached object. Futhermore, the Child and ChildKey classes include a getParentId method that returns the Long identifier of the Parent object.

There are two ways to ensure that Child objects are collected with their Parent objects (in the same storage-enabled cluster node).

  1. Make the ChildKey class implement coherence::net::cache::KeyAssociation as follows:
     virtual Object::View getAssociatedKey() const
         return getParentId();
    and the ParentKey class implement coherence::net::cache::KeyAssociation as follows:
     public: virtual Object::View getAssociatedKey()
         return getId();
    Note: a Java version of these classes must also exist and contain the same logic
  2. Implement a custom in Java which will be processed on the cache servers.
The first approach requires a trivial change to the ChildKey and ParentKey classes, whereas the second requires a new class and a configuration change, but no changes to existing classes.

Now, to retrieve all the Child objects of a given Parent using an optimized query you would do the following:

 ParentKey::Handle parentKey = ParentKey::create(...);
 Integer64::View   parentId  = parentKey->getId();

 // this Filter will be applied to all Child objects in order to fetch those
 // for which getParentId() returns the specified Parent identifier
 Filter::View filterEq = EqualsFilter::create(ReflectionExtractor::create(
       "getParentId"), parentId);

 // this Filter will direct the query to the cluster node that currently
 // owns the Parent object with the given identifier
 Filter::View filterAsc =  KeyAssociatedFilter::create(filterEq, parentId);

 // run the optimized query to get the ChildKey objects
 Set::View setChildKeys = cacheChildren->keySet(filterAsc);

 // get all the Child objects at once
 Set::Handle setChildren = cacheChildren->getAll(setChildKeys);
To remove the Child objects you would then do the following:

djl 2008.05.19

Public Types

typedef spec::Handle Handle
 KeyAssociatedFilter Handle definition.
typedef spec::View View
 KeyAssociatedFilter View definition.
typedef spec::Holder Holder
 KeyAssociatedFilter Holder definition.

Public Member Functions

virtual bool evaluate (Object::View v) const
 Apply the test to the object.

v the object to test
true if the test passes, false otherwise

virtual void readExternal (PofReader::Handle hIn)
virtual void writeExternal (PofWriter::Handle hOut) const
virtual bool equals (Object::View v) const
virtual size32_t hashCode () const
 Return a hash code value for the Object.

This method is supported for the benefit of hash-based containers.

The general contract of hashCode is:

  • Whenever it is invoked on the same Object more than once during an execution of an application, the hashCode method must consistently return the same value, provided no information used in equals comparisons on the object is modified. This value need not remain consistent from one execution of an application to another execution of the same application.
  • If two Objects are equal according to the equals method, then calling the hashCode method on each of the two Objects must produce the same value.
  • It is not required that if two Objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct results. However, the programmer should be aware that producing distinct results for unequal objects may improve the performance of hash-based containers.

The default implementation is identity based.

a hash code value for this Object

virtual void toStream (std::ostream &out) const
 Output a human-readable description of this Object to the given stream.

coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toStream method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents.

 Object::View vKey   = ...
 Object::View vValue = ...
 std::cout << vKey << " = " << vValue << std::endl;

 String::Handle hs = COH_TO_STRING(vKey << " = " << vValue);

out the stream used to output the description

virtual Filter::View getFilter () const
 Obtain the wrapped Filter.
virtual Object::View getHostKey () const
 Obtain the host key that serves as an associated key for all keys that the wrapped filter will be applied to.

Protected Member Functions

 KeyAssociatedFilter ()
 Default constructor (necessary for the PortableObject interface).
 KeyAssociatedFilter (Filter::View vFilter, Object::View vHostKey)
 Construct a key associated filter.

Protected Attributes

FinalView< Filterm_vFilter
 The underlying filter.
FinalView< Objectm_vHostKey
 The association host key.

Constructor & Destructor Documentation

KeyAssociatedFilter ( Filter::View  vFilter,
Object::View  vHostKey 
) [protected]

Construct a key associated filter.

vFilter the underlying (wrapped) filter
vHostKey the host key that serves as an associated key for all keys that the wrapped filter will be applied to

Member Function Documentation

virtual Filter::View getFilter (  )  const [virtual]

Obtain the wrapped Filter.

the wrapped filter object

virtual Object::View getHostKey (  )  const [virtual]

Obtain the host key that serves as an associated key for all keys that the wrapped filter will be applied to.

the host key

The documentation for this class was generated from the following file:
Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.