|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.flink.streaming.api.functions.sink.v2; |
| 19 | + |
| 20 | +import org.apache.flink.annotation.PublicEvolving; |
| 21 | +import org.apache.flink.api.common.SupportsConcurrentExecutionAttempts; |
| 22 | +import org.apache.flink.api.connector.sink2.Sink; |
| 23 | +import org.apache.flink.api.connector.sink2.SinkWriter; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | + |
| 27 | +/** |
| 28 | + * A special sink that ignores all elements. |
| 29 | + * |
| 30 | + * @param <IN> The type of elements received by the sink. |
| 31 | + */ |
| 32 | +@PublicEvolving |
| 33 | +public class DiscardingSink<IN> implements Sink<IN>, SupportsConcurrentExecutionAttempts { |
| 34 | + private static final long serialVersionUID = 1L; |
| 35 | + |
| 36 | + @Override |
| 37 | + public SinkWriter<IN> createWriter(InitContext context) throws IOException { |
| 38 | + return new DiscardingElementWriter(); |
| 39 | + } |
| 40 | + |
| 41 | + private class DiscardingElementWriter implements SinkWriter<IN> { |
| 42 | + |
| 43 | + @Override |
| 44 | + public void write(IN element, Context context) throws IOException, InterruptedException { |
| 45 | + // discard it. |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void flush(boolean endOfInput) throws IOException, InterruptedException { |
| 50 | + // this writer has no pending data. |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void close() throws Exception { |
| 55 | + // do nothing. |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments