-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE #5108] Abstracting and transforming EventMeshFunction, and imp…
…lementing FunctionRuntime. (#5109) * feat: Unified function module * feat: update something * feat: update FunctionRuntime * feat: update FunctionRuntime
- Loading branch information
Showing
42 changed files
with
901 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...n-api/src/main/java/org/apache/eventmesh/function/api/AbstractEventMeshFunctionChain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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.eventmesh.function.api; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* AbstractEventMeshFunctionChain is an abstract class that implements the {@link EventMeshFunction} interface and provides a framework | ||
* for chaining multiple {@link EventMeshFunction} instances that operate on inputs of type {@code T} and produce outputs of type | ||
* {@code R}. This class can be extended to create specific function chains with customized behavior for different | ||
* data types. | ||
* | ||
* <p>The primary purpose of this class is to allow the sequential execution of functions, where the output of one | ||
* function is passed as the input to the next function in the chain. The chain can be dynamically modified by adding | ||
* functions either at the beginning or the end of the chain.</p> | ||
* | ||
* @param <T> the type of the input to the function | ||
* @param <R> the type of the result of the function | ||
*/ | ||
public abstract class AbstractEventMeshFunctionChain<T, R> implements EventMeshFunction<T, R> { | ||
|
||
protected final List<EventMeshFunction<T, R>> functions; | ||
|
||
/** | ||
* Default constructor that initializes an empty function chain. | ||
*/ | ||
public AbstractEventMeshFunctionChain() { | ||
this.functions = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Constructor that initializes the function chain with a given list of functions. The functions will be executed | ||
* in the order they are provided when the {@link #apply(Object)} method is called. | ||
* | ||
* @param functions the initial list of functions to be added to the chain | ||
*/ | ||
public AbstractEventMeshFunctionChain(List<EventMeshFunction<T, R>> functions) { | ||
this.functions = functions; | ||
} | ||
|
||
/** | ||
* Adds a {@link EventMeshFunction} to the beginning of the chain. The function will be executed first when the | ||
* {@link #apply(Object)} method is called. | ||
* | ||
* @param function the function to be added to the beginning of the chain | ||
*/ | ||
public void addFirst(EventMeshFunction<T, R> function) { | ||
this.functions.add(0, function); | ||
} | ||
|
||
/** | ||
* Adds a {@link EventMeshFunction} to the end of the chain. The function will be executed in sequence after all previously | ||
* added functions when the {@link #apply(Object)} method is called. | ||
* | ||
* @param function the function to be added to the end of the chain | ||
*/ | ||
public void addLast(EventMeshFunction<T, R> function) { | ||
this.functions.add(function); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...tmesh-function-api/src/main/java/org/apache/eventmesh/function/api/EventMeshFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.eventmesh.function.api; | ||
|
||
/** | ||
* EventMesh Interface for a function that accepts one argument and produces a result. This is a functional interface whose functional method is | ||
* {@link #apply(Object)}. | ||
* | ||
* <p>This interface is similar to {@link java.util.function.Function}, | ||
* but it is specifically designed for use within the EventMesh. It allows defining custom functions to process data or events in the EventMesh. The | ||
* main use case is to encapsulate operations that can be passed around and applied to data or event messages in the EventMesh processing | ||
* pipeline.</p> | ||
* | ||
* @param <T> the type of the input to the function | ||
* @param <R> the type of the result of the function | ||
*/ | ||
public interface EventMeshFunction<T, R> { | ||
|
||
/** | ||
* Applies this function to the given argument within the context of the EventMesh module. This method encapsulates the logic for processing the | ||
* input data and producing a result, which can be used in the EventMesh event processing pipeline. | ||
* | ||
* @param t the function argument, representing the input data or event to be processed | ||
* @return the function result, representing the processed output | ||
*/ | ||
R apply(T t); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
dependencies { | ||
implementation project(":eventmesh-common") | ||
implementation project(":eventmesh-function:eventmesh-function-api") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.