码迷,mamicode.com
首页 > Web开发 > 详细

Hadoop实战-Flume之自定义Source(十八)

时间:2017-05-17 01:00:10      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:tac   interrupt   har   rri   ring   channel   nts   pac   utf-8   

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Random;

import org.apache.flume.Context;
import org.apache.flume.EventDeliveryException;
import org.apache.flume.PollableSource;
import org.apache.flume.conf.Configurable;
import org.apache.flume.event.EventBuilder;
import org.apache.flume.source.AbstractSource;

public class MySouce extends AbstractSource implements Configurable,
        PollableSource {

    @Override
    public long getBackOffSleepIncrement() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public long getMaxBackOffSleepInterval() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Status process() throws EventDeliveryException {
        try {

            while (true) {

                int max = 20;

                int min = 10;

                Random random = new Random();

                int s = random.nextInt(max) % (max - min + 1) + min;

                HashMap<String, String> header = new HashMap<String, String>();

                header.put("id", Integer.toString(s));

                this.getChannelProcessor().processEvent(
                        EventBuilder.withBody(Integer.toString(s),
                                Charset.forName("UTF-8"), header));
                Thread.sleep(1000);
            }

        } catch (InterruptedException e) {

            e.printStackTrace();

        }
        return null;
    }

    @Override
    public void configure(Context arg0) {
        // TODO Auto-generated method stub

    }

}

 

Hadoop实战-Flume之自定义Source(十八)

标签:tac   interrupt   har   rri   ring   channel   nts   pac   utf-8   

原文地址:http://www.cnblogs.com/qq27271609/p/6864192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!