Show / Hide Table of Contents

Class KeyAssociatedFilter

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

Inheritance
object
KeyAssociatedFilter
Implements
IFilter
IPortableObject
Inherited Members
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
Namespace: Tangosol.Util.Filter
Assembly: Coherence.dll
Syntax
public class KeyAssociatedFilter : IFilter, IPortableObject
Remarks

This filter is intended to be used to optimize queries for partitioned caches that utilize any of the key association algorithms (by implementing either KeyAssociator or 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.)

Note 2: This filter is intended to be processed only on the client side of the partitioned cache service.

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 Id property that returns a Long value that uniquely identifies the object. Similarly, the ParentKey and ChildKey classes have a Id property that uniquely identifies the corresponding cached object. Futhermore, the Child and ChildKey classes include a ParentId property that returns the Long identifier of the Parent object.

There are two ways to ensure that Child objects are collocated with their Parent objects (in the same storage-enabled cluster node).
  1. Make the ChildKey class implement KeyAssociation as follows:
    public Object AssociatedKey
     {
         get { return ParentId; }
     }
    and the ParentKey class implement KeyAssociation as follows:
    public Object AssociatedKey
     {
         get { return Id; }
     }
  2. Implement a custom KeyAssociator as follows:
    public object GetAssociatedKey(object key)
     {
         if (key is ChildKey)
         {
             return ((ChildKey) key).ParentId;
         }
         else if (key is ParentKey)
         {
             return ((ParentKey) key).Id;
         }
         else
         {
         return null;
         }
     }
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 parentKey = new ParentKey(...);
 Long      parentId  = parentKey.Id;

// this Filter will be applied to all Child objects in order to fetch // those for which ParentId returns the specified Parent identifier IFilter filterEq = new EqualsFilter("ParentId", parentId);

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

// run the optimized query to get the ChildKey objects ICollection colChildKeys = cacheChildren.Keys(filterAsc);

// get all the Child objects at once ICollection colChildren = cacheChildren.GetAll(colChildKeys);

To remove the Child objects you would then do the following:
cacheChildren.Keys.RemoveAll(colChildKeys);

Constructors

KeyAssociatedFilter()

Default constructor.

Declaration
public KeyAssociatedFilter()

KeyAssociatedFilter(IFilter, object)

Construct a key associated filter.

Declaration
public KeyAssociatedFilter(IFilter filter, object hostKey)
Parameters
Type Name Description
IFilter filter

The underlying (wrapped) filter.

object hostKey

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

Properties

Filter

Obtain the wrapped IFilter.

Declaration
public virtual IFilter Filter { get; }
Property Value
Type Description
IFilter

The wrapped filter object.

HostKey

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

Declaration
public virtual object HostKey { get; }
Property Value
Type Description
object

The host key.

Methods

Equals(object)

Compare the KeyAssociatedFilter with another object to determine equality.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
object obj

The KeyAssociatedFilter to compare to.

Returns
Type Description
bool

true if this KeyAssociatedFilter and the passed object are equivalent KeyAssociatedFilter objects.

Overrides
object.Equals(object)
Remarks

Two KeyAssociatedFilter objects are considered equal if the wrapped filters and host keys are equal.

Evaluate(object)

Apply the test to the object.

Declaration
public virtual bool Evaluate(object o)
Parameters
Type Name Description
object o

An object to which the test is applied.

Returns
Type Description
bool

true if the test passes, false otherwise.

GetHashCode()

Determine a hash value for the KeyAssociatedFilter object according to the general object.GetHashCode() contract.

Declaration
public override int GetHashCode()
Returns
Type Description
int

An integer hash value for this KeyAssociatedFilter object.

Overrides
object.GetHashCode()

ReadExternal(IPofReader)

Restore the contents of a user type instance by reading its state using the specified IPofReader object.

Declaration
public virtual void ReadExternal(IPofReader reader)
Parameters
Type Name Description
IPofReader reader

The IPofReader from which to read the object's state.

Exceptions
Type Condition
IOException

If an I/O error occurs.

ToString()

Return a human-readable description for this KeyAssociatedFilter.

Declaration
public override string ToString()
Returns
Type Description
string

A string description of the KeyAssociatedFilter.

Overrides
object.ToString()

WriteExternal(IPofWriter)

Save the contents of a POF user type instance by writing its state using the specified IPofWriter object.

Declaration
public virtual void WriteExternal(IPofWriter writer)
Parameters
Type Name Description
IPofWriter writer

The IPofWriter to which to write the object's state.

Exceptions
Type Condition
IOException

If an I/O error occurs.

Implements

IFilter
IPortableObject
In this article
Back to top Copyright © 2000, 2024, Oracle and/or its affiliates.