This is an automated email from the ASF dual-hosted git repository.
mxsm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 47203c745 [ISSUE #3516] Do some code optimization.[SubClientImpl]
(#4480)
47203c745 is described below
commit 47203c7457f500146fd121f2c6d4fb0e0abd835e
Author: yanrongzhen <[email protected]>
AuthorDate: Wed Oct 11 16:15:54 2023 +0800
[ISSUE #3516] Do some code optimization.[SubClientImpl] (#4480)
* Do some code optimizations.
* optimize assert logic
* Optimize assertion.
---
.../runtime/client/impl/SubClientImpl.java | 48 ++++++++++------------
1 file changed, 21 insertions(+), 27 deletions(-)
diff --git
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java
index ef79a066b..bd37aed1f 100644
---
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java
+++
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java
@@ -49,11 +49,11 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SubClientImpl extends TCPClient implements SubClient {
- private transient UserAgent userAgent;
+ private final transient UserAgent userAgent;
private transient ReceiveMsgHook callback;
- private transient List<SubscriptionItem> subscriptionItems = new
ArrayList<SubscriptionItem>();
+ private final transient List<SubscriptionItem> subscriptionItems = new
ArrayList<SubscriptionItem>();
private transient ScheduledFuture<?> task;
@@ -96,23 +96,19 @@ public class SubClientImpl extends TCPClient implements
SubClient {
}
public void heartbeat() throws Exception {
- task = scheduler.scheduleAtFixedRate(new Runnable() {
-
- @Override
- public void run() {
- try {
- if (!isActive()) {
- SubClientImpl.this.reconnect();
- }
- Package msg = MessageUtils.heartBeat();
- if (log.isDebugEnabled()) {
- log.debug("SubClientImpl|{}|send
heartbeat|Command={}|msg={}", clientNo,
- msg.getHeader().getCommand(), msg);
- }
- SubClientImpl.this.dispatcher(msg,
ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS);
- } catch (Exception e) {
- // ignore
+ task = scheduler.scheduleAtFixedRate(() -> {
+ try {
+ if (!isActive()) {
+ SubClientImpl.this.reconnect();
}
+ Package msg = MessageUtils.heartBeat();
+ if (log.isDebugEnabled()) {
+ log.debug("SubClientImpl|{}|send
heartbeat|Command={}|msg={}", clientNo,
+ msg.getHeader().getCommand(), msg);
+ }
+ SubClientImpl.this.dispatcher(msg,
ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS);
+ } catch (Exception e) {
+ // ignore
}
}, ClientConstants.HEARTBEAT, ClientConstants.HEARTBEAT,
TimeUnit.MILLISECONDS);
}
@@ -171,26 +167,24 @@ public class SubClientImpl extends TCPClient implements
SubClient {
Package response = super.io(request, timeout);
switch (request.getHeader().getCommand()) {
case HELLO_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.HELLO_RESPONSE);
+ Assertions.assertEquals(Command.HELLO_RESPONSE,
response.getHeader().getCommand());
break;
case HEARTBEAT_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.HEARTBEAT_RESPONSE);
+ Assertions.assertEquals(Command.HEARTBEAT_RESPONSE,
response.getHeader().getCommand());
break;
case LISTEN_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.LISTEN_RESPONSE);
+ Assertions.assertEquals(Command.LISTEN_RESPONSE,
response.getHeader().getCommand());
break;
case CLIENT_GOODBYE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.CLIENT_GOODBYE_RESPONSE);
+ Assertions.assertEquals(Command.CLIENT_GOODBYE_RESPONSE,
response.getHeader().getCommand());
break;
case SUBSCRIBE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.SUBSCRIBE_RESPONSE);
+ Assertions.assertEquals(Command.SUBSCRIBE_RESPONSE,
response.getHeader().getCommand());
break;
case UNSUBSCRIBE_REQUEST:
- Assertions.assertEquals(response.getHeader().getCommand(),
Command.UNSUBSCRIBE_RESPONSE);
+ Assertions.assertEquals(Command.UNSUBSCRIBE_RESPONSE,
response.getHeader().getCommand());
break;
case SYS_LOG_TO_LOGSERVER:
- Assertions.assertNull(response);
- break;
case TRACE_LOG_TO_LOGSERVER:
Assertions.assertNull(response);
break;
@@ -198,7 +192,7 @@ public class SubClientImpl extends TCPClient implements
SubClient {
break;
}
if (response != null) {
- assert response.getHeader().getCode() ==
OPStatus.SUCCESS.getCode();
+ Assertions.assertEquals(OPStatus.SUCCESS.getCode(),
response.getHeader().getCode());
}
return response;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]