/*
 * Copyright 2013 Cloudera 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 com.cloudera.cdk.morphline.stdlib;

import java.util.Collection;
import java.util.Collections;

import com.cloudera.cdk.morphline.api.Command;
import com.cloudera.cdk.morphline.api.CommandBuilder;
import com.cloudera.cdk.morphline.api.MorphlineContext;
import com.cloudera.cdk.morphline.api.Record;
import com.typesafe.config.Config;

/**
 * Command that silently consumes records without ever emitting any record - think /dev/null.
 */
public final class DropRecordBuilder implements CommandBuilder {

  @Override
  public Collection<String> getNames() {
    return Collections.singletonList("dropRecord");
  }

  @Override
  public Command build(Config config, Command parent, Command child, MorphlineContext context) {
    return new DropRecord(config, parent);
  }
  
  
  ///////////////////////////////////////////////////////////////////////////////
  // Nested classes:
  ///////////////////////////////////////////////////////////////////////////////
  private static final class DropRecord implements Command {
    
    private Command parent;
    
    public DropRecord(Config config, Command parent) { 
      this.parent = parent;
    }

    @Override
    public Command getParent() {
      return parent;
    }
    
    @Override
    public void notify(Record notification) {
    }

    @Override
    public boolean process(Record record) {
      return true;
    }

  }

}

@@ -908,30 +908,128 @@
 com.
-typesafe.config.Config
+cloudera.cdk.morphline.base.AbstractCommand;%0Aimport com.typesafe.config.Config;%0Aimport com.typesafe.config.ConfigFactory
 ;%0A%0A/
@@ -1410,24 +1410,99 @@
  context) %7B%0A
+    if (config == null) %7B%0A      return new DevNull(parent);%0A    %7D else %7B%0A  
     return n
@@ -1529,18 +1529,40 @@
 , parent
-);
+, child, context);%0A    %7D
 %0A  %7D%0A  %0A
@@ -1749,16 +1749,77 @@
 ///////%0A
+  /** Implementation that does not do logging and metrics */%0A
   privat
@@ -1840,25 +1840,22 @@
  class D
-ropRecord
+evNull
  impleme
@@ -1922,33 +1922,15 @@
 ic D
-ropRecord(Config config, 
+evNull(
 Comm
@@ -2209,15 +2209,1341 @@
 %0A    %7D%0A%0A
+  %7D%0A  %0A  ///////////////////////////////////////////////////////////////////////////////%0A  // Nested classes:%0A  ///////////////////////////////////////////////////////////////////////////////%0A  /** Implementation that does logging and metrics */%0A  private static final class DropRecord extends AbstractCommand %7B%0A    %0A    public DropRecord(Config config, Command parent, Command child, MorphlineContext context) %7B%0A      super(ConfigFactory.empty(), parent, new DummyCommand(), context);%0A    %7D%0A%0A    @Override%0A    protected void doNotify(Record notification) %7B%0A    %7D%0A%0A    @Override%0A    protected boolean doProcess(Record record) %7B%0A      return true;%0A    %7D%0A%0A  %7D%0A%0A%0A  ///////////////////////////////////////////////////////////////////////////////%0A  // Nested classes:%0A  ///////////////////////////////////////////////////////////////////////////////%0A  /** Hack because passing child=null to AbstractCommand ctor is illegal */%0A  private static final class DummyCommand implements Command %7B%0A    %0A    @Override%0A    public Command getParent() %7B%0A      throw new UnsupportedOperationException();%0A    %7D%0A    %0A    @Override%0A    public void notify(Record notification) %7B%0A      throw new UnsupportedOperationException();%0A    %7D%0A%0A    @Override%0A    public boolean process(Record record) %7B%0A      throw new UnsupportedOperationException();%0A    %7D%0A%0A
   %7D%0A%0A%7D%0A

add logging and metrics to dropRecord command