com.tangosol.util.filter.PartitionedFilter Maven / Gradle / Ivy
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
package com.tangosol.util.filter;
import com.tangosol.io.ExternalizableLite;
import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;
import com.tangosol.net.partition.PartitionSet;
import com.tangosol.util.ExternalizableHelper;
import com.tangosol.util.Filter;
import com.tangosol.util.InvocableMapHelper;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Map;
import javax.json.bind.annotation.JsonbProperty;
/**
* Filter which limits the scope of another filter to those entries that have
* keys that belong to the specified partition set.
*
* This filter is intended to be used in advanced scenarios, when a caller wants
* to retrieve the results of parallel processing restricted to a subset of
* partitions. This approach may somewhat complicate the client code, but can
* dramatically reduce the memory footprint used by the requestor.
*
* Below are two examples of PartitionedFilter usage:
*
* - Run a parallel query partition-by-partition:
*
* void executeByPartitions(NamedCache cache, Filter filter)
* {
* DistributedCacheService service =
* (DistributedCacheService) cache.getCacheService();
* int cPartitions = service.getPartitionCount();
*
* PartitionSet parts = new PartitionSet(cPartitions);
* for (int iPartition = 0; iPartition < cPartitions; iPartition++)
* {
* parts.add(iPartition);
*
* Filter filterPart = new PartitionedFilter(filter, parts);
*
* Set setEntriesPart = cache.entrySet(filterPart);
*
* // process the entries ...
*
* parts.remove(iPartition);
* }
* }
*
* - Run a parallel query member-by-member:
*
* void executeByMembers(NamedCache cache, Filter f)
* {
* DistributedCacheService service =
* (DistributedCacheService) cache.getCacheService();
* int cPartitions = service.getPartitionCount();
*
* PartitionSet partsProcessed = new PartitionSet(cPartitions);
* for (Iterator iter = service.getStorageEnabledMembers().iterator();
* iter.hasNext();)
* {
* Member member = (Member) iter.next();
*
* PartitionSet partsMember = service.getOwnedPartitions(member);
*
* // due to a redistribution some partitions may have already been processed
* partsMember.remove(partsProcessed);
*
* Filter filterPart = new PartitionedFilter(filter, partsMember);
* Set setEntriesPart = cache.entrySet(filterPart);
*
* // process the entries ...
*
* partsProcessed.add(partsMember);
* }
*
* // due to a possible redistribution, some partitions may have been skipped
* if (!partsProcessed.isFull())
* {
* partsProcessed.invert();
* Filter filter = new PartitionedFilter(filter, partsProcessed);
*
* // process the remaining entries ...
* }
* }
*
*
* Note: This filter must be the outermost filter and cannot be used
* as a part of any composite filter (AndFilter, OrFilter, etc.)
*
* To iterate through a query on a partition-by-partition or member-by-member
* basis, use the {@link com.tangosol.net.partition.PartitionedIterator
* PartitionedIterator} class.
*
* @author gg 2008.02.06
* @since Coherence 3.4
*/
public class PartitionedFilter
extends ExternalizableHelper
implements Filter, EntryFilter