From 33109368d7466346475d6d6f34c60ea1fcf0df51 Mon Sep 17 00:00:00 2001 From: "fulan.zjf" Date: Tue, 11 Feb 2020 11:26:45 +0800 Subject: [PATCH] remove dependency --- cola-statemachine/pom.xml | 25 ------------------- .../statemachine/StateMachineFactory.java | 4 +-- .../builder/TransitionBuilderImpl.java | 2 -- .../cola/statemachine/impl/Debugger.java | 22 ++++++++++++++++ .../cola/statemachine/impl/StateImpl.java | 4 +-- .../statemachine/impl/StateMachineImpl.java | 21 ++++++++++------ .../statemachine/impl/TransitionImpl.java | 6 ++--- .../cola/test/StateMachinePlantUMLTest.java | 7 ++++++ 8 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/Debugger.java diff --git a/cola-statemachine/pom.xml b/cola-statemachine/pom.xml index 6780a28ab..4867c50f1 100644 --- a/cola-statemachine/pom.xml +++ b/cola-statemachine/pom.xml @@ -17,31 +17,6 @@ - - - org.slf4j - slf4j-api - 1.7.9 - provided - - - ch.qos.logback - logback-core - 1.2.3 - provided - - - ch.qos.logback - logback-classic - 1.2.3 - provided - - - org.projectlombok - lombok - 1.16.22 - provided - junit junit diff --git a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/StateMachineFactory.java b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/StateMachineFactory.java index 81c5e2f82..b23594698 100644 --- a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/StateMachineFactory.java +++ b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/StateMachineFactory.java @@ -14,7 +14,7 @@ public class StateMachineFactory { static Map stateMachineMap = new ConcurrentHashMap<>(); - public static void register(StateMachine stateMachine){ + public static void register(StateMachine stateMachine){ String machineId = stateMachine.getMachineId(); if(stateMachineMap.get(machineId) != null){ throw new StateMachineException("The state machine with id ["+machineId+"] is already built, no need to build again"); @@ -22,7 +22,7 @@ public static void register(StateMachine stateMachine){ stateMachineMap.put(stateMachine.getMachineId(), stateMachine); } - public static StateMachine get(String machineId){ + public static StateMachine get(String machineId){ StateMachine stateMachine = stateMachineMap.get(machineId); if(stateMachine == null){ throw new StateMachineException("There is no stateMachine instance for "+machineId+", please build it first"); diff --git a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/TransitionBuilderImpl.java b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/TransitionBuilderImpl.java index dc2a71134..334ed0ffc 100644 --- a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/TransitionBuilderImpl.java +++ b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/builder/TransitionBuilderImpl.java @@ -6,7 +6,6 @@ import com.alibaba.cola.statemachine.Transition; import com.alibaba.cola.statemachine.impl.StateHelper; import com.alibaba.cola.statemachine.impl.TransitionType; -import lombok.extern.slf4j.Slf4j; import java.util.Map; @@ -16,7 +15,6 @@ * @author Frank Zhang * @date 2020-02-07 10:20 PM */ -@Slf4j class TransitionBuilderImpl implements ExternalTransitionBuilder, InternalTransitionBuilder, From, On, To { final Map> stateMap; diff --git a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/Debugger.java b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/Debugger.java new file mode 100644 index 000000000..5453763fb --- /dev/null +++ b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/Debugger.java @@ -0,0 +1,22 @@ +package com.alibaba.cola.statemachine.impl; + +/** + * Debugger, This is used to decouple Logging framework dependency + * + * @author Frank Zhang + * @date 2020-02-11 11:08 AM + */ +public class Debugger { + + private static boolean isDebugOn = false; + + public static void debug(String message){ + if(isDebugOn){ + System.out.println(message); + } + } + + public static void enableDebug(){ + isDebugOn = true; + } +} diff --git a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateImpl.java b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateImpl.java index d900ec82f..30ad40984 100644 --- a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateImpl.java +++ b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateImpl.java @@ -3,7 +3,6 @@ import com.alibaba.cola.statemachine.State; import com.alibaba.cola.statemachine.Transition; import com.alibaba.cola.statemachine.Visitor; -import lombok.extern.slf4j.Slf4j; import java.util.Collection; import java.util.HashMap; @@ -15,7 +14,6 @@ * @author Frank Zhang * @date 2020-02-07 11:19 PM */ -@Slf4j public class StateImpl implements State { protected final S stateId; private HashMap> transitions = new HashMap<>(); @@ -32,7 +30,7 @@ public Transition addTransition(E event, State target, Transitio newTransition.setEvent(event); newTransition.setType(transitionType); - log.debug("Begin to add new transition: "+ newTransition); + Debugger.debug("Begin to add new transition: "+ newTransition); verify(event, newTransition); transitions.put(event, newTransition); return newTransition; diff --git a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateMachineImpl.java b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateMachineImpl.java index 4d40a8da9..a72147b82 100644 --- a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateMachineImpl.java +++ b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateMachineImpl.java @@ -4,9 +4,6 @@ import com.alibaba.cola.statemachine.StateMachine; import com.alibaba.cola.statemachine.Transition; import com.alibaba.cola.statemachine.Visitor; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; import java.util.Map; import java.util.Optional; @@ -21,16 +18,12 @@ * @author Frank Zhang * @date 2020-02-07 5:40 PM */ -@Slf4j public class StateMachineImpl implements StateMachine { - @Getter - @Setter private String machineId; private final Map> stateMap; - @Setter private boolean ready; public StateMachineImpl(Map> stateMap){ @@ -48,7 +41,7 @@ private State doTransition(State sourceState, E event, C ctx) { if(transition.isPresent()){ return transition.get().transit(ctx); } - log.warn("There is no Transition for " + event); + Debugger.debug("There is no Transition for " + event); return sourceState; } @@ -88,4 +81,16 @@ public void generatePlantUML(){ accept(plantUMLVisitor); } + @Override + public String getMachineId() { + return machineId; + } + + public void setMachineId(String machineId) { + this.machineId = machineId; + } + + public void setReady(boolean ready) { + this.ready = ready; + } } diff --git a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/TransitionImpl.java b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/TransitionImpl.java index 67a7f8f10..357299e5f 100644 --- a/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/TransitionImpl.java +++ b/cola-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/TransitionImpl.java @@ -4,7 +4,6 @@ import com.alibaba.cola.statemachine.Condition; import com.alibaba.cola.statemachine.State; import com.alibaba.cola.statemachine.Transition; -import lombok.extern.slf4j.Slf4j; /** * TransitionImpl。 @@ -14,7 +13,6 @@ * @author Frank Zhang * @date 2020-02-07 10:32 PM */ -@Slf4j public class TransitionImpl implements Transition { private State source; @@ -86,7 +84,7 @@ public void setAction(Action action) { @Override public State transit(C ctx) { - log.debug("Do transition: "+this); + Debugger.debug("Do transition: "+this); this.verify(); if(condition == null || condition.isSatisfied(ctx)){ if(action != null){ @@ -95,7 +93,7 @@ public State transit(C ctx) { return target; } - log.debug("Condition is not satisfied, stay at the "+source+" state "); + Debugger.debug("Condition is not satisfied, stay at the "+source+" state "); return source; } diff --git a/cola-statemachine/src/test/java/com/alibaba/cola/test/StateMachinePlantUMLTest.java b/cola-statemachine/src/test/java/com/alibaba/cola/test/StateMachinePlantUMLTest.java index c4b6bd0ca..ce5c7d44a 100644 --- a/cola-statemachine/src/test/java/com/alibaba/cola/test/StateMachinePlantUMLTest.java +++ b/cola-statemachine/src/test/java/com/alibaba/cola/test/StateMachinePlantUMLTest.java @@ -5,6 +5,8 @@ import com.alibaba.cola.statemachine.StateMachine; import com.alibaba.cola.statemachine.builder.StateMachineBuilder; import com.alibaba.cola.statemachine.builder.StateMachineBuilderFactory; +import com.alibaba.cola.statemachine.impl.Debugger; +import org.junit.Before; import org.junit.Test; import java.util.stream.Stream; @@ -81,6 +83,11 @@ public boolean isSystemEvent(){ } } + @Before + public void init(){ + Debugger.enableDebug(); + } + @Test public void testPlantUML(){ StateMachineBuilder builder = StateMachineBuilderFactory.create();