Home > other >  Why add custom in the Flume interceptor will quote us a ClassNotFoundException
Why add custom in the Flume interceptor will quote us a ClassNotFoundException

Time:09-23

RT, I'd like to add a custom in the Flume interceptors, but encountered problems
The following is my flume configuration file:
Agent. The sources=s1
Agent. The channels=c1
Agent. Sinks=k1

Agent. Sources. S1. Type=syslogtcp
Agent. Sources. S1. Host=192.168.1.37
Agent. Sources. S1. The port=i20000
Agent. Sources. S1. Channels=c1
Agent. Sources. S1. Interceptors=i1
Agent. Sources. S1. Interceptors. I1. Type=com. Flume. The interceptor. HbInterceptor $Builder

Agent. Sinks. K1. Type=file_roll
Agent. Sinks. K1. Sink. Directory=/soft/flume/file_sink
Agent. Sinks. K1. Sink. Serializer=text
Agent. Sinks. K1. Channel=c1

Agent. Channels. C1. Type=memory
Agent. Channels. C1. Capacity=1000
Agent. Channels. C1. TransactionCapacity=500
The code below is my custom interceptor class:
Package the flume. The interceptor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

The import org. Apache. The flume. The Context;
The import org. Apache. The flume. The Event;
The import org. Apache. The flume. The interceptor. The interceptor;

Public class HbInterceptor implements Interceptor {

HbInterceptor () {

}

Public void the close () {

}

Public void the initialize () {

}

The public Event intercept (Event Event) {
Try {
Byte [] body=event. GetBody ();
Byte [] frame=Arrays. CopyOfRange (body, 0, 2);
If (frame [0]=='#' & amp; & Frame [1]=='#') {
Byte [] dataLen=Arrays. CopyOfRange (body, frame length,
Frame. The length + 4);
String dataLenStr=String. The valueOf (dataLen);
Int dataLength=Integer. ParseInt (dataLenStr);
Byte [] data=https://bbs.csdn.net/topics/Arrays.copyOfRange (body, frame length
+ dataLen + dataLen. Length, frame length. The length
+ dataLength);
Byte [] crcCheck=Arrays. CopyOfRange (body, frame length
. + dataLen length + dataLength, frame length
+ dataLen. Length + dataLength + 4);
Int dataCRC=ByteStrToInt (crcCheck);
Int CrcSum=checkOutSixteenCheckSum (data, dataLength);
If (dataCRC==CrcSum) {
Event. SetBody (data);
} else {
The event=null;
}
} else {
The event=null;
}
} the catch (Exception e) {
e.printStackTrace();
}

Return the event;
}

Public List Intercept (List Events) {
List Intercepted=new ArrayList (a);
For (Event Event: events) {
The Event interceptorEvent=intercept (Event);
If (interceptorEvent!=null) {
Intercepted. Add (interceptorEvent);
}
}
Return intercepted.
}

Public static class Builer implements Interceptor. Builder {

Public void the configure (Context Context) {

}

Public Interceptor build () {
Return new HbInterceptor ();
}

}

//\ u5c06 \ u7ec8 \ u7aef \ u8ba1 \ u7b97 \ u7684CRC \ u8ba1 \ u7b97 \ u503c \ u8f6c \ u5316 \ u6210int \ u578b
Public int ByteStrToInt (byte [] checkSum) {
String STR=new String (checkSum);
Int iValule=Integer. ParseInt (STR, 16);
Return iValule;
}

//212 \ u534f \ u8bae \ u7684CRC \ u6821 \ u9a8c \ u7b97 \ u6cd5
Private int checkOutSixteenCheckSum (byte [] bytes, int len) {
Int r=0 XFFFF;
Char hi;
Char flag;
for (int i=0; i Hi=(char) (r & gt; & gt; 8);
Hi ^=bytes [I];
R=the hi;

For (int j=0; J & lt; 8; J++) {
Flag=(char) (r & amp; 0 x0001);
R=r & gt; & gt; 1;
If (flag==1) {
R ^=0 xa001;
}
}
}
Return r;
}
}
I put the project into jars in the lib folder in the root directory of the flume, and then use the run configuration file will be quoted above Java lang. ClassNotFoundException: com. Flume. The interceptor. HbInterceptor $Builder
The at java.net.URLClassLoader$1.run URLClassLoader. Java: (366)
The at java.net.URLClassLoader$1.run URLClassLoader. Java: (355)
The at Java. Security. The AccessController. DoPrivileged (Native Method)
The at java.net.URLClassLoader.findClass URLClassLoader. Java: (354)
The at Java. Lang. This. LoadClass (425). This Java:
At sun. Misc. The Launcher $AppClassLoader. LoadClass (308). The Launcher Java:
The at Java. Lang. This. LoadClass (358). This Java:
The at Java. Lang. Class. ForName0 (Native Method)
The at Java. Lang. Class.forname (190) Class. Java:
The at org. Apache. The flume. The interceptor. InterceptorBuilderFactory. NewInstance (InterceptorBuilderFactory. Java: 48)
The at org. Apache. The flume. Channel. ChannelProcessor. ConfigureInterceptors (ChannelProcessor. Java: 111)
The at org. Apache. The flume. Channel. ChannelProcessor. Configure (ChannelProcessor. Java: 82)
The at org. Apache. The flume. Conf. Configurables. Configure (Configurables. Java: 41)
The at org. Apache. The flume. Node. AbstractConfigurationProvider. LoadSources (AbstractConfigurationProvider. Java: 348)
The at org. Apache. The flume. Node. AbstractConfigurationProvider. GetConfiguration (AbstractConfigurationProvider. Java: 101)
The at org. Apache. The flume. Node. PollingPropertiesFileConfigurationProvider $FileWatcherRunnable. Run (PollingPropertiesFileConfigurationProvider. Java: 141)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related