当前位置: 首页>>代码示例>>Java>>正文


Java Sink类代码示例

本文整理汇总了Java中org.apache.flume.Sink的典型用法代码示例。如果您正苦于以下问题:Java Sink类的具体用法?Java Sink怎么用?Java Sink使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Sink类属于org.apache.flume包,在下文中一共展示了Sink类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public Status process() throws EventDeliveryException {
  Status status = null;

  Iterator<Sink> sinkIterator = selector.createSinkIterator();
  while (sinkIterator.hasNext()) {
    Sink sink = sinkIterator.next();
    try {
      status = sink.process();
      break;
    } catch (Exception ex) {
      selector.informSinkFailed(sink);
      LOGGER.warn("Sink failed to consume event. "
          + "Attempting next sink if available.", ex);
    }
  }

  if (status == null) {
    throw new EventDeliveryException("All configured sinks have failed");
  }

  return status;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:24,代码来源:LoadBalancingSinkProcessor.java

示例2: testDuplicateCreate

import org.apache.flume.Sink; //导入依赖的package包/类
@Test
public void testDuplicateCreate() {

  Sink avroSink1 = sinkFactory.create("avroSink1", "avro");
  Sink avroSink2 = sinkFactory.create("avroSink2", "avro");

  Assert.assertNotNull(avroSink1);
  Assert.assertNotNull(avroSink2);
  Assert.assertNotSame(avroSink1, avroSink2);
  Assert.assertTrue(avroSink1 instanceof AvroSink);
  Assert.assertTrue(avroSink2 instanceof AvroSink);

  Sink s1 = sinkFactory.create("avroSink1", "avro");
  Sink s2 = sinkFactory.create("avroSink2", "avro");

  Assert.assertNotSame(avroSink1, s1);
  Assert.assertNotSame(avroSink2, s2);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:19,代码来源:TestDefaultSinkFactory.java

示例3: testStaticTopic

import org.apache.flume.Sink; //导入依赖的package包/类
@Test
public void testStaticTopic() {
  Context context = prepareDefaultContext();
  // add the static topic
  context.put(TOPIC_CONFIG, TestConstants.STATIC_TOPIC);
  String msg = "static-topic-test";

  try {
    Sink.Status status = prepareAndSend(context, msg);
    if (status == Sink.Status.BACKOFF) {
      fail("Error Occurred");
    }
  } catch (EventDeliveryException ex) {
    // ignore
  }

  String fetchedMsg = new String((byte[]) testUtil.getNextMessageFromConsumer(
      TestConstants.STATIC_TOPIC).message());
  assertEquals(msg, fetchedMsg);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestKafkaSink.java

示例4: testEmptyChannel

import org.apache.flume.Sink; //导入依赖的package包/类
@Test
public void testEmptyChannel() throws UnsupportedEncodingException, EventDeliveryException {
  Sink kafkaSink = new KafkaSink();
  Context context = prepareDefaultContext();
  Configurables.configure(kafkaSink, context);
  Channel memoryChannel = new MemoryChannel();
  Configurables.configure(memoryChannel, context);
  kafkaSink.setChannel(memoryChannel);
  kafkaSink.start();

  Sink.Status status = kafkaSink.process();
  if (status != Sink.Status.BACKOFF) {
    fail("Error Occurred");
  }
  assertNull(testUtil.getNextMessageFromConsumer(DEFAULT_TOPIC));
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:TestKafkaSink.java

示例5: prepareAndSend

import org.apache.flume.Sink; //导入依赖的package包/类
private Sink.Status prepareAndSend(Context context, String msg)
    throws EventDeliveryException {
  Sink kafkaSink = new KafkaSink();
  Configurables.configure(kafkaSink, context);
  Channel memoryChannel = new MemoryChannel();
  Configurables.configure(memoryChannel, context);
  kafkaSink.setChannel(memoryChannel);
  kafkaSink.start();

  Transaction tx = memoryChannel.getTransaction();
  tx.begin();
  Event event = EventBuilder.withBody(msg.getBytes());
  memoryChannel.put(event);
  tx.commit();
  tx.close();

  return kafkaSink.process();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:19,代码来源:TestKafkaSink.java

示例6: run

import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public void run() {
  run = true;
  while (run && count < until) {
    boolean error = true;
    try {
      if (Sink.Status.READY.equals(sink.process())) {
        count++;
        error = false;
      }
    } catch (Exception ex) {
      errors.add(ex);
    }
    if (error) {
      try {
        Thread.sleep(1000L);
      } catch (InterruptedException e) {
      }
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:CountingSinkRunner.java

示例7: processEmtpyChannel

import org.apache.flume.Sink; //导入依赖的package包/类
@Ignore @Test
public void processEmtpyChannel() throws EventDeliveryException {
  final CassandraSink sink = new CassandraSink();
  final Channel channel = mock(Channel.class);
  final Transaction tx = mock(Transaction.class);
  final CassandraTable table = mock(CassandraTable.class);
  final Context ctx = new Context();
  ctx.put("tables", "keyspace.table");
  sink.configure(ctx);
  sink.tables = Collections.singletonList(table);
  sink.setChannel(channel);
  when(channel.getTransaction()).thenReturn(tx);
  when(channel.take()).thenReturn(null);
  assertThat(sink.process()).isEqualTo(Sink.Status.READY);
  verifyZeroInteractions(table);
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:17,代码来源:TestCassandraSink.java

示例8: processOneEvent

import org.apache.flume.Sink; //导入依赖的package包/类
@Ignore @Test
public void processOneEvent() throws EventDeliveryException {
  final CassandraSink sink = new CassandraSink();
  final Channel channel = mock(Channel.class);
  final Transaction tx = mock(Transaction.class);
  final CassandraTable table = mock(CassandraTable.class);
  final Context ctx = new Context();
  ctx.put("tables", "keyspace.table");
  sink.configure(ctx);
  sink.tables = Collections.singletonList(table);
  sink.setChannel(channel);
  when(channel.getTransaction()).thenReturn(tx);
  final Event event = EventBuilder.withBody(new byte[0], ImmutableMap.of("id", "1", "col", "text"));
  when(channel.take()).thenReturn(event).thenReturn(null);
  assertThat(sink.process()).isEqualTo(Sink.Status.READY);
  verify(table).save(ImmutableList.of(event));
  verifyNoMoreInteractions(table);
  verify(tx).begin();
  verify(tx).commit();
  verify(tx).close();
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:22,代码来源:TestCassandraSink.java

示例9: processOneEventWithBatchSizeOne

import org.apache.flume.Sink; //导入依赖的package包/类
@Test
public void processOneEventWithBatchSizeOne() throws EventDeliveryException {
  final CassandraSink sink = new CassandraSink();
  final Channel channel = mock(Channel.class);
  final Transaction tx = mock(Transaction.class);
  final CassandraTable table = mock(CassandraTable.class);
  final Context ctx = new Context();
  ctx.put("tables", "keyspace.table");
  ctx.put("batchSize", "1");
  sink.configure(ctx);
  sink.tables = Collections.singletonList(table);
  sink.setChannel(channel);
  when(channel.getTransaction()).thenReturn(tx);
  final Event event = EventBuilder.withBody(new byte[0], ImmutableMap.of("id", "1", "col", "text"));
  when(channel.take()).thenReturn(event).thenReturn(null);
  assertThat(sink.process()).isEqualTo(Sink.Status.READY);
  verify(table).save(ImmutableList.of(event));
  verifyNoMoreInteractions(table);
  verify(tx).begin();
  verify(tx).commit();
  verify(tx).close();
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:23,代码来源:TestCassandraSink.java

示例10: moveActiveToDeadAndGetNext

import org.apache.flume.Sink; //导入依赖的package包/类
private Sink moveActiveToDeadAndGetNext() {
  Integer key = liveSinks.lastKey();
  failedSinks.add(new FailedSink(key, activeSink, 1));
  liveSinks.remove(key);
  if (liveSinks.isEmpty()) return null;
  if (liveSinks.lastKey() != null) {
    return liveSinks.get(liveSinks.lastKey());
  } else {
    return null;
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:12,代码来源:FailoverSinkProcessor.java

示例11: setSinks

import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public void setSinks(List<Sink> sinks) {
  // needed to implement the start/stop functionality
  super.setSinks(sinks);

  this.sinks = new HashMap<String, Sink>();
  for (Sink sink : sinks) {
    this.sinks.put(sink.getName(), sink);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:11,代码来源:FailoverSinkProcessor.java

示例12: setSinks

import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public void setSinks(List<Sink> sinks) {
  Preconditions.checkNotNull(sinks);
  Preconditions.checkArgument(sinks.size() == 1, "DefaultSinkPolicy can "
      + "only handle one sink, "
      + "try using a policy that supports multiple sinks");
  sink = sinks.get(0);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:9,代码来源:DefaultSinkProcessor.java

示例13: create

import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public Sink create(String name, String type) throws FlumeException {
  Preconditions.checkNotNull(name, "name");
  Preconditions.checkNotNull(type, "type");
  logger.info("Creating instance of sink: {}, type: {}", name, type);
  Class<? extends Sink> sinkClass = getClass(type);
  try {
    Sink sink = sinkClass.newInstance();
    sink.setName(name);
    return sink;
  } catch (Exception ex) {
    throw new FlumeException("Unable to create sink: " + name
        + ", type: " + type + ", class: " + sinkClass.getName(), ex);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:16,代码来源:DefaultSinkFactory.java

示例14: start

import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public void start() {
  for (Sink s : sinkList) {
    s.start();
  }

  state = LifecycleState.START;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:9,代码来源:AbstractSinkProcessor.java

示例15: stop

import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public void stop() {
  for (Sink s : sinkList) {
    s.stop();
  }
  state = LifecycleState.STOP;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:8,代码来源:AbstractSinkProcessor.java


注:本文中的org.apache.flume.Sink类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。