Java Code Examples for org.apache.flink.streaming.api.functions.sink.SinkFunction#Context

The following examples show how to use org.apache.flink.streaming.api.functions.sink.SinkFunction#Context . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Buckets.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
Bucket<IN, BucketID> onElement(final IN value, final SinkFunction.Context context) throws Exception {
	final long currentProcessingTime = context.currentProcessingTime();

	// setting the values in the bucketer context
	bucketerContext.update(
			context.timestamp(),
			context.currentWatermark(),
			currentProcessingTime);

	final BucketID bucketId = bucketAssigner.getBucketId(value, bucketerContext);
	final Bucket<IN, BucketID> bucket = getOrCreateBucketForBucketId(bucketId);
	bucket.write(value, currentProcessingTime);

	// we update the global max counter here because as buckets become inactive and
	// get removed from the list of active buckets, at the time when we want to create
	// another part file for the bucket, if we start from 0 we may overwrite previous parts.

	this.maxPartCounter = Math.max(maxPartCounter, bucket.getPartCounter());
	return bucket;
}
 
Example 2
Source File: Buckets.java    From flink with Apache License 2.0 6 votes vote down vote up
Bucket<IN, BucketID> onElement(final IN value, final SinkFunction.Context context) throws Exception {
	final long currentProcessingTime = context.currentProcessingTime();

	// setting the values in the bucketer context
	bucketerContext.update(
			context.timestamp(),
			context.currentWatermark(),
			currentProcessingTime);

	final BucketID bucketId = bucketAssigner.getBucketId(value, bucketerContext);
	final Bucket<IN, BucketID> bucket = getOrCreateBucketForBucketId(bucketId);
	bucket.write(value, currentProcessingTime);

	// we update the global max counter here because as buckets become inactive and
	// get removed from the list of active buckets, at the time when we want to create
	// another part file for the bucket, if we start from 0 we may overwrite previous parts.

	this.maxPartCounter = Math.max(maxPartCounter, bucket.getPartCounter());
	return bucket;
}
 
Example 3
Source File: PubSubSink.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(IN message, SinkFunction.Context context) throws Exception {
	PubsubMessage pubsubMessage = PubsubMessage
		.newBuilder()
		.setData(ByteString.copyFrom(serializationSchema.serialize(message)))
		.build();

	ApiFuture<String> future = publisher.publish(pubsubMessage);
	numPendingFutures.incrementAndGet();
	ApiFutures.addCallback(future, failureHandler, directExecutor());
}
 
Example 4
Source File: PubSubSink.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(IN message, SinkFunction.Context context) throws Exception {
	PubsubMessage pubsubMessage = PubsubMessage
		.newBuilder()
		.setData(ByteString.copyFrom(serializationSchema.serialize(message)))
		.build();

	ApiFuture<String> future = publisher.publish(pubsubMessage);
	numPendingFutures.incrementAndGet();
	ApiFutures.addCallback(future, failureHandler, directExecutor());
}
 
Example 5
Source File: Buckets.java    From flink with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public Bucket<IN, BucketID> onElement(
		final IN value,
		final SinkFunction.Context context) throws Exception {
	return onElement(
			value,
			context.currentProcessingTime(),
			context.timestamp(),
			context.currentWatermark());
}
 
Example 6
Source File: StreamingFileSink.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(IN value, SinkFunction.Context context) throws Exception {
	this.helper.onElement(
			value,
			context.currentProcessingTime(),
			context.timestamp(),
			context.currentWatermark());
}
 
Example 7
Source File: StreamingFileSink.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void invoke(IN value, SinkFunction.Context context) throws Exception {
	buckets.onElement(value, context);
}
 
Example 8
Source File: StreamingFileSink.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void invoke(IN value, SinkFunction.Context context) throws Exception {
	buckets.onElement(value, context);
}
 
Example 9
Source File: BasePostgresSink.java    From FlinkExperiments with MIT License 4 votes vote down vote up
@Override
public void invoke(TEntity entity, SinkFunction.Context context) {
    bulkProcessor.add(entity);
}
 
Example 10
Source File: BaseElasticSearchSink.java    From FlinkExperiments with MIT License 4 votes vote down vote up
@Override
public void invoke(TEntity entity, SinkFunction.Context context) {
    client.index(entity);
}
 
Example 11
Source File: KuduCatalogTest.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
public void invoke(T value, SinkFunction.Context context) throws Exception {
    output.add(value);
}