本文整理汇总了Java中org.apache.flume.Event类的典型用法代码示例。如果您正苦于以下问题:Java Event类的具体用法?Java Event怎么用?Java Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Event类属于org.apache.flume包,在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateMiniParse
import org.apache.flume.Event; //导入依赖的package包/类
private void validateMiniParse(EventDeserializer des) throws IOException {
Event evt;
des.mark();
evt = des.readEvent();
assertEquals(new String(evt.getBody()), mini);
des.reset(); // reset!
evt = des.readEvent();
assertEquals("data should be repeated, " +
"because we reset() the stream", new String(evt.getBody()), mini);
evt = des.readEvent();
assertNull("Event should be null because there are no lines " +
"left to read", evt);
des.mark();
des.close();
}
示例2: append
import org.apache.flume.Event; //导入依赖的package包/类
@Override
public void append(Event event) throws EventDeliveryException {
throwIfClosed();
boolean eventSent = false;
Iterator<HostInfo> it = selector.createHostIterator();
while (it.hasNext()) {
HostInfo host = it.next();
try {
RpcClient client = getClient(host);
client.append(event);
eventSent = true;
break;
} catch (Exception ex) {
selector.informFailure(host);
LOGGER.warn("Failed to send event to host " + host, ex);
}
}
if (!eventSent) {
throw new EventDeliveryException("Unable to send event to any host");
}
}
示例3: appendBatch
import org.apache.flume.Event; //导入依赖的package包/类
@Override
public Status appendBatch(List<ThriftFlumeEvent> events) throws TException {
sourceCounter.incrementAppendBatchReceivedCount();
sourceCounter.addToEventReceivedCount(events.size());
List<Event> flumeEvents = Lists.newArrayList();
for (ThriftFlumeEvent event : events) {
flumeEvents.add(EventBuilder.withBody(event.getBody(), event.getHeaders()));
}
try {
getChannelProcessor().processEventBatch(flumeEvents);
} catch (ChannelException ex) {
logger.warn("Thrift source %s could not append events to the channel.", getName());
return Status.FAILED;
}
sourceCounter.incrementAppendBatchAcceptedCount();
sourceCounter.addToEventAcceptedCount(events.size());
return Status.OK;
}
示例4: testThreeParamBatchAppend
import org.apache.flume.Event; //导入依赖的package包/类
@Test
public void testThreeParamBatchAppend() throws FlumeException,
EventDeliveryException {
int batchSize = 7;
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getDefaultInstance(localhost, server.getPort(),
batchSize);
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < batchSize; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例5: testPropertiesBatchAppend
import org.apache.flume.Event; //导入依赖的package包/类
@Test
public void testPropertiesBatchAppend() throws FlumeException,
EventDeliveryException {
int batchSize = 7;
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
Properties p = new Properties();
p.put("hosts", "host1");
p.put("hosts.host1", localhost + ":" + String.valueOf(server.getPort()));
p.put("batch-size", String.valueOf(batchSize));
client = RpcClientFactory.getInstance(p);
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < batchSize; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例6: testOK
import org.apache.flume.Event; //导入依赖的package包/类
@Test
public void testOK() throws Exception {
src = new ThriftTestingSource(ThriftTestingSource.HandlerType.OK.name(),
port, ThriftRpcClient.COMPACT_PROTOCOL);
client = (ThriftRpcClient) RpcClientFactory.getInstance(props);
insertEvents(client, 10); //10 events
insertAsBatch(client, 10, 25); //16 events
insertAsBatch(client, 26, 37); //12 events
int count = 0;
Assert.assertEquals(38, src.flumeEvents.size());
for (Event e : src.flumeEvents) {
Assert.assertEquals(new String(e.getBody()), String.valueOf(count++));
}
Assert.assertEquals(10, src.individualCount);
Assert.assertEquals(4, src.batchCount);
Assert.assertEquals(2, src.incompleteBatches);
}
示例7: readEvent
import org.apache.flume.Event; //导入依赖的package包/类
@Override
public Event readEvent() throws IOException {
if (fileReader.hasNext()) {
record = fileReader.next(record);
out.reset();
datumWriter.write(record, encoder);
encoder.flush();
// annotate header with 64-bit schema CRC hash in hex
Event event = EventBuilder.withBody(out.toByteArray());
if (schemaType == AvroSchemaType.HASH) {
event.getHeaders().put(AVRO_SCHEMA_HEADER_HASH, schemaHashString);
} else {
event.getHeaders().put(AVRO_SCHEMA_HEADER_LITERAL, schema.toString());
}
return event;
}
return null;
}
示例8: createGoodChannel
import org.apache.flume.Event; //导入依赖的package包/类
ChannelProcessor createGoodChannel() {
ChannelProcessor channelProcessor = mock(ChannelProcessor.class);
events = Lists.newArrayList();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
events.addAll((List<Event>)invocation.getArguments()[0]);
return null;
}
}).when(channelProcessor).processEventBatch(any(List.class));
return channelProcessor;
}
示例9: testExtractBadEvent4
import org.apache.flume.Event; //导入依赖的package包/类
/**
* Test bad event format 4: Priority too long
*/
@Test
public void testExtractBadEvent4() {
String badData1 = "<123123123123123123123123123123> bad bad data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
}
示例10: testRequest
import org.apache.flume.Event; //导入依赖的package包/类
@Test
public void testRequest() throws InterruptedException, IOException {
bind();
Map flumeMap = new HashMap<CharSequence, ByteBuffer>();
ThriftFlumeEvent thriftEvent = new ThriftFlumeEvent(
1, Priority.INFO, ByteBuffer.wrap("foo".getBytes()),
0, "fooHost", flumeMap);
FlumeClient fClient = new FlumeClient("0.0.0.0", selectedPort);
fClient.append(thriftEvent);
// check if the even has arrived in the channel through OG thrift source
Transaction transaction = channel.getTransaction();
transaction.begin();
Event event = channel.take();
Assert.assertNotNull(event);
Assert.assertEquals("Channel contained our event", "foo",
new String(event.getBody()));
transaction.commit();
transaction.close();
stop();
}
示例11: testSchemaLiteral
import org.apache.flume.Event; //导入依赖的package包/类
@Test
public void testSchemaLiteral() throws IOException {
File tempFile = newTestFile(true);
String target = tempFile.getAbsolutePath();
logger.info("Target: {}", target);
TransientPositionTracker tracker = new TransientPositionTracker(target);
Context context = new Context();
context.put(AvroEventDeserializer.CONFIG_SCHEMA_TYPE_KEY,
AvroEventDeserializer.AvroSchemaType.LITERAL.toString());
ResettableInputStream in =
new ResettableFileInputStream(tempFile, tracker);
EventDeserializer des =
new AvroEventDeserializer.Builder().build(context, in);
Event event = des.readEvent();
String eventSchema =
event.getHeaders().get(AvroEventDeserializer.AVRO_SCHEMA_HEADER_LITERAL);
Assert.assertEquals(schema.toString(), eventSchema);
}
示例12: doTake
import org.apache.flume.Event; //导入依赖的package包/类
@Override
protected Event doTake() throws InterruptedException {
channelCounter.incrementEventTakeAttemptCount();
if (takeList.remainingCapacity() == 0) {
throw new ChannelException("Take list for MemoryTransaction, capacity " +
takeList.size() + " full, consider committing more frequently, " +
"increasing capacity, or increasing thread count");
}
if (!queueStored.tryAcquire(keepAlive, TimeUnit.SECONDS)) {
return null;
}
Event event;
synchronized (queueLock) {
event = queue.poll();
}
Preconditions.checkNotNull(event, "Queue.poll returned NULL despite semaphore " +
"signalling existence of entry");
takeList.put(event);
int eventByteSize = (int) Math.ceil(estimateEventSize(event) / byteCapacitySlotSize);
takeByteCounter += eventByteSize;
return event;
}
示例13: addEvent
import org.apache.flume.Event; //导入依赖的package包/类
@Override
public void addEvent(Event event, IndexNameBuilder indexNameBuilder, String indexType,
long ttlMs) throws Exception {
BytesReference content = serializer.getContentBuilder(event).bytes();
Map<String, Map<String, String>> parameters = new HashMap<String, Map<String, String>>();
Map<String, String> indexParameters = new HashMap<String, String>();
indexParameters.put(INDEX_PARAM, indexNameBuilder.getIndexName(event));
indexParameters.put(TYPE_PARAM, indexType);
if (ttlMs > 0) {
indexParameters.put(TTL_PARAM, Long.toString(ttlMs));
}
parameters.put(INDEX_OPERATION_NAME, indexParameters);
Gson gson = new Gson();
synchronized (bulkBuilder) {
bulkBuilder.append(gson.toJson(parameters));
bulkBuilder.append("\n");
bulkBuilder.append(content.toBytesArray().toUtf8());
bulkBuilder.append("\n");
}
}
示例14: intercept
import org.apache.flume.Event; //导入依赖的package包/类
@Override
public Event intercept(Event event)
{
Map<String, String> headers = event.getHeaders();
String eventBody = new String(event.getBody(), UTF_8);
eventBody = eventBody.trim();
int index = eventBody.indexOf(' ');
if (index == -1) {
headers.put(this.header, this.defaultTag);
}
else {
String appTag = eventBody.substring(0, index);
headers.put(this.header, appTag);
}
if (this.preserveTag == false) {
String newEventBody = eventBody.substring(index, eventBody.length()).trim();
event.setBody(newEventBody.getBytes());
}
return event;
}
示例15: testExceptionFromGetTransaction
import org.apache.flume.Event; //导入依赖的package包/类
/**
* Ensure that we bubble up any specific exception thrown from getTransaction
* instead of another exception masking it such as an NPE
*/
@Test(expected = ChannelException.class)
public void testExceptionFromGetTransaction() {
// create a channel which unexpectedly throws a ChEx on getTransaction()
Channel ch = mock(Channel.class);
when(ch.getTransaction()).thenThrow(new ChannelException("doh!"));
ChannelSelector sel = new ReplicatingChannelSelector();
sel.setChannels(Lists.newArrayList(ch));
ChannelProcessor proc = new ChannelProcessor(sel);
List<Event> events = Lists.newArrayList();
events.add(EventBuilder.withBody("event 1", Charsets.UTF_8));
proc.processEventBatch(events);
}