apache / apache/incubator-seata-samples

Why does `BusinessService` call non-public Java API to perform health check?

Open
#685 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.4k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

## Why you need it?
Is your feature request related to a problem? Please describe in details

- I noticed that `org.apache.seata.api.BusinessService` was calling a non-public Java API to do health checks. Refer to https://github.com/apache/incubator-seata-samples/blob/3ae0a30e94ccb76eabf8ffc15863dbfa29bda598/at-sample/at-api/src/main/java/org/apache/seata/api/BusinessService.java .

```java
import io.seata.core.exception.TransactionException;
import io.seata.core.rpc.netty.RmNettyRemotingClient;
import io.seata.rm.RMClient;
import io.seata.tm.TMClient;
import io.seata.tm.api.GlobalTransaction;
import io.seata.tm.api.GlobalTransactionContext;
import org.apache.seata.api.service.OrderService;
import org.apache.seata.api.service.impl.AccountServiceImpl;
import org.apache.seata.api.service.impl.OrderServiceImpl;
import org.apache.seata.api.service.impl.StorageServiceImpl;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;

RmNettyRemotingClient rmNettyRemotingClient = RmNettyRemotingClient.getInstance();
Class rmRemoteClass = rmNettyRemotingClient.getClass();
ReflectionUtils.doWithFields(rmRemoteClass, field -> {
if (field.getName().equals("clientChannelManager")) {
field.setAccessible(true);
//channelManger
Object o = field.get(rmNettyRemotingClient);
Method reconnect;
try {
reconnect = o.getClass().getDeclaredMethod("reconnect", String.class);
reconnect.setAccessible(true);
reconnect.invoke(o, "my_test_tx_group");
} catch (Exception e) {
throw new RuntimeException("reconnect failed!", e);
}
}
});
```
- To do a health check, it is very strange to have to use reflection.

## How it could be?
A clear and concise description of what you want to happen. You can explain more about input of the feature, and output of it.

- No sure. Maybe expose the relevant API on the seata client side?

## Other related information
Add any other context or screenshots about the feature request here.

- Null.

Contributor guide

Open the contributing guide

Research direction

Start with at-sample/at-api/src/main/java/org/apache/seata/api/BusinessService.java and trace the RmNettyRemotingClient and reflective clientChannelManager calls shown there. Determine the supported public API for the health check or reconnect behavior; done means BusinessService no longer requires reflective access and the intended behavior is documented by the sample.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.