package org.calrissian.flowbox.example;

import org.calrissian.flowbox.example.support.ExampleRunner;
import org.calrissian.flowbox.example.support.FlowProvider;
import org.calrissian.flowbox.model.Event;
import org.calrissian.flowbox.model.Flow;
import org.calrissian.flowbox.model.Policy;
import org.calrissian.flowbox.model.builder.FlowBuilder;
import org.calrissian.flowbox.support.Criteria;
import org.calrissian.flowbox.support.aggregator.CountAggregator;

import java.util.List;

import static java.util.Arrays.asList;

public class AggregatorExample implements FlowProvider {
  @Override
  public List<Flow> getFlows() {
    Flow flow = new FlowBuilder()
      .id("flow1")
      .flowDefs()
        .stream("stream1")
          .select().field("key3").end()

          /**
           * Every 5 seconds, emit the counts of events grouped by the key3 field. Don't allow more than 50000
           * items to exist in the window at any point in time (maxCount = 50000)
           */
          .partition().field("key3").end()  // remove this to get the total number of events
          .aggregate().aggregator(CountAggregator.class).evict(Policy.COUNT, 50000).trigger(Policy.TIME, 5).end()
        .endStream()
      .endDefs()
    .createFlow();

    return asList(new Flow[]{flow});
  }

  public static void main(String args[]) {
    new ExampleRunner(new AggregatorExample()).run();
  }
}

@@ -1,8 +1,614 @@
+/*%0A * Copyright (C) 2014 The Calrissian Authors%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 
@@ -765,51 +765,8 @@
 er;%0A
-import org.calrissian.flowbox.model.Event;%0A
 impo
@@ -847,16 +847,16 @@
 Policy;%0A
+
 import o
@@ -908,56 +908,8 @@
 er;%0A
-import org.calrissian.flowbox.support.Criteria;%0A
 impo

add license header to new example