North Concepts
home » data pipeline » examples » Throttle data being read

Throttle data being read

/*
* Copyright (c) 2006-2008 North Concepts Inc.  All rights reserved.
* Proprietary and Confidential.  Use is subject to license terms.
*
* http://northconcepts.com/data-pipeline/licensing/
*
*/
package com.northconcepts.datapipeline.examples.cookbook;

import java.io.File;

import org.apache.log4j.Logger;

import com.northconcepts.datapipeline.core.DataEndpoint;
import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.DataWriter;
import com.northconcepts.datapipeline.csv.CSVReader;
import com.northconcepts.datapipeline.csv.CSVWriter;
import com.northconcepts.datapipeline.job.JobTemplate;
import com.northconcepts.datapipeline.throttle.ThrottledReader;

public class ThrottleDataBeingRead {
   
   
public static final Logger log = DataEndpoint.log;

   
private static final int MAX_BYTES_PER_SECOND = 1024;

   
public static void main(String[] args) throws Throwable {
       
DataReader reader = new CSVReader(new File("credit-balance.csv"))
           
.setFieldNamesInFirstRow(true);
       
        DataWriter writer =
new CSVWriter(new File("credit-balance4.csv"))
           
.setFieldNamesInFirstRow(true);

        ThrottledReader throttledReader =
new ThrottledReader(reader, MAX_BYTES_PER_SECOND);

        JobTemplate.DEFAULT.transfer
(throttledReader, writer);
        log.debug
("read rate: " + throttledReader.getMeter().getUnitsPerSecondAsString());
   
}

}

back to examples index

© 2010 North Concepts Inc.   All rights reserved. | Contact Us