ImportJava.nio.charset.Charset;ImportJava.util.HashMap;ImportJava.util.Random;ImportOrg.apache.flume.Context;Importorg.apache.flume.EventDeliveryException;ImportOrg.apache.flume.PollableSource;Importorg.apache.flume.conf.Configurable;ImportOrg.apache.flume.event.EventBuilder;ImportOrg.apache.flume.source.AbstractSource; Public classMysouceextendsAbstractsourceImplementsConfigurable, Pollablesource {@Override Public Longgetbackoffsleepincrement () {//TODO auto-generated Method Stub return0; } @Override Public LongGetmaxbackoffsleepinterval () {//TODO auto-generated Method Stub return0; } @Override PublicStatus process ()throwseventdeliveryexception {Try { while(true) { intmax = 20; intMin = 10; Random Random=NewRandom (); ints = random.nextint (max)% (Max-min + 1) +min; HashMap<string, string> Header =NewHashmap<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 voidConfigure (Context arg0) {//TODO auto-generated Method Stub }}
Hadoop actual combat-flume Custom Source (18)