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/23 14:23:02 UTC
[incubator-eventmesh] branch storage-api updated: [ISSUE #1777] add CloudEventUtils under storage api module
This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch storage-api
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/storage-api by this push:
new 7a3ee6ed [ISSUE #1777] add CloudEventUtils under storage api module
new 6c5d77fc Merge pull request #1780 from githublaohu/jdbc-connector-storage
7a3ee6ed is described below
commit 7a3ee6ed4941fc9d0743a40c733e8309aab50179
Author: githublaohu <23...@qq.com>
AuthorDate: Sun Oct 23 22:16:45 2022 +0800
[ISSUE #1777] add CloudEventUtils under storage api module
---
.../api/connector/storage/CloudEventUtils.java | 94 ++++++++++++++++++++++
.../eventmesh/api/connector/storage/Constant.java | 23 ++++++
2 files changed, 117 insertions(+)
diff --git a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/storage/CloudEventUtils.java b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/storage/CloudEventUtils.java
new file mode 100644
index 00000000..d935c5ba
--- /dev/null
+++ b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/storage/CloudEventUtils.java
@@ -0,0 +1,94 @@
+/*
+ * 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.api.connector.storage;
+
+import org.apache.eventmesh.api.connector.storage.data.CloudEventInfo;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.Objects;
+
+import io.cloudevents.CloudEvent;
+import io.cloudevents.core.impl.BaseCloudEvent;
+import io.cloudevents.core.v03.CloudEventV03;
+import io.cloudevents.core.v1.CloudEventV1;
+
+public class CloudEventUtils {
+
+ private static Field CLOUD_EVENT_EXTENSIONS_FIELD;
+
+ static {
+ try {
+ CLOUD_EVENT_EXTENSIONS_FIELD = BaseCloudEvent.class.getField("extensions");
+ CLOUD_EVENT_EXTENSIONS_FIELD.setAccessible(true);
+ } catch (NoSuchFieldException | SecurityException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static CloudEvent setValue(CloudEvent cloudEvent, String key, Object value) {
+ if (Objects.nonNull(CLOUD_EVENT_EXTENSIONS_FIELD)
+ && (cloudEvent instanceof CloudEventV1 || cloudEvent instanceof CloudEventV03)) {
+ try {
+ Map<String, Object> extensions = (Map<String, Object>) CLOUD_EVENT_EXTENSIONS_FIELD.get(cloudEvent);
+ extensions.put(key, value);
+ return cloudEvent;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ public static String getNodeAdress(CloudEvent cloudEvent) {
+ return (String) cloudEvent.getExtension(Constant.NODE_ADDRESS);
+ }
+
+ public static String getTopic(CloudEvent cloudEvent) {
+ return null;
+ }
+
+ public static String getId(CloudEvent cloudEvent) {
+ return null;
+ }
+
+ public static CloudEvent createCloudEvent(CloudEventInfo cloudEventInfo) {
+
+ return null;
+ }
+
+ public static CloudEvent createReplyDataEvent(CloudEventInfo cloudEventInfo) {
+
+ return null;
+ }
+
+ public static String getCloudEventMessageId(CloudEventInfo cloudEventInfo) {
+
+ return null;
+ }
+
+ public static String serializeReplyData(CloudEvent cloudEvent) {
+ return null;
+ }
+
+ public static String deserializeReplyData(CloudEventInfo cloudEventInfo) {
+ return null;
+ }
+
+}
diff --git a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/storage/Constant.java b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/storage/Constant.java
new file mode 100644
index 00000000..f08d62cf
--- /dev/null
+++ b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/storage/Constant.java
@@ -0,0 +1,23 @@
+/*
+ * 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.api.connector.storage;
+
+public class Constant {
+
+ public static final String NODE_ADDRESS = "nodeAddress";
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org