Skip to content

Commit

Permalink
[ISSUE apache#3506] Removed for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
PickBas committed Mar 30, 2023
1 parent c818b9a commit b693ff3
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,29 @@ public List<EventMeshServicePubTopicInfo> findEventMeshServicePubTopicInfos() th

@Nullable
public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfoByGroup(String group) throws RegistryException {

Client client = getEtcdClient();
String keyPrefix = KEY_PREFIX + KEY_APP + EtcdConstant.KEY_SEPARATOR + group;
List<KeyValue> 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;

}
}

0 comments on commit b693ff3

Please sign in to comment.