Skip to content

Commit

Permalink
[ISSUE #2255] simplify the code (#2259)
Browse files Browse the repository at this point in the history
* simplify the code

* format code
  • Loading branch information
weihubeats authored Nov 27, 2022
1 parent b318fbc commit dd2a9e9
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

public class PubClientImpl extends TCPClient implements PubClient {

private Logger publogger = LoggerFactory.getLogger(this.getClass());
private final Logger publogger = LoggerFactory.getLogger(this.getClass());

private UserAgent userAgent;
private final UserAgent userAgent;

private ReceiveMsgHook callback;

Expand Down Expand Up @@ -79,19 +79,16 @@ public void close() {
}

public void heartbeat() throws Exception {
task = scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
if (!isActive()) {
PubClientImpl.this.reconnect();
}
Package msg = MessageUtils.heartBeat();
publogger.debug("PubClientImpl|{}|send heartbeat|Command={}|msg={}", clientNo, msg.getHeader().getCommand(), msg);
PubClientImpl.this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS);
} catch (Exception e) {
//ignore
task = scheduler.scheduleAtFixedRate(() -> {
try {
if (!isActive()) {
PubClientImpl.this.reconnect();
}
Package msg = MessageUtils.heartBeat();
publogger.debug("PubClientImpl|{}|send heartbeat|Command={}|msg={}", clientNo, msg.getHeader().getCommand(), msg);
PubClientImpl.this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS);
} catch (Exception e) {
//ignore
}
}, ClientConstants.HEARTBEAT, ClientConstants.HEARTBEAT, TimeUnit.MILLISECONDS);
}
Expand All @@ -116,7 +113,7 @@ private void hello() throws Exception {
*/
@Override
public Package rr(Package msg, long timeout) throws Exception {
publogger.info("PubClientImpl|{}|rr|send|Command={}|msg={}", clientNo, msg.getHeader().getCommand().REQUEST_TO_SERVER, msg);
publogger.info("PubClientImpl|{}|rr|send|Command={}|msg={}", clientNo, Command.REQUEST_TO_SERVER, msg);
return dispatcher(msg, timeout);
}

Expand Down

0 comments on commit dd2a9e9

Please sign in to comment.