本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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));
}
示例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();
}
示例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) {
}
}
}
}
示例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);
}
示例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();
}
示例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();
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例14: start
import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public void start() {
for (Sink s : sinkList) {
s.start();
}
state = LifecycleState.START;
}
示例15: stop
import org.apache.flume.Sink; //导入依赖的package包/类
@Override
public void stop() {
for (Sink s : sinkList) {
s.stop();
}
state = LifecycleState.STOP;
}