From 39c8293477bc4ac35a7d1cbc500dd573b9b19c18 Mon Sep 17 00:00:00 2001 From: scwlkq <89067331+scwlkq@users.noreply.github.com> Date: Sat, 20 Jan 2024 21:45:27 +0800 Subject: [PATCH] [ISSUE #4095] Code Optimization and Interrupeted Exception handling.[EtcdCustomService] (#4752) * Enhance thread handling of InterruptedException * inline variable * check code style * catch InterruptedException in a separate catch code block --- .../meta/etcd/service/EtcdCustomService.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/eventmesh-meta/eventmesh-meta-etcd/src/main/java/org/apache/eventmesh/meta/etcd/service/EtcdCustomService.java b/eventmesh-meta/eventmesh-meta-etcd/src/main/java/org/apache/eventmesh/meta/etcd/service/EtcdCustomService.java index 23ca9985bc..11460cc684 100644 --- a/eventmesh-meta/eventmesh-meta-etcd/src/main/java/org/apache/eventmesh/meta/etcd/service/EtcdCustomService.java +++ b/eventmesh-meta/eventmesh-meta-etcd/src/main/java/org/apache/eventmesh/meta/etcd/service/EtcdCustomService.java @@ -66,6 +66,9 @@ public List findEventMeshServicePubTopicInfos() th } return eventMeshServicePubTopicInfoList; } + } catch (InterruptedException e) { + log.error("[EtcdRegistryService][findEventMeshServicePubTopicInfos] InterruptedException", e); + Thread.currentThread().interrupt(); } catch (Exception e) { log.error("[EtcdRegistryService][findEventMeshServicePubTopicInfos] error", e); throw new MetaException(e.getMessage()); @@ -84,12 +87,13 @@ public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String group GetOption getOption = GetOption.newBuilder().withPrefix(keyByteSequence).build(); keyValues = client.getKVClient().get(keyByteSequence, getOption).get().getKvs(); if (CollectionUtils.isNotEmpty(keyValues)) { - EventMeshAppSubTopicInfo eventMeshAppSubTopicInfo = - JsonUtils.parseObject( - new String(keyValues.get(0).getValue().getBytes(), Constants.DEFAULT_CHARSET), - EventMeshAppSubTopicInfo.class); - return eventMeshAppSubTopicInfo; + return JsonUtils.parseObject( + new String(keyValues.get(0).getValue().getBytes(), Constants.DEFAULT_CHARSET), + EventMeshAppSubTopicInfo.class); } + } catch (InterruptedException e) { + log.error("[EtcdRegistryService][findEventMeshAppSubTopicInfoByGroup] InterruptedException", e); + Thread.currentThread().interrupt(); } catch (Exception e) { log.error("[EtcdRegistryService][findEventMeshAppSubTopicInfoByGroup] error, group: {}", group, e); throw new MetaException(e.getMessage());