Skip to content

Commit

Permalink
feature: add workflow definition graph and service
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqi committed Sep 8, 2024
1 parent 9f3e808 commit 0d9f1c2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,7 +110,7 @@ private Action<WorkflowInstanceState, WorkflowInstanceEvent, Pair<Long, Throwabl

Message message = Message.builder()
.topic(queue.getName())
.body(FuryUtil.serializeByJava(eventDTO))
.body(Serder.serializeByJava(eventDTO))
.build();
queue.push(message);
};
Expand Down

0 comments on commit 0d9f1c2

Please sign in to comment.