/*
 * Copyright © 2015 Cask Data, Inc.
 *
 * 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 $package;

import co.cask.cdap.api.annotation.Description;
import co.cask.cdap.api.annotation.Name;
import co.cask.cdap.api.annotation.Plugin;
import co.cask.cdap.api.data.format.StructuredRecord;
import co.cask.cdap.api.templates.plugins.PluginConfig;
import co.cask.cdap.templates.etl.api.Emitter;
import co.cask.cdap.templates.etl.api.PipelineConfigurer;
import co.cask.cdap.templates.etl.api.config.ETLStage;
import co.cask.cdap.templates.etl.api.realtime.RealtimeContext;
import co.cask.cdap.templates.etl.api.realtime.RealtimeSource;
import co.cask.cdap.templates.etl.api.realtime.SourceState;

import javax.annotation.Nullable;

/**
 * Realtime Source to poll data from external sources.
 */
@Plugin(type = "source")
@Name("Source")
@Description("Realtime Source")
public class Source extends RealtimeSource<StructuredRecord> {

  private final SourceConfig config;

  public Source(SourceConfig config) {
    this.config = config;
  }


  /**
   * Config class for Source.
   */
  public static class SourceConfig extends PluginConfig {

    @Name("param")
    @Description("Source Param")
    private String param;
    // Note:  only primitives (included boxed types) and string are the types that are supported

  }

  
  @Nullable
  @Override
  public SourceState poll(Emitter<StructuredRecord> writer, SourceState currentState) {
    // Poll for new data
    // Write structured record to the writer
    //writer.emit(myStructuredRecord);
    return currentState;
  }

  @Override
  public void initialize(RealtimeContext context) throws Exception {
    super.initialize(context);
    // No-op
    // Get Config param and use to initialize
    // String param = config.param
    // Perform init operations, external operations etc.
  }

  @Override
  public void destroy() {
    // No-op
    // Handle destroy life
  }
}


@@ -823,143 +823,84 @@
 api.
-templates.plugins.PluginConfig;%0Aimport co.cask.cdap.templates.etl.api.Emitter;%0Aimport co.cask.cdap.templates.etl.api.Pipel
+dataset.lib.KeyValue;%0Aimport co.cask.cdap.api.templates.plugins.Plug
 in
-e
 Config
-urer
 ;%0Aim
@@ -909,32 +909,36 @@
 rt co.cask.cdap.
+api.
 templates.etl.ap
@@ -935,31 +935,32 @@
 tes.
-etl.api.config.ETLStage
+plugins.PluginProperties
 ;%0Aim
@@ -999,32 +999,15 @@
 api.
-realtime.RealtimeContext
+Emitter
 ;%0Aim
@@ -1046,25 +1046,19 @@
 api.
-realtime.Realtime
+batch.Batch
 Sour
@@ -1103,63 +1103,32 @@
 api.
-realtime.SourceState;%0A%0Aimport javax.annotation.Nullable
+batch.BatchSourceContext
 ;%0A%0A/
@@ -1133,24 +1133,21 @@
 %0A/**%0A * 
-Realtime
+Batch
  Source 
@@ -1241,24 +1241,21 @@
 iption(%22
-Realtime
+Batch
  Source%22
@@ -1288,23 +1288,36 @@
 nds 
-RealtimeSource%3C
+BatchSource%3Cbyte%5B%5D, byte%5B%5D, 
 Stru
@@ -1728,23 +1728,8 @@
  %7D%0A%0A
-  %0A  @Nullable%0A
   @O
@@ -1749,286 +1749,51 @@
 lic 
-SourceState poll(Emitter%3CStructuredRecord%3E writer, SourceState currentState) %7B%0A    // Poll for new data%0A    // Write structured record to the writer%0A    //writer.emit(myStructuredRecord);%0A    return currentState;%0A  %7D%0A%0A  @Override%0A  public void initialize(RealtimeContext context
+void initialize(PluginProperties properties
 ) th
@@ -1834,15 +1834,18 @@
 ize(
-context
+properties
 );%0A 
@@ -2029,63 +2029,346 @@
 oid 
-destroy() %7B%0A    // No-op%0A    // Handle destroy life%0A  %7D%0A%7D
+prepareJob(BatchSourceContext context) %7B%0A    // Configure hadoop job before running in batch.%0A  %7D%0A%0A  @Override%0A  public void destroy() %7B%0A    // No-op%0A    // Handle destroy life%0A  %7D%0A%0A%0A%0A  @Override%0A  public void transform(KeyValue%3Cbyte%5B%5D, byte%5B%5D%3E input, Emitter%3CStructuredRecord%3E emitter) throws Exception %7B%0A    // emitter.emit(value);%0A  %7D%0A%7D%0A
 %0A%0A

Fix batch source