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/09/18 07:40:39 UTC

[incubator-eventmesh] branch master updated: add selector interface

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a3eeea5c add selector interface
     new 76e1cec0 Merge pull request #1290 from walterlife/selector
a3eeea5c is described below

commit a3eeea5c5319a5d8f57f073bcfb398e54662ca3f
Author: walterlife <wa...@gmail.com>
AuthorDate: Thu Sep 15 22:01:51 2022 +0800

    add selector interface
---
 .../apache/eventmesh/client/selector/Selector.java | 25 +++++++++++++
 .../client/selector/SelectorException.java         | 30 ++++++++++++++++
 .../eventmesh/client/selector/SelectorFactory.java | 36 +++++++++++++++++++
 .../eventmesh/client/selector/ServiceInstance.java | 42 ++++++++++++++++++++++
 4 files changed, 133 insertions(+)

diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/Selector.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/Selector.java
new file mode 100644
index 00000000..b47dd25d
--- /dev/null
+++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/Selector.java
@@ -0,0 +1,25 @@
+/*
+ * 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.client.selector;
+
+/**
+ * Selector is the abstract of selecting registry service instances
+ */
+public interface Selector {
+    ServiceInstance selectOne(String serverName) throws SelectorException;
+}
diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java
new file mode 100644
index 00000000..bf960a7c
--- /dev/null
+++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.client.selector;
+
+public class SelectorException extends RuntimeException {
+    private static final long serialVersionUID = 7126682512429265292L;
+
+    public SelectorException(String message) {
+        super(message);
+    }
+
+    public SelectorException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java
new file mode 100644
index 00000000..5a92d366
--- /dev/null
+++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/SelectorFactory.java
@@ -0,0 +1,36 @@
+/*
+ * 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.client.selector;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SelectorFactory {
+    private static final Map<String, Selector> selectorMap = new HashMap<>();
+
+    public static Selector get(String type) {
+        return selectorMap.get(type);
+    }
+
+    public static void register(String type, Selector selector) {
+        if (selector == null) {
+            return;
+        }
+        selectorMap.put(type, selector);
+    }
+}
diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java
new file mode 100644
index 00000000..e43ef67d
--- /dev/null
+++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/selector/ServiceInstance.java
@@ -0,0 +1,42 @@
+/*
+ * 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.client.selector;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import lombok.Data;
+
+@Data
+public class ServiceInstance implements Serializable {
+
+    private static final long serialVersionUID = -5770826614635186498L;
+
+    private String host;
+    private int port;
+    private boolean isHealthy;
+    private Map<String, String> metadata;
+
+    public ServiceInstance() {
+        this.host = null;
+        this.port = 0;
+        this.isHealthy = true;
+        this.metadata = new HashMap<>();
+    }
+}


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