Skip to content

Commit

Permalink
Release version 1.0.0 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron authored Nov 8, 2024
1 parent 9d219f9 commit c76fbc2
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 201 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Maven Publish
on:
release:
types: [created]
types: [ created ]
jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -15,8 +15,14 @@ jobs:
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD

- name: Install GPG secret key
run: |
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
gpg --list-secret-keys --keyid-format LONG
- name: Publish package
run: mvn --batch-mode deploy
run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} clean deploy -P release
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.digitalpetri.fsm</groupId>
<artifactId>strict-machine</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0</version>

<name>Strict Machine</name>
<description>
Expand Down Expand Up @@ -44,6 +44,9 @@
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Dependencies -->
<slf4j.version>2.0.16</slf4j.version>

<!-- Test Dependencies -->
<junit.version>5.10.2</junit.version>

Expand All @@ -54,6 +57,12 @@
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/digitalpetri/fsm/FsmContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public interface FsmContext<S, E> {
*
* @return the user-configurable context associated with this FSM instance.
*/
Object getContext();
Object getUserContext();

final class Key<T> {

Expand Down
64 changes: 0 additions & 64 deletions src/main/java/com/digitalpetri/fsm/FsmLogging.java

This file was deleted.

104 changes: 0 additions & 104 deletions src/main/java/com/digitalpetri/fsm/Log.java

This file was deleted.

82 changes: 58 additions & 24 deletions src/main/java/com/digitalpetri/fsm/StrictMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package com.digitalpetri.fsm;

import com.digitalpetri.fsm.FsmLogging.Level;
import com.digitalpetri.fsm.dsl.ActionContext;
import com.digitalpetri.fsm.dsl.ActionProxy;
import com.digitalpetri.fsm.dsl.Transition;
Expand All @@ -26,6 +25,9 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Consumer;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class StrictMachine<S, E> implements Fsm<S, E> {

Expand All @@ -38,23 +40,29 @@ public class StrictMachine<S, E> implements Fsm<S, E> {
private final Map<FsmContext.Key<?>, Object> contextValues = new ConcurrentHashMap<>();
private final AtomicReference<S> state = new AtomicReference<>();

private final Object context;
private final Logger logger;
private final Map<String, String> mdc;
private final Executor executor;
private final Object userContext;
private final ActionProxy<S, E> actionProxy;
private final List<Transition<S, E>> transitions;
private final List<TransitionAction<S, E>> transitionActions;

public StrictMachine(
Object context,
String loggerName,
Map<String, String> mdc,
Executor executor,
Object userContext,
ActionProxy<S, E> actionProxy,
S initialState,
List<Transition<S, E>> transitions,
List<TransitionAction<S, E>> transitionActions
) {

this.context = context;
this.logger = LoggerFactory.getLogger(loggerName);
this.mdc = mdc;
this.executor = executor;
this.userContext = userContext;
this.actionProxy = actionProxy;
this.transitions = transitions;
this.transitionActions = transitionActions;
Expand Down Expand Up @@ -171,14 +179,18 @@ public void run() {

state.set(nextState);

if (Log.isLevelEnabled(Level.DEBUG)) {
Log.debug(
context,
"%s x %s = %s",
padRight(String.format("S(%s)", currState)),
padRight(String.format("E(%s)", event)),
padRight(String.format("S'(%s)", nextState))
);
if (logger.isDebugEnabled()) {
mdc.forEach(MDC::put);
try {
logger.debug(
"{} x {} = {}",
padRight(String.format("S(%s)", currState)),
padRight(String.format("E(%s)", event)),
padRight(String.format("S'(%s)", nextState))
);
} finally {
mdc.keySet().forEach(MDC::remove);
}
}

var actionContext = new ActionContextImpl(
Expand All @@ -195,27 +207,49 @@ public void run() {
}
}

Log.trace(context, "found %d matching TransitionActions", matchingActions.size());
if (logger.isTraceEnabled()) {
mdc.forEach(MDC::put);
try {
logger.trace("found {} matching TransitionActions", matchingActions.size());
} finally {
mdc.keySet().forEach(MDC::remove);
}
}

matchingActions.forEach(transitionAction -> {
try {
if (actionProxy == null) {
Log.trace(context, "executing TransitionAction: %s", transitionAction);
if (logger.isTraceEnabled()) {
mdc.forEach(MDC::put);
try {
logger.trace("executing TransitionAction: {}", transitionAction);
} finally {
mdc.keySet().forEach(MDC::remove);
}
}

transitionAction.execute(actionContext);
} else {
Log.trace(
context,
"executing (via proxy) TransitionAction: %s", transitionAction
);
if (logger.isTraceEnabled()) {
mdc.forEach(MDC::put);
try {
logger.trace("executing (via proxy) TransitionAction: {}", transitionAction);
} finally {
mdc.keySet().forEach(MDC::remove);
}
}

actionProxy.execute(actionContext, transitionAction::execute);
}
} catch (Throwable ex) {
Log.warn(
context,
"Uncaught Throwable executing TransitionAction: %s\n%s", transitionAction, ex
);

mdc.forEach(MDC::put);
try {
logger.warn("uncaught Throwable executing TransitionAction: {}",
transitionAction, ex);
} finally {
mdc.keySet().forEach(MDC::remove);
}
}
});

Expand Down Expand Up @@ -318,8 +352,8 @@ public void set(Key<?> key, Object value) {
}

@Override
public Object getContext() {
return context;
public Object getUserContext() {
return userContext;
}

}
Expand Down
Loading

0 comments on commit c76fbc2

Please sign in to comment.