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

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

    }

}
时间: 2025-01-14 17:08:53

Hadoop实战-Flume之自定义Source(十八)的相关文章

Hadoop实战-Flume之自定义Sink(十九)

import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.flume.Channel; import org.apache.flume.Context; import org.apache.flume.Event; import org.apache.flume.EventDeli

Hadoop实战-Flume之Hdfs Sink(十)

a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # Describe the sink #a1.sinks.k1.type = logger a1.sinks.k1.type = hdfs a1.sinks.k1.hd

Hadoop实战-Flume之Source replicating(十四)

a1.sources = r1 a1.sinks = k1 k2 a1.channels = c1 c2 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # Describe the sink a1.sinks.k1.type =file_roll a1.sinks.k1.sink.directory=/hom

Hadoop实战-Flume之Source regex_extractor(十二)

a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 a1.sources.r1.interceptors = i1 i2 i3 i4 a1.sources.r1.interceptors.i4.type = timesta

Hadoop实战-Flume之Source regex_filter(十三)

a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 a1.sources.r1.interceptors =i5 #a1.sources.r1.interceptors.i4.type = timestamp #a1.so

Hadoop实战-Flume之Source interceptor(十一)(2017-05-16 22:40)

a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 a1.sources.r1.interceptors = i1 i2 i3 a1.sources.r1.interceptors.i1.type = timestamp

Hadoop实战-Flume之Hello world(九)

环境介绍: 主服务器ip:192.168.80.128 1.准备apache-flume-1.7.0-bin.tar文件 2.上传到master(192.168.80.128)服务器上 3.解压apache-flume-1.7.0-bin.tar tar -zxvf apache-flume-1.7.0-bin.tar 4.进入到Flume的配置文件目录 cd /apache-flume-1.7.0-bin/conf 5.修改apache-flume-1.7.0-bin/conf的里面内容 a1

Hadoop实战-Flume之Sink Load-balancing(十七)

a1.sources = r1 a1.sinks = k1 k2 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # Describe the sink a1.sinks.k1.type =file_roll a1.sinks.k1.sink.directory=/home/c

Android实战简易教程-第五十八枪(AlarmManager类用法研究小实例)

一.概念及相关方法 android中实现定时任务一般有两种实现方式,一种是使用Java API中提供的Timer类,一种是使用android的Alarm机制.Timer机制有个短板就是不太适用于那些需要长期在后台运行的任务,我们都知道为了让电池更加耐用,会在长时间不操作手机的情况下,CPU进入休眠状态,这是可能导致Timer中的定时任务无法正确运行.所以我们重点来研究一下Alarm机制. AlarmManager,顾名思义,就是"提醒",是Android中常用的一种系统级别的提示服务,