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


Java Event.setHeaders方法代碼示例

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


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

示例1: testMissingSchema

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testMissingSchema() throws EventDeliveryException {
  final DatasetSink sink = sink(in, config);

  Event badEvent = new SimpleEvent();
  badEvent.setHeaders(Maps.<String, String>newHashMap());
  badEvent.setBody(serialize(expected.get(0), RECORD_SCHEMA));
  putToChannel(in, badEvent);

  // run the sink
  sink.start();
  assertThrows("Should fail", EventDeliveryException.class,
      new Callable() {
        @Override
        public Object call() throws EventDeliveryException {
          sink.process();
          return null;
        }
      });
  sink.stop();

  Assert.assertEquals("Should have rolled back",
      expected.size() + 1, remaining(in));
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:25,代碼來源:TestDatasetSink.java

示例2: withBody

import org.apache.flume.Event; //導入方法依賴的package包/類
/**
 * Instantiate an Event instance based on the provided body and headers.
 * If <code>headers</code> is <code>null</code>, then it is ignored.
 * @param body
 * @param headers
 * @return
 */
public static Event withBody(byte[] body, Map<String, String> headers) {
  Event event = new SimpleEvent();

  if (body == null) {
    body = new byte[0];
  }
  event.setBody(body);

  if (headers != null) {
    event.setHeaders(new HashMap<String, String>(headers));
  }

  return event;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:EventBuilder.java

示例3: getEvents

import org.apache.flume.Event; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public List<Event> getEvents(HttpServletRequest request) throws Exception {
  Map<String, String> headers = new HashMap<String, String>();

  InputStream inputStream = request.getInputStream();

  Map<String, String[]> parameters = request.getParameterMap();
  for (String parameter : parameters.keySet()) {
    String value = parameters.get(parameter)[0];
    if (LOG.isDebugEnabled() && LogPrivacyUtil.allowLogRawData()) {
      LOG.debug("Setting Header [Key, Value] as [{},{}] ", parameter, value);
    }
    headers.put(parameter, value);
  }

  for (String header : mandatoryHeaders) {
    Preconditions.checkArgument(headers.containsKey(header),
        "Please specify " + header + " parameter in the request.");
  }

  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  try {
    IOUtils.copy(inputStream, outputStream);
    LOG.debug("Building an Event with stream of size -- {}", outputStream.size());
    Event event = EventBuilder.withBody(outputStream.toByteArray(), headers);
    event.setHeaders(headers);
    List<Event> eventList = new ArrayList<Event>();
    eventList.add(event);
    return eventList;
  } finally {
    outputStream.close();
    inputStream.close();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:39,代碼來源:BLOBHandler.java

示例4: testNoMandatory

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testNoMandatory() {

  config.put("default", "ch3");
  config.put("optional.foo", "ch1 ch2");
  config.put("optional.zebra", "ch2 ch3");
  selector = ChannelSelectorFactory.create(channels, config);
  Assert.assertTrue(selector instanceof MultiplexingChannelSelector);

  Event event1 = new MockEvent();
  Map<String, String> header1 = new HashMap<String, String>();
  header1.put("myheader", "foo");// should match ch1 ch2
  event1.setHeaders(header1);

  List<Channel> reqCh1 = selector.getRequiredChannels(event1);
  Assert.assertEquals(1, reqCh1.size());
  Assert.assertEquals("ch3", reqCh1.get(0).getName());
  List<Channel> optCh1 = selector.getOptionalChannels(event1);
  Assert.assertEquals(2, optCh1.size());
  //ch2 should not be there -- since it is a required channel
  Assert.assertEquals("ch1", optCh1.get(0).getName());
  Assert.assertEquals("ch2", optCh1.get(1).getName());

  Event event4 = new MockEvent();
  Map<String, String> header4 = new HashMap<String, String>();
  header4.put("myheader", "zebra");
  event4.setHeaders(header4);

  List<Channel> reqCh4 = selector.getRequiredChannels(event4);
  Assert.assertEquals(1, reqCh4.size());
  Assert.assertTrue(reqCh4.get(0).getName().equals("ch3"));
  List<Channel> optCh4 = selector.getOptionalChannels(event4);
  //ch3 was returned as a required channel, because it is default.
  //So it is not returned in optional
  Assert.assertEquals(1, optCh4.size());
  Assert.assertEquals("ch2", optCh4.get(0).getName());

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

示例5: testOnlyOptional

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testOnlyOptional() {
  config.put("optional.foo", "ch1 ch2");
  config.put("optional.zebra", "ch2 ch3");
  selector = ChannelSelectorFactory.create(channels, config);
  Assert.assertTrue(selector instanceof MultiplexingChannelSelector);

  Event event1 = new MockEvent();
  Map<String, String> header1 = new HashMap<String, String>();
  header1.put("myheader", "foo");// should match ch1 ch2
  event1.setHeaders(header1);

  List<Channel> reqCh1 = selector.getRequiredChannels(event1);
  Assert.assertTrue(reqCh1.isEmpty());
  List<Channel> optCh1 = selector.getOptionalChannels(event1);
  Assert.assertEquals(2,optCh1.size());
  //ch2 should not be there -- since it is a required channel


  Event event4 = new MockEvent();
  Map<String, String> header4 = new HashMap<String, String>();
  header4.put("myheader", "zebra");
  event4.setHeaders(header4);

  List<Channel> reqCh4 = selector.getRequiredChannels(event4);
  Assert.assertTrue(reqCh4.isEmpty());
  List<Channel> optCh4 = selector.getOptionalChannels(event4);
  Assert.assertEquals(2, optCh4.size());
  Assert.assertEquals("ch2", optCh4.get(0).getName());
  Assert.assertEquals("ch3", optCh4.get(1).getName());

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

示例6: indexNameShouldBePrefixDashFormattedTimestamp

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void indexNameShouldBePrefixDashFormattedTimestamp() {
  long time = 987654321L;
  Event event = new SimpleEvent();
  Map<String, String> headers = new HashMap<String, String>();
  headers.put("timestamp", Long.toString(time));
  event.setHeaders(headers);
  assertEquals("prefix-" + indexNameBuilder.getFastDateFormat().format(time),
      indexNameBuilder.getIndexName(event));
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:11,代碼來源:TimeBasedIndexNameBuilderTest.java

示例7: testMissingSchemaWithSavePolicy

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testMissingSchemaWithSavePolicy() throws EventDeliveryException {
  if (Datasets.exists(ERROR_DATASET_URI)) {
    Datasets.delete(ERROR_DATASET_URI);
  }
  config.put(DatasetSinkConstants.CONFIG_FAILURE_POLICY,
      DatasetSinkConstants.SAVE_FAILURE_POLICY);
  config.put(DatasetSinkConstants.CONFIG_KITE_ERROR_DATASET_URI,
      ERROR_DATASET_URI);
  final DatasetSink sink = sink(in, config);

  Event badEvent = new SimpleEvent();
  badEvent.setHeaders(Maps.<String, String>newHashMap());
  badEvent.setBody(serialize(expected.get(0), RECORD_SCHEMA));
  putToChannel(in, badEvent);

  // run the sink
  sink.start();
  sink.process();
  sink.stop();

  Assert.assertEquals("Good records should have been written",
      Sets.newHashSet(expected),
      read(Datasets.load(FILE_DATASET_URI)));
  Assert.assertEquals("Should not have rolled back", 0, remaining(in));
  Assert.assertEquals("Should have saved the bad event",
      Sets.newHashSet(AvroFlumeEvent.newBuilder()
        .setBody(ByteBuffer.wrap(badEvent.getBody()))
        .setHeaders(toUtf8Map(badEvent.getHeaders()))
        .build()),
      read(Datasets.load(ERROR_DATASET_URI, AvroFlumeEvent.class)));
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:33,代碼來源:TestDatasetSink.java

示例8: event

import org.apache.flume.Event; //導入方法依賴的package包/類
public static Event event(
    Object datum, Schema schema, File file, boolean useURI) {
  Map<String, String> headers = Maps.newHashMap();
  if (useURI) {
    headers.put(DatasetSinkConstants.AVRO_SCHEMA_URL_HEADER,
        file.getAbsoluteFile().toURI().toString());
  } else {
    headers.put(DatasetSinkConstants.AVRO_SCHEMA_LITERAL_HEADER,
        schema.toString());
  }
  Event e = new SimpleEvent();
  e.setBody(serialize(datum, schema));
  e.setHeaders(headers);
  return e;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:16,代碼來源:TestDatasetSink.java

示例9: testHeaderIndex

import org.apache.flume.Event; //導入方法依賴的package包/類
/**
 * tests header based index, type and id
 */
@Test
public void testHeaderIndex() {
    Event event = new SimpleEvent();
    Map<String, String> headers = new HashMap<String, String>();
    headers.put(INDEX, index);
    headers.put(TYPE, type);
    headers.put(ID, id);
    event.setHeaders(headers);
    assertEquals(index, headerBasedIndexBuilder.getIndex(event));
    assertEquals(type, headerBasedIndexBuilder.getType(event));
    assertEquals(id, headerBasedIndexBuilder.getId(event));
}
 
開發者ID:cognitree,項目名稱:flume-elasticsearch-sink,代碼行數:16,代碼來源:TestHeaderIndexBuilder.java

示例10: run

import org.apache.flume.Event; //導入方法依賴的package包/類
private void run() throws IOException, FlumeException,
    EventDeliveryException {

  EventReader reader = null;

  RpcClient rpcClient;
  if (rpcClientPropsFile != null) {
    rpcClient = RpcClientFactory.getInstance(new File(rpcClientPropsFile));
  } else {
    rpcClient = RpcClientFactory.getDefaultInstance(hostname, port,
        BATCH_SIZE);
  }

  try {
    if (fileName != null) {
      reader = new SimpleTextLineEventReader(new FileReader(new File(fileName)));
    } else if (dirName != null) {
      reader = new ReliableSpoolingFileEventReader.Builder()
          .spoolDirectory(new File(dirName)).build();
    } else {
      reader = new SimpleTextLineEventReader(new InputStreamReader(System.in));
    }

    long lastCheck = System.currentTimeMillis();
    long sentBytes = 0;

    int batchSize = rpcClient.getBatchSize();
    List<Event> events;
    while (!(events = reader.readEvents(batchSize)).isEmpty()) {
      for (Event event : events) {
        event.setHeaders(headers);
        sentBytes += event.getBody().length;
        sent++;

        long now = System.currentTimeMillis();
        if (now >= lastCheck + 5000) {
          logger.debug("Packed {} bytes, {} events", sentBytes, sent);
          lastCheck = now;
        }
      }
      rpcClient.appendBatch(events);
      if (reader instanceof ReliableEventReader) {
        ((ReliableEventReader) reader).commit();
      }
    }
    logger.debug("Finished");
  } finally {
    if (reader != null) {
      logger.debug("Closing reader");
      reader.close();
    }

    logger.debug("Closing RPC client");
    rpcClient.close();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:57,代碼來源:AvroCLIClient.java

示例11: testSelection

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testSelection() throws Exception {

  config.put("mapping.foo", "ch1 ch2");
  config.put("mapping.bar", "ch2 ch3");
  config.put("mapping.xyz", "ch1 ch2 ch3");
  config.put("default", "ch1 ch3");
  selector = ChannelSelectorFactory.create(channels, config);
  Assert.assertTrue(selector instanceof MultiplexingChannelSelector);

  Event event1 = new MockEvent();
  Map<String, String> header1 = new HashMap<String, String>();
  header1.put("myheader", "foo");// should match ch1 ch2
  event1.setHeaders(header1);

  List<Channel> reqCh1 = selector.getRequiredChannels(event1);
  Assert.assertEquals(2, reqCh1.size());
  Assert.assertTrue(reqCh1.get(0).getName().equals("ch1"));
  Assert.assertTrue(reqCh1.get(1).getName().equals("ch2"));
  List<Channel> optCh1 = selector.getOptionalChannels(event1);
  Assert.assertTrue(optCh1.size() == 1);
  //ch2 should not be there -- since it is a required channel
  Assert.assertTrue(optCh1.get(0).getName().equals("ch3"));



  Event event2 = new MockEvent();
  Map<String, String> header2 = new HashMap<String, String>();
  header2.put("myheader", "bar"); // should match ch2 ch3
  event2.setHeaders(header2);

  List<Channel> reqCh2 = selector.getRequiredChannels(event2);
  Assert.assertEquals(2, reqCh2.size());
  Assert.assertTrue(reqCh2.get(0).getName().equals("ch2"));
  Assert.assertTrue(reqCh2.get(1).getName().equals("ch3"));
  List<Channel> optCh2 = selector.getOptionalChannels(event2);
  Assert.assertTrue(optCh2.isEmpty());

  Event event3 = new MockEvent();
  Map<String, String> header3 = new HashMap<String, String>();
  header3.put("myheader", "xyz"); // should match ch1 ch2 ch3
  event3.setHeaders(header3);

  List<Channel> reqCh3 = selector.getRequiredChannels(event3);
  Assert.assertEquals(3, reqCh3.size());
  Assert.assertTrue(reqCh3.get(0).getName().equals("ch1"));
  Assert.assertTrue(reqCh3.get(1).getName().equals("ch2"));
  Assert.assertTrue(reqCh3.get(2).getName().equals("ch3"));
  List<Channel> optCh3 = selector.getOptionalChannels(event3);
  //All of the optional channels should go away.
  Assert.assertTrue(optCh3.size() == 0);

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

示例12: testNoSelection

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testNoSelection() throws Exception {

  config.put("mapping.foo", "ch1 ch2");
  config.put("mapping.bar", "ch2 ch3");
  config.put("mapping.xyz", "ch1 ch2 ch3");
  config.put("default", "ch1 ch3");
  selector = ChannelSelectorFactory.create(channels, config);
  Assert.assertTrue(selector instanceof MultiplexingChannelSelector);
  Event noHeaderEvent = new MockEvent();

  List<Channel> reqCh1 = selector.getRequiredChannels(noHeaderEvent);
  List<Channel> optCh1 = selector.getOptionalChannels(noHeaderEvent);
  Assert.assertEquals(2, reqCh1.size());
  Assert.assertTrue(reqCh1.get(0).getName().equals("ch1"));
  Assert.assertTrue(reqCh1.get(1).getName().equals("ch3"));
  Assert.assertTrue(optCh1.isEmpty());

  Map<String, String> header2 = new HashMap<String, String>();
  header2.put("someheader", "foo");
  Event invalidHeaderEvent = new MockEvent();
  invalidHeaderEvent.setHeaders(header2);

  List<Channel> reqCh2 = selector.getRequiredChannels(invalidHeaderEvent);
  List<Channel> optCh2 = selector.getOptionalChannels(invalidHeaderEvent);
  Assert.assertEquals(2, reqCh2.size());
  Assert.assertTrue(reqCh2.get(0).getName().equals("ch1"));
  Assert.assertTrue(reqCh2.get(1).getName().equals("ch3"));
  Assert.assertTrue(optCh2.isEmpty());

  Map<String, String> header3 = new HashMap<String, String>();
  header3.put("myheader", "bar1");
  Event unmatchedHeaderEvent = new MockEvent();
  unmatchedHeaderEvent.setHeaders(header3);

  List<Channel> reqCh3 = selector.getRequiredChannels(unmatchedHeaderEvent);
  List<Channel> optCh3 = selector.getOptionalChannels(unmatchedHeaderEvent);
  Assert.assertEquals(2, reqCh3.size());
  Assert.assertTrue(reqCh3.get(0).getName().equals("ch1"));
  Assert.assertTrue(reqCh3.get(1).getName().equals("ch3"));
  Assert.assertTrue(optCh3.isEmpty());

  Map<String, String> header4 = new HashMap<String, String>();
  header4.put("myheader", "zebra");
  Event zebraEvent = new MockEvent();
  zebraEvent.setHeaders(header4);

  List<Channel> reqCh4 = selector.getRequiredChannels(zebraEvent);
  List<Channel> optCh4 = selector.getOptionalChannels(zebraEvent);
  Assert.assertEquals(2, reqCh4.size());
  Assert.assertTrue(reqCh4.get(0).getName().equals("ch1"));
  Assert.assertTrue(reqCh4.get(1).getName().equals("ch3"));
  //Since ch1 is also in default list, it is removed.
  Assert.assertTrue(optCh4.size() == 1);
  Assert.assertTrue(optCh4.get(0).getName().equals("ch2"));

  List<Channel> allChannels = selector.getAllChannels();
  Assert.assertTrue(allChannels.size() == 3);
  Assert.assertTrue(allChannels.get(0).getName().equals("ch1"));
  Assert.assertTrue(allChannels.get(1).getName().equals("ch2"));
  Assert.assertTrue(allChannels.get(2).getName().equals("ch3"));
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:63,代碼來源:TestMultiplexingChannelSelector.java

示例13: testNoDefault

import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testNoDefault() {

  config.put("mapping.foo", "ch1 ch2");
  config.put("mapping.bar", "ch2 ch3");
  config.put("mapping.xyz", "ch1 ch2 ch3");
  config.put("mapping.zebra", "ch2");
  config.put("optional.zebra", "ch1 ch3");
  selector = ChannelSelectorFactory.create(channels, config);
  Assert.assertTrue(selector instanceof MultiplexingChannelSelector);

  Event event1 = new MockEvent();
  Map<String, String> header1 = new HashMap<String, String>();
  header1.put("myheader", "foo");// should match ch1 ch2
  event1.setHeaders(header1);

  List<Channel> reqCh1 = selector.getRequiredChannels(event1);
  Assert.assertEquals(2, reqCh1.size());
  Assert.assertEquals("ch1", reqCh1.get(0).getName());
  Assert.assertEquals("ch2", reqCh1.get(1).getName());
  List<Channel> optCh1 = selector.getOptionalChannels(event1);
  Assert.assertTrue(optCh1.size() == 1);
  //ch2 should not be there -- since it is a required channel
  Assert.assertEquals("ch3", optCh1.get(0).getName());



  Event event2 = new MockEvent();
  Map<String, String> header2 = new HashMap<String, String>();
  header2.put("myheader", "bar"); // should match ch2 ch3
  event2.setHeaders(header2);

  List<Channel> reqCh2 = selector.getRequiredChannels(event2);
  Assert.assertEquals(2, reqCh2.size());
  Assert.assertEquals("ch2", reqCh2.get(0).getName());
  Assert.assertEquals("ch3", reqCh2.get(1).getName());
  List<Channel> optCh2 = selector.getOptionalChannels(event2);
  Assert.assertTrue(optCh2.isEmpty());

  Event event3 = new MockEvent();
  Map<String, String> header3 = new HashMap<String, String>();
  header3.put("myheader", "xyz"); // should match ch1 ch2 ch3
  event3.setHeaders(header3);

  List<Channel> reqCh3 = selector.getRequiredChannels(event3);
  Assert.assertEquals(3, reqCh3.size());
  Assert.assertEquals("ch1", reqCh3.get(0).getName());
  Assert.assertEquals("ch2", reqCh3.get(1).getName());
  Assert.assertEquals("ch3", reqCh3.get(2).getName());
  List<Channel> optCh3 = selector.getOptionalChannels(event3);
  //All of the optional channels should go away.
  Assert.assertTrue(optCh3.isEmpty());

  Event event4 = new MockEvent();
  Map<String, String> header4 = new HashMap<String, String>();
  header4.put("myheader", "zebra");
  event4.setHeaders(header4);

  List<Channel> reqCh4 = selector.getRequiredChannels(event4);
  Assert.assertEquals(1, reqCh4.size());
  Assert.assertEquals("ch2", reqCh4.get(0).getName());
  List<Channel> optCh4 = selector.getOptionalChannels(event4);
  Assert.assertEquals(2, optCh4.size());
  Assert.assertEquals("ch1", optCh4.get(0).getName());
  Assert.assertEquals("ch3", optCh4.get(1).getName());
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:67,代碼來源:TestMultiplexingChannelSelector.java


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