From 0d9f1c2ef51eea8fc4d6cef8d962da976c63e390 Mon Sep 17 00:00:00 2001 From: wangqi Date: Sun, 8 Sep 2024 20:39:04 +0800 Subject: [PATCH] feature: add workflow definition graph and service --- .../sliew/carp/module/queue/api/Message.java | 6 ++- .../carp/module/queue/api/util/Serder.java | 45 +++++++++++++++++++ .../WorkflowInstanceStateMachine.java | 3 +- 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/util/Serder.java diff --git a/carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/Message.java b/carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/Message.java index c524347e..fc00eefa 100644 --- a/carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/Message.java +++ b/carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/Message.java @@ -18,14 +18,16 @@ package cn.sliew.carp.module.queue.api; +import lombok.Builder; +import lombok.Data; import lombok.Getter; import lombok.Setter; import java.util.EventObject; import java.util.Map; -@Getter -@Setter +@Data +@Builder public final class Message extends EventObject { public Message(Object source) { diff --git a/carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/util/Serder.java b/carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/util/Serder.java new file mode 100644 index 00000000..dbd66c23 --- /dev/null +++ b/carp-modules/carp-module-queue/carp-module-queue-api/src/main/java/cn/sliew/carp/module/queue/api/util/Serder.java @@ -0,0 +1,45 @@ +/* + * 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 cn.sliew.carp.module.queue.api.util; + +import java.io.*; + +public enum Serder { + ; + + public static byte[] serializeByJava(Object obj) { + try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos)) { + oos.writeObject(obj); + return bos.toByteArray(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static Object deserializeByJava(byte[] bytes) { + try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bis)) { + return ois.readObject(); + + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } +} diff --git a/carp-modules/carp-module-workflow/carp-module-workflow-internal/src/main/java/cn/sliew/carp/module/workflow/internal/statemachine/WorkflowInstanceStateMachine.java b/carp-modules/carp-module-workflow/carp-module-workflow-internal/src/main/java/cn/sliew/carp/module/workflow/internal/statemachine/WorkflowInstanceStateMachine.java index a63e0da7..50d771ec 100644 --- a/carp-modules/carp-module-workflow/carp-module-workflow-internal/src/main/java/cn/sliew/carp/module/workflow/internal/statemachine/WorkflowInstanceStateMachine.java +++ b/carp-modules/carp-module-workflow/carp-module-workflow-internal/src/main/java/cn/sliew/carp/module/workflow/internal/statemachine/WorkflowInstanceStateMachine.java @@ -24,6 +24,7 @@ import cn.sliew.carp.module.queue.api.Message; import cn.sliew.carp.module.queue.api.Queue; import cn.sliew.carp.module.queue.api.QueueFactory; +import cn.sliew.carp.module.queue.api.util.Serder; import cn.sliew.carp.module.workflow.internal.listener.workflowinstance.*; import cn.sliew.milky.common.util.JacksonUtil; import com.alibaba.cola.statemachine.Action; @@ -109,7 +110,7 @@ private Action