You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/10/10 03:14:48 UTC

[incubator-eventmesh] branch eventmesh-filters updated: [ISSUE #1502] Add StaticFilterLoader for filter module

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch eventmesh-filters
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/eventmesh-filters by this push:
     new c6f5fd87 [ISSUE #1502] Add StaticFilterLoader for filter module
     new 37a033e8 Merge pull request #1504 from xwm1992/eventmesh-filter
c6f5fd87 is described below

commit c6f5fd87fd636f5726da573c51f7cd67d25351dc
Author: xwm1992 <mi...@126.com>
AuthorDate: Mon Oct 10 11:03:23 2022 +0800

    [ISSUE #1502] Add StaticFilterLoader for filter module
---
 .../eventmesh/filter/api/loader/FilterLoader.java  |  2 -
 .../filter/api/loader/StaticFilterLoader.java      | 63 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/eventmesh-filter-plugin/eventmesh-filter-api/src/main/java/org/apache/eventmesh/filter/api/loader/FilterLoader.java b/eventmesh-filter-plugin/eventmesh-filter-api/src/main/java/org/apache/eventmesh/filter/api/loader/FilterLoader.java
index 03180222..c1e514b2 100644
--- a/eventmesh-filter-plugin/eventmesh-filter-api/src/main/java/org/apache/eventmesh/filter/api/loader/FilterLoader.java
+++ b/eventmesh-filter-plugin/eventmesh-filter-api/src/main/java/org/apache/eventmesh/filter/api/loader/FilterLoader.java
@@ -23,8 +23,6 @@ import org.apache.eventmesh.filter.api.FilterType;
 import java.util.Comparator;
 import java.util.SortedSet;
 
-import io.cloudevents.CloudEvent;
-
 public interface FilterLoader {
 
     Comparator<EventMeshFilter<?, ?>> FILTER_COMPARATOR =
diff --git a/eventmesh-filter-plugin/eventmesh-filter-api/src/main/java/org/apache/eventmesh/filter/api/loader/StaticFilterLoader.java b/eventmesh-filter-plugin/eventmesh-filter-api/src/main/java/org/apache/eventmesh/filter/api/loader/StaticFilterLoader.java
new file mode 100644
index 00000000..235d3c15
--- /dev/null
+++ b/eventmesh-filter-plugin/eventmesh-filter-api/src/main/java/org/apache/eventmesh/filter/api/loader/StaticFilterLoader.java
@@ -0,0 +1,63 @@
+/*
+ * 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.filter.api.loader;
+
+import org.apache.eventmesh.filter.api.EventMeshFilter;
+import org.apache.eventmesh.filter.api.FilterType;
+import org.apache.eventmesh.filter.api.factory.FilterFactory;
+import org.apache.eventmesh.filter.api.factory.StaticFilterPluginFactory;
+
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import io.cloudevents.CloudEvent;
+
+public class StaticFilterLoader implements FilterLoader {
+
+    private static final FilterFactory filterFactory = new StaticFilterPluginFactory();
+
+    private static final List<String> FILTER_NAME_LIST = Arrays.asList("source-default");
+
+    private static final Map<FilterType, SortedSet<EventMeshFilter<?, ?>>> FILTER_TYPE_SORTED_SET_MAP
+        = new EnumMap<>(FilterType.class);
+
+    static {
+        loadFilters();
+    }
+
+    //todo: load filters when server init
+
+    @Override
+    public SortedSet<EventMeshFilter<?, ?>> getFiltersByType(FilterType filterType) {
+
+        return FILTER_TYPE_SORTED_SET_MAP.get(filterType);
+    }
+
+    public static void loadFilters() {
+        for (String filterName : FILTER_NAME_LIST) {
+            EventMeshFilter<CloudEvent, CloudEvent> eventMeshFilter = filterFactory.getMeshFilter(filterName);
+
+            FILTER_TYPE_SORTED_SET_MAP.computeIfAbsent(eventMeshFilter.filterType(),
+                k -> new TreeSet<>(FILTER_COMPARATOR)).add(eventMeshFilter);
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org