/*
 *  Copyright (c) 2012 Malhar, Inc.
 *  All Rights Reserved.
 */
package com.malhartech.api;

import java.util.List;
import java.util.Map;

/**
 *
 * @author Chetan Narsude <chetan@malhar-inc.com>
 */
public interface PartitionableOperator extends Operator
{
  /**
   * Give an opportunity to the operator to decide how it would like to clone itself
   * into multiple copies so that they all collectively can do the work by working on
   * only a partition of the data.
   *
   * @param partitions - Current partitions, containing at least one entry.
   *
   * @return New partitioning. Partitions from input list which should not be changed can be returned
   * as they are.
   */
  public List<Partition> definePartitions(List<? extends Partition> partitions);

  public interface Partition
  {
    /**
     * Return the partition keys for this partition.
     * Input ports that are not mapped will receive all data.
     * @return
     */
    public Map<InputPort<?>, List<Integer>> getPartitionKeys();

    /**
     * Get an indication of the load handled by this particular partition.
     *
     * @return An positive integer is an indicative of the load handled by the partition.
     */
    public int getLoad();

    /**
     * Get the frozen state of the operator which is currently handling the partition.
     *
     * @return frozen operator instance
     */
    public PartitionableOperator getOperator();

    /**
     * Create a new partition for the given operator. The returned partition
     * needs to be further configured with the port to partition key mapping.
     *
     * @return
     */
    public Partition getInstance(PartitionableOperator operator);
  }
}

@@ -134,16 +134,38 @@
 til.Map;
+%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -783,16 +783,97 @@
 ions);%0A%0A
+  public class PartitionKeys%0A  %7B%0A    int mask;%0A    Set%3CInteger%3E partitions;%0A  %7D%0A%0A
   public
@@ -1076,21 +1076,21 @@
 ?%3E, 
-List%3CInteger%3E
+PartitionKeys
 %3E ge

support bitwise partition in PartitionableOperator.