org.apache.flink.cep.PatternProcessFunctionBuilder Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.cep;
import org.apache.flink.annotation.Internal;
import org.apache.flink.cep.functions.PatternProcessFunction;
import org.apache.flink.cep.functions.adaptors.PatternFlatSelectAdapter;
import org.apache.flink.cep.functions.adaptors.PatternSelectAdapter;
import org.apache.flink.cep.functions.adaptors.PatternTimeoutFlatSelectAdapter;
import org.apache.flink.cep.functions.adaptors.PatternTimeoutSelectAdapter;
import org.apache.flink.util.OutputTag;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
* Builder for adapting pre-1.8 functions like {@link PatternFlatSelectFunction}, {@link
* PatternFlatTimeoutFunction} into {@link PatternProcessFunction}.
*/
@Internal
class PatternProcessFunctionBuilder {
/**
* Starts constructing a {@link PatternProcessFunction} from a {@link PatternFlatSelectFunction}
* that emitted elements through {@link org.apache.flink.util.Collector}.
*/
static FlatSelectBuilder fromFlatSelect(
final PatternFlatSelectFunction function) {
return new FlatSelectBuilder<>(function);
}
/**
* Starts constructing a {@link PatternProcessFunction} from a {@link PatternSelectFunction}
* that emitted elements through return value.
*/
static SelectBuilder fromSelect(
final PatternSelectFunction function) {
return new SelectBuilder<>(function);
}
/**
* Wraps {@link PatternFlatSelectFunction} in a builder. The builder can construct a * {@link
* PatternProcessFunction} adapter.
*/
static class FlatSelectBuilder {
private final PatternFlatSelectFunction flatSelectFunction;
FlatSelectBuilder(PatternFlatSelectFunction function) {
this.flatSelectFunction = checkNotNull(function);
}
FlatTimeoutSelectBuilder withTimeoutHandler(
final OutputTag outputTag,
final PatternFlatTimeoutFunction timeoutHandler) {
return new FlatTimeoutSelectBuilder<>(flatSelectFunction, timeoutHandler, outputTag);
}
PatternProcessFunction build() {
return new PatternFlatSelectAdapter<>(flatSelectFunction);
}
}
/**
* Wraps {@link PatternFlatSelectFunction} and {@link PatternFlatTimeoutFunction} in a builder.
* The builder will create a {@link PatternProcessFunction} adapter that handles timed out
* partial matches as well.
*/
static class FlatTimeoutSelectBuilder {
private final PatternFlatSelectFunction flatSelectFunction;
private final PatternFlatTimeoutFunction timeoutHandler;
private final OutputTag outputTag;
FlatTimeoutSelectBuilder(
final PatternFlatSelectFunction flatSelectFunction,
final PatternFlatTimeoutFunction timeoutHandler,
final OutputTag outputTag) {
this.flatSelectFunction = checkNotNull(flatSelectFunction);
this.timeoutHandler = checkNotNull(timeoutHandler);
this.outputTag = checkNotNull(outputTag);
}
PatternProcessFunction build() {
return new PatternTimeoutFlatSelectAdapter<>(
flatSelectFunction, timeoutHandler, outputTag);
}
}
/**
* Wraps {@link PatternSelectFunction} in a builder. The builder can construct a {@link
* PatternProcessFunction} adapter.
*/
static class SelectBuilder {
private final PatternSelectFunction selectFunction;
SelectBuilder(PatternSelectFunction function) {
this.selectFunction = checkNotNull(function);
}
TimeoutSelectBuilder withTimeoutHandler(
final OutputTag outputTag,
final PatternTimeoutFunction timeoutHandler) {
return new TimeoutSelectBuilder<>(selectFunction, timeoutHandler, outputTag);
}
PatternProcessFunction build() {
return new PatternSelectAdapter<>(selectFunction);
}
}
/**
* Wraps {@link PatternSelectFunction} and {@link PatternTimeoutFunction} in a builder. The
* builder will create a {@link PatternProcessFunction} adapter that handles timed out partial
* matches as well.
*/
static class TimeoutSelectBuilder {
private final PatternSelectFunction selectFunction;
private final PatternTimeoutFunction timeoutHandler;
private final OutputTag outputTag;
TimeoutSelectBuilder(
final PatternSelectFunction flatSelectFunction,
final PatternTimeoutFunction timeoutHandler,
final OutputTag outputTag) {
this.selectFunction = checkNotNull(flatSelectFunction);
this.timeoutHandler = checkNotNull(timeoutHandler);
this.outputTag = checkNotNull(outputTag);
}
PatternProcessFunction build() {
return new PatternTimeoutSelectAdapter<>(selectFunction, timeoutHandler, outputTag);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy