/*
 * Copyright (c) 2013 DataTorrent, Inc. ALL Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.datatorrent.api;

import java.io.IOException;
import java.util.List;

import com.datatorrent.api.Stats.OperatorStats;


/**
 * Listener for operator status updates.
 * <p>
 * Can be directly implemented by operator class or defined via operator context attribute. Implementation in the
 * operator allows the operator developer to define a handler that along with the stats can access the operator
 * properties and control partitioning.
 *
 * @since 0.9.1
 */
public interface StatsListener
{
  /**
   * Command to be executed at subsequent end of window on the operator instance that is deployed in the container.
   * Provides the opportunity to define operator specific actions such as method invocation or property set.
   */
  public interface OperatorCommand
  {
    /**
     * Execute the command.
     *
     * @param operator
     * @param operatorId
     * @param windowId
     * @throws IOException
     */
    public void execute(Operator operator, int operatorId, long windowId) throws IOException;
  }

  /**
   * List of recent, per window operator stats and moving averages.
   */
  public interface BatchedOperatorStats
  {
    /**
      Stats list will typically contain multiple entries, depending on streaming window size and heartbeat interval.
     */
    List<OperatorStats> getLastWindowedStats();
    int getOperatorId();
    long getCurrentWindowId();
    long getTuplesProcessedPSMA();
    long getTuplesEmittedPSMA();
    double getCpuPercentageMA();
    long getLatencyMA();
  }

  public class Response
  {
    /**
     * Set true to request repartition of the logical operator.
     * The controller will call {@link PartitionableOperator#definePartitions(java.util.Collection, int)} if applicable.
     */
    public boolean repartitionRequired;

    /**
     * Load indicator for the partition. See {@link PartitionableOperator.Partition#getLoad()}.
     * Taken into consideration on repartition.
     */
    public int loadIndicator;

    /**
     * List of commands to be executed on all deployed operator instances.
     */
    public List<OperatorCommand> operatorCommands;
  }

  /**
   * Called when new stats become available and status for operator is updated.
   * @param status
   */
  Response processStats(BatchedOperatorStats stats);

}

@@ -675,16 +675,45 @@
 eption;%0A
+import java.io.Serializable;%0A
 import j
@@ -1925,16 +1925,34 @@
 terval.%0A
+      * @return %0A 
      */%0A
@@ -2209,16 +2209,40 @@
 Response
+ implements Serializable
 %0A  %7B%0A   
@@ -2812,16 +2812,81 @@
 ommands;
+%0A%0A    private static final long serialVersionUID = 201401201506L;
 %0A  %7D%0A%0A  
@@ -2985,18 +2985,30 @@
 ram stat
-u
 s
+%0A   * @return
 %0A   */%0A 

Make StatsListener.Response serializable.