From b693ff3f857b63bfe333cde5136b3fb0ab0145e5 Mon Sep 17 00:00:00 2001 From: Kirill Saied Date: Thu, 30 Mar 2023 10:37:10 +0300 Subject: [PATCH] [ISSUE #3506] Removed for loop --- .../etcd/service/EtcdCustomService.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java b/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java index 6a98ceb247..88b6f76196 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-etcd/src/main/java/org/apache/eventmesh/registry/etcd/service/EtcdCustomService.java @@ -77,34 +77,29 @@ public List findEventMeshServicePubTopicInfos() th @Nullable public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String group) throws RegistryException { - Client client = getEtcdClient(); String keyPrefix = KEY_PREFIX + KEY_APP + EtcdConstant.KEY_SEPARATOR + group; List keyValues = null; try { ByteSequence keyByteSequence = ByteSequence.from(keyPrefix.getBytes(Constants.DEFAULT_CHARSET)); - GetOption getOption = GetOption.newBuilder().withPrefix(keyByteSequence).build(); - keyValues = client.getKVClient().get(keyByteSequence, getOption).get().getKvs(); - - if (CollectionUtils.isNotEmpty(keyValues)) { - EventMeshAppSubTopicInfo eventMeshAppSubTopicInfo = null; - for (KeyValue kv : keyValues) { - eventMeshAppSubTopicInfo = JsonUtils.parseObject( - new String(kv.getValue().getBytes(), Constants.DEFAULT_CHARSET), + EventMeshAppSubTopicInfo eventMeshAppSubTopicInfo = + JsonUtils.parseObject( + new String(keyValues.get(0).getValue().getBytes(), Constants.DEFAULT_CHARSET), EventMeshAppSubTopicInfo.class ); + if (eventMeshAppSubTopicInfo != null) { + return eventMeshAppSubTopicInfo; + } else { + throw new NullPointerException("eventMeshAppSubTopicInfo is null!"); } - return eventMeshAppSubTopicInfo; } } catch (Exception e) { logger.error("[EtcdRegistryService][findEventMeshAppSubTopicInfoByGroup] error, group: {}", group, e); throw new RegistryException(e.getMessage()); } - return null; - } }