當前位置: 首頁>>代碼示例>>Java>>正文


Java Event.getBody方法代碼示例

本文整理匯總了Java中org.apache.flume.Event.getBody方法的典型用法代碼示例。如果您正苦於以下問題:Java Event.getBody方法的具體用法?Java Event.getBody怎麽用?Java Event.getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.flume.Event的用法示例。


在下文中一共展示了Event.getBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PersistableEvent

import org.apache.flume.Event; //導入方法依賴的package包/類
public PersistableEvent(String channel, Event event) {
  this.channel = channel;

  byte[] givenPayload = event.getBody();
  if (givenPayload.length < ConfigurationConstants.PAYLOAD_LENGTH_THRESHOLD) {
    basePayload = Arrays.copyOf(givenPayload, givenPayload.length);
    spillPayload = null;
  } else {
    basePayload = Arrays.copyOfRange(givenPayload, 0,
        ConfigurationConstants.PAYLOAD_LENGTH_THRESHOLD);
    spillPayload = Arrays.copyOfRange(givenPayload,
        ConfigurationConstants.PAYLOAD_LENGTH_THRESHOLD, givenPayload.length);
  }

  Map<String, String> headerMap = event.getHeaders();
  if (headerMap != null && headerMap.size() > 0) {
    headers = new ArrayList<HeaderEntry>();
    for (Map.Entry<String, String> entry : headerMap.entrySet()) {
      String name = entry.getKey();
      String value = entry.getValue();
      headers.add(new HeaderEntry(name, value));
    }
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:25,代碼來源:PersistableEvent.java

示例2: testLayout

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testLayout() throws IOException {
  configureSource();
  props.put("log4j.appender.out2.layout", "org.apache.log4j.PatternLayout");
  props.put("log4j.appender.out2.layout.ConversionPattern",
      "%-5p [%t]: %m%n");
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  Thread.currentThread().setName("Log4jAppenderTest");
  for (int count = 0; count <= 100; count++) {
    /*
     * Log4j internally defines levels as multiples of 10000. So if we
     * create levels directly using count, the level will be set as the
     * default.
     */
    int level = ((count % 5) + 1) * 10000;
    String msg = "This is log message number" + String.valueOf(count);

    logger.log(Level.toLevel(level), msg);
    Transaction transaction = ch.getTransaction();
    transaction.begin();
    Event event = ch.take();
    Assert.assertNotNull(event);
    StringBuilder builder = new StringBuilder();
    builder.append("[").append("Log4jAppenderTest").append("]: ")
        .append(msg);
    //INFO seems to insert an extra space, so lets split the string.
    String eventBody = new String(event.getBody(), "UTF-8");
    String eventLevel = eventBody.split("\\s+")[0];
    Assert.assertEquals(Level.toLevel(level).toString(), eventLevel);
    Assert.assertEquals(
        new String(event.getBody(), "UTF8").trim()
            .substring(eventLevel.length()).trim(), builder.toString());

    Map<String, String> hdrs = event.getHeaders();

    Assert.assertNotNull(hdrs.get(Log4jAvroHeaders.TIMESTAMP.toString()));

    Assert.assertEquals(Level.toLevel(level),
        Level.toLevel(Integer.parseInt(hdrs.get(Log4jAvroHeaders.LOG_LEVEL
            .toString()))));

    Assert.assertEquals(logger.getName(),
        hdrs.get(Log4jAvroHeaders.LOGGER_NAME.toString()));

    Assert.assertEquals("UTF8",
        hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
    transaction.commit();
    transaction.close();
  }


}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:54,代碼來源:TestLog4jAppender.java

示例3: serializeEvent

import org.apache.flume.Event; //導入方法依賴的package包/類
private byte[] serializeEvent(Event event, boolean useAvroEventFormat) throws IOException {
  byte[] bytes;
  if (useAvroEventFormat) {
    if (!tempOutStream.isPresent()) {
      tempOutStream = Optional.of(new ByteArrayOutputStream());
    }
    if (!writer.isPresent()) {
      writer = Optional.of(new SpecificDatumWriter<AvroFlumeEvent>(AvroFlumeEvent.class));
    }
    tempOutStream.get().reset();
    AvroFlumeEvent e = new AvroFlumeEvent(toCharSeqMap(event.getHeaders()),
                                          ByteBuffer.wrap(event.getBody()));
    encoder = EncoderFactory.get().directBinaryEncoder(tempOutStream.get(), encoder);
    writer.get().write(e, encoder);
    encoder.flush();
    bytes = tempOutStream.get().toByteArray();
  } else {
    bytes = event.getBody();
  }
  return bytes;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:KafkaSink.java

示例4: serializeValue

import org.apache.flume.Event; //導入方法依賴的package包/類
private byte[] serializeValue(Event event, boolean parseAsFlumeEvent) throws IOException {
  byte[] bytes;
  if (parseAsFlumeEvent) {
    if (!tempOutStream.isPresent()) {
      tempOutStream = Optional.of(new ByteArrayOutputStream());
    }
    if (!writer.isPresent()) {
      writer = Optional.of(new
              SpecificDatumWriter<AvroFlumeEvent>(AvroFlumeEvent.class));
    }
    tempOutStream.get().reset();
    AvroFlumeEvent e = new AvroFlumeEvent(
            toCharSeqMap(event.getHeaders()),
            ByteBuffer.wrap(event.getBody()));
    encoder = EncoderFactory.get()
            .directBinaryEncoder(tempOutStream.get(), encoder);
    writer.get().write(e, encoder);
    encoder.flush();
    bytes = tempOutStream.get().toByteArray();
  } else {
    bytes = event.getBody();
  }
  return bytes;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:25,代碼來源:KafkaChannel.java

示例5: write

import org.apache.flume.Event; //導入方法依賴的package包/類
/**
 * Write data, update stats
 * @param event
 * @throws WriteException - other streaming io error
 * @throws InterruptedException
 */
public synchronized void write(final Event event)
    throws WriteException, InterruptedException {
  if (closed) {
    throw new IllegalStateException("Writer closed. Cannot write to : " + endPoint);
  }

  batch.add(event);
  if (batch.size() == writeBatchSz) {
    // write the event
    writeEventBatchToSerializer();
  }

  // Update Statistics
  processSize += event.getBody().length;
  eventCounter++;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:23,代碼來源:HiveWriter.java

示例6: assertEquals

import org.apache.flume.Event; //導入方法依賴的package包/類
private static void assertEquals(Event e1, Event e2) {
  byte[] pl1 = e1.getBody();
  byte[] pl2 = e2.getBody();

  Assert.assertArrayEquals(pl1, pl2);
  Map<String, String> h1 = e1.getHeaders();
  Map<String, String> h2 = e2.getHeaders();
  if (h1 == null || h1.size() == 0) {
    Assert.assertTrue(h2 == null || h2.size() == 0);
  } else {
    Assert.assertTrue(h1.size() == h2.size());
    for (String key : h1.keySet()) {
      Assert.assertTrue(h2.containsKey(key));
      String v1 = h1.get(key);
      String v2 = h2.remove(key);
      Assert.assertEquals(v1, v2);
    }
    Assert.assertTrue(h2.size() == 0);
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:21,代碼來源:BaseJdbcChannelProviderTest.java

示例7: intercept

import org.apache.flume.Event; //導入方法依賴的package包/類
@Override
public Event intercept(Event event) {
  String origBody = new String(event.getBody(), charset);
  Matcher matcher = searchPattern.matcher(origBody);
  String newBody = matcher.replaceAll(replaceString);
  event.setBody(newBody.getBytes(charset));
  return event;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:9,代碼來源:SearchAndReplaceInterceptor.java

示例8: testSearchReplace

import org.apache.flume.Event; //導入方法依賴的package包/類
private void testSearchReplace(Context context, String input, String output)
    throws Exception {
  Interceptor.Builder builder = InterceptorBuilderFactory.newInstance(
      InterceptorType.SEARCH_REPLACE.toString());
  builder.configure(context);
  Interceptor interceptor = builder.build();

  Event event = EventBuilder.withBody(input, Charsets.UTF_8);
  event = interceptor.intercept(event);
  String val = new String(event.getBody(), Charsets.UTF_8);
  assertEquals(output, val);
  logger.info(val);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:14,代碼來源:TestSearchAndReplaceInterceptor.java

示例9: testReconfigure

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testReconfigure() throws InterruptedException, IOException {
  final int NUM_RECONFIGS = 20;
  for (int i = 0; i < NUM_RECONFIGS; i++) {
    Context context = new Context();
    File file = new File(tmpDir.getAbsolutePath() + "/file-" + i);
    Files.write("File " + i, file, Charsets.UTF_8);
    context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
        tmpDir.getAbsolutePath());
    Configurables.configure(source, context);
    source.start();
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    Transaction txn = channel.getTransaction();
    txn.begin();
    try {
      Event event = channel.take();
      String content = new String(event.getBody(), Charsets.UTF_8);
      Assert.assertEquals("File " + i, content);
      txn.commit();
    } catch (Throwable t) {
      txn.rollback();
    } finally {
      txn.close();
    }
    source.stop();
    Assert.assertFalse("Fatal error on iteration " + i, source.hasFatalError());
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:29,代碼來源:TestSpoolDirectorySource.java

示例10: testBatchProcessWithLifeCycle

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testBatchProcessWithLifeCycle() throws InterruptedException, LifecycleException,
    EventDeliveryException {

  int batchSize = 10;

  Channel channel = new PseudoTxnMemoryChannel();
  Context context = new Context();

  context.put("logicalNode.name", "test");
  context.put("batchSize", Integer.toString(batchSize));

  Configurables.configure(source, context);
  Configurables.configure(channel, context);

  List<Channel> channels = new ArrayList<Channel>();
  channels.add(channel);

  ChannelSelector rcs = new ReplicatingChannelSelector();
  rcs.setChannels(channels);

  source.setChannelProcessor(new ChannelProcessor(rcs));

  source.start();

  for (long i = 0; i < 100; i++) {
    source.process();

    for (long j = batchSize; j > 0; j--) {
      Event event = channel.take();
      String expectedVal = String.valueOf(((i + 1) * batchSize) - j);
      String resultedVal = new String(event.getBody());
      Assert.assertTrue("Expected " + expectedVal + " is not equals to " +
          resultedVal, expectedVal.equals(resultedVal));
    }
  }

  source.stop();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:40,代碼來源:TestSequenceGeneratorSource.java

示例11: estimateEventSize

import org.apache.flume.Event; //導入方法依賴的package包/類
private long estimateEventSize(Event event) {
  byte[] body = event.getBody();
  if (body != null && body.length != 0) {
    return body.length;
  }
  //Each event occupies at least 1 slot, so return 1.
  return 1;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:9,代碼來源:SpillableMemoryChannel.java

示例12: binding

import org.apache.flume.Event; //導入方法依賴的package包/類
public Object binding(final Event event) {
    if (header == null) {
        final byte body[] = event.getBody();
        return dataType.convert(new String(body, Charsets.UTF_8));
    } else {
        final Map<String, String> headers = event.getHeaders();
        for (final Map.Entry<String, String> entry : headers.entrySet()) {
            if (entry.getKey().equals(header)) {
                return dataType.convert(entry.getValue());
            }
        }
    }
    log.trace("No bindable field found for {}", this);
    return null;
}
 
開發者ID:SoonhyukYoon,項目名稱:stratio-jdbc-sink-mariadb,代碼行數:16,代碼來源:TemplateQueryGenerator.java

示例13: initialize

import org.apache.flume.Event; //導入方法依賴的package包/類
@Override
public void initialize(Event event, byte[] cf) {
  this.payload = event.getBody();
  this.cf = cf;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:6,代碼來源:SimpleHbaseEventSerializer.java

示例14: assertEventBodyEquals

import org.apache.flume.Event; //導入方法依賴的package包/類
private void assertEventBodyEquals(String expected, Event event) {
  String bodyStr = new String(event.getBody(), Charsets.UTF_8);
  Assert.assertEquals(expected, bodyStr);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:5,代碼來源:TestLineDeserializer.java

示例15: bodyAsString

import org.apache.flume.Event; //導入方法依賴的package包/類
static String bodyAsString(Event event) {
  return new String(event.getBody());
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:4,代碼來源:TestSpoolingFileLineReader.java


注:本文中的org.apache.flume.Event.getBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。