Skip to content

Commit 551610d

Browse files
authored
[ISSUE #5108] Abstracting and transforming EventMeshFunction, and implementing FunctionRuntime. (#5109)
* feat: Unified function module * feat: update something * feat: update FunctionRuntime * feat: update FunctionRuntime
1 parent 5412bbb commit 551610d

File tree

42 files changed

+901
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+901
-85
lines changed

eventmesh-filter/build.gradle renamed to eventmesh-function/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
18-
19-
dependencies {
20-
implementation project(":eventmesh-common")
21-
}

eventmesh-transformer/build.gradle renamed to eventmesh-function/eventmesh-function-api/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
18-
19-
dependencies {
20-
implementation project(":eventmesh-common")
21-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.eventmesh.function.api;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
/**
24+
* AbstractEventMeshFunctionChain is an abstract class that implements the {@link EventMeshFunction} interface and provides a framework
25+
* for chaining multiple {@link EventMeshFunction} instances that operate on inputs of type {@code T} and produce outputs of type
26+
* {@code R}. This class can be extended to create specific function chains with customized behavior for different
27+
* data types.
28+
*
29+
* <p>The primary purpose of this class is to allow the sequential execution of functions, where the output of one
30+
* function is passed as the input to the next function in the chain. The chain can be dynamically modified by adding
31+
* functions either at the beginning or the end of the chain.</p>
32+
*
33+
* @param <T> the type of the input to the function
34+
* @param <R> the type of the result of the function
35+
*/
36+
public abstract class AbstractEventMeshFunctionChain<T, R> implements EventMeshFunction<T, R> {
37+
38+
protected final List<EventMeshFunction<T, R>> functions;
39+
40+
/**
41+
* Default constructor that initializes an empty function chain.
42+
*/
43+
public AbstractEventMeshFunctionChain() {
44+
this.functions = new ArrayList<>();
45+
}
46+
47+
/**
48+
* Constructor that initializes the function chain with a given list of functions. The functions will be executed
49+
* in the order they are provided when the {@link #apply(Object)} method is called.
50+
*
51+
* @param functions the initial list of functions to be added to the chain
52+
*/
53+
public AbstractEventMeshFunctionChain(List<EventMeshFunction<T, R>> functions) {
54+
this.functions = functions;
55+
}
56+
57+
/**
58+
* Adds a {@link EventMeshFunction} to the beginning of the chain. The function will be executed first when the
59+
* {@link #apply(Object)} method is called.
60+
*
61+
* @param function the function to be added to the beginning of the chain
62+
*/
63+
public void addFirst(EventMeshFunction<T, R> function) {
64+
this.functions.add(0, function);
65+
}
66+
67+
/**
68+
* Adds a {@link EventMeshFunction} to the end of the chain. The function will be executed in sequence after all previously
69+
* added functions when the {@link #apply(Object)} method is called.
70+
*
71+
* @param function the function to be added to the end of the chain
72+
*/
73+
public void addLast(EventMeshFunction<T, R> function) {
74+
this.functions.add(function);
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.eventmesh.function.api;
19+
20+
/**
21+
* EventMesh Interface for a function that accepts one argument and produces a result. This is a functional interface whose functional method is
22+
* {@link #apply(Object)}.
23+
*
24+
* <p>This interface is similar to {@link java.util.function.Function},
25+
* but it is specifically designed for use within the EventMesh. It allows defining custom functions to process data or events in the EventMesh. The
26+
* main use case is to encapsulate operations that can be passed around and applied to data or event messages in the EventMesh processing
27+
* pipeline.</p>
28+
*
29+
* @param <T> the type of the input to the function
30+
* @param <R> the type of the result of the function
31+
*/
32+
public interface EventMeshFunction<T, R> {
33+
34+
/**
35+
* Applies this function to the given argument within the context of the EventMesh module. This method encapsulates the logic for processing the
36+
* input data and producing a result, which can be used in the EventMesh event processing pipeline.
37+
*
38+
* @param t the function argument, representing the input data or event to be processed
39+
* @return the function result, representing the processed output
40+
*/
41+
R apply(T t);
42+
43+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
dependencies {
19+
implementation project(":eventmesh-common")
20+
implementation project(":eventmesh-function:eventmesh-function-api")
21+
}

eventmesh-filter/src/main/java/org/apache/eventmesh/filter/PatternEntry.java renamed to eventmesh-function/eventmesh-function-filter/src/main/java/org/apache/eventmesh/function/filter/PatternEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.eventmesh.filter;
18+
package org.apache.eventmesh.function.filter;
1919

20-
import org.apache.eventmesh.filter.condition.Condition;
20+
import org.apache.eventmesh.function.filter.condition.Condition;
2121

2222
import java.util.ArrayList;
2323
import java.util.List;

eventmesh-filter/src/main/java/org/apache/eventmesh/filter/condition/AnythingButCondition.java renamed to eventmesh-function/eventmesh-function-filter/src/main/java/org/apache/eventmesh/function/filter/condition/AnythingButCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.eventmesh.filter.condition;
18+
package org.apache.eventmesh.function.filter.condition;
1919

2020
import java.util.ArrayList;
2121
import java.util.Iterator;

eventmesh-filter/src/main/java/org/apache/eventmesh/filter/condition/Condition.java renamed to eventmesh-function/eventmesh-function-filter/src/main/java/org/apache/eventmesh/function/filter/condition/Condition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.eventmesh.filter.condition;
18+
package org.apache.eventmesh.function.filter.condition;
1919

2020
import com.fasterxml.jackson.databind.JsonNode;
2121

eventmesh-filter/src/main/java/org/apache/eventmesh/filter/condition/ConditionsBuilder.java renamed to eventmesh-function/eventmesh-function-filter/src/main/java/org/apache/eventmesh/function/filter/condition/ConditionsBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.eventmesh.filter.condition;
18+
package org.apache.eventmesh.function.filter.condition;
1919

2020
import com.fasterxml.jackson.databind.JsonNode;
2121

eventmesh-filter/src/main/java/org/apache/eventmesh/filter/condition/ExistsCondition.java renamed to eventmesh-function/eventmesh-function-filter/src/main/java/org/apache/eventmesh/function/filter/condition/ExistsCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.eventmesh.filter.condition;
18+
package org.apache.eventmesh.function.filter.condition;
1919

2020
import com.fasterxml.jackson.databind.JsonNode;
2121

0 commit comments

Comments
 (0)