Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return correct name of action #1131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/
package org.springframework.statemachine.boot.support;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void transition(StateMachine<S, E> stateMachine, Transition<S, E> transit

@Override
public void action(StateMachine<S, E> stateMachine, Function<StateContext<S, E>, Mono<Void>> action, long duration) {
String actionName = actionFunctionToName(action);
String actionName = actionToName(action);
getActionCounterBuilder(action).register(meterRegistry).increment();
getActionTimerBuilder(action).register(meterRegistry).record(duration, TimeUnit.MILLISECONDS);
Map<String, Object> traceInfo = new HashMap<>();
Expand Down Expand Up @@ -135,11 +136,14 @@ private static <S, E> String transitionToName(Transition<S, E> transition) {
}

private static <S, E> String actionToName(Function<StateContext<S, E>, Mono<Void>> action) {
return ObjectUtils.getDisplayString(action);
}

private static <S, E> String actionFunctionToName(Function<StateContext<S, E>, Mono<Void>> action) {
return ObjectUtils.getDisplayString(action);
try {
Field[] fields = action.getClass().getDeclaredFields();
Field actionField = fields[0];
actionField.setAccessible(true);
return actionField.get(action).getClass().getSimpleName();
} catch (IllegalAccessException ex) {
return ObjectUtils.getDisplayString(action);
}
}

private static <S, E> String nullStateId(State<S, E> state) {
Expand Down