You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/12/11 08:43:30 UTC
[GitHub] [incubator-eventmesh] jonyangx opened a new pull request, #2554: [ISSUE #2545] refactor String concatenation '+=' in loop
jonyangx opened a new pull request, #2554:
URL: https://github.com/apache/incubator-eventmesh/pull/2554
Fixes #2545 .
### Motivation
refactor String concatenation '+=' in loop
### Modifications
refactor eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
,convert variable "result" from String to StringBuilder.
### Documentation
- Does this pull request introduce a new feature? (no)
- If yes, how is the feature documented? ( not documented)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org
[GitHub] [incubator-eventmesh] jonyangx commented on a diff in pull request #2554: [ISSUE #2545] refactor String concatenation '+=' in loop
Posted by GitBox <gi...@apache.org>.
jonyangx commented on code in PR #2554:
URL: https://github.com/apache/incubator-eventmesh/pull/2554#discussion_r1045237677
##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java:
##########
@@ -58,38 +58,33 @@ public ShowClientBySystemHandler(EventMeshTCPServer eventMeshTCPServer, HttpHand
*/
@Override
public void handle(HttpExchange httpExchange) throws IOException {
- String result = "";
- OutputStream out = httpExchange.getResponseBody();
- try {
+ StringBuffer result = new StringBuffer();
+ try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo = NetUtils.formData2Dic(queryString);
String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
String newLine = System.getProperty("line.separator");
- logger.info("showClientBySubsys,subsys:{}=================", subSystem);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("showClientBySubsys,subsys:{}", subSystem);
+ }
ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap = clientSessionGroupMapping.getSessionMap();
- if (!sessionMap.isEmpty()) {
+ if (sessionMap != null && !sessionMap.isEmpty()) {
for (Session session : sessionMap.values()) {
if (session.getClient().getSubsystem().equals(subSystem)) {
UserAgent userAgent = session.getClient();
- result += String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", userAgent.getPid(), userAgent
- .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose()) + newLine;
+ result.append(String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s",
+ userAgent.getPid(), userAgent.getHost(), userAgent.getPort(),
+ userAgent.getPath(), userAgent.getPurpose()))
+ .append(newLine);
}
}
}
NetUtils.sendSuccessResponseHeaders(httpExchange);
- out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+ out.write(result.toString().getBytes(Constants.DEFAULT_CHARSET));
} catch (Exception e) {
- logger.error("ShowClientBySystemAndHandler fail...", e);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- logger.warn("out close failed...", e);
- }
- }
+ LOGGER.error("ShowClientBySystemAndHandler fail...", e);
Review Comment:
@walterlife
I have deleted redundant code.
##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java:
##########
@@ -58,38 +58,33 @@ public ShowClientBySystemHandler(EventMeshTCPServer eventMeshTCPServer, HttpHand
*/
@Override
public void handle(HttpExchange httpExchange) throws IOException {
- String result = "";
- OutputStream out = httpExchange.getResponseBody();
- try {
+ StringBuffer result = new StringBuffer();
+ try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo = NetUtils.formData2Dic(queryString);
String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
String newLine = System.getProperty("line.separator");
- logger.info("showClientBySubsys,subsys:{}=================", subSystem);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("showClientBySubsys,subsys:{}", subSystem);
+ }
ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap = clientSessionGroupMapping.getSessionMap();
- if (!sessionMap.isEmpty()) {
+ if (sessionMap != null && !sessionMap.isEmpty()) {
for (Session session : sessionMap.values()) {
if (session.getClient().getSubsystem().equals(subSystem)) {
UserAgent userAgent = session.getClient();
- result += String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", userAgent.getPid(), userAgent
- .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose()) + newLine;
+ result.append(String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s",
+ userAgent.getPid(), userAgent.getHost(), userAgent.getPort(),
+ userAgent.getPath(), userAgent.getPurpose()))
+ .append(newLine);
}
}
}
NetUtils.sendSuccessResponseHeaders(httpExchange);
- out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+ out.write(result.toString().getBytes(Constants.DEFAULT_CHARSET));
} catch (Exception e) {
- logger.error("ShowClientBySystemAndHandler fail...", e);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- logger.warn("out close failed...", e);
- }
- }
+ LOGGER.error("ShowClientBySystemAndHandler fail...", e);
Review Comment:
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org
[GitHub] [incubator-eventmesh] walterlife commented on a diff in pull request #2554: [ISSUE #2545] refactor String concatenation '+=' in loop
Posted by GitBox <gi...@apache.org>.
walterlife commented on code in PR #2554:
URL: https://github.com/apache/incubator-eventmesh/pull/2554#discussion_r1045194603
##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java:
##########
@@ -58,38 +58,33 @@ public ShowClientBySystemHandler(EventMeshTCPServer eventMeshTCPServer, HttpHand
*/
@Override
public void handle(HttpExchange httpExchange) throws IOException {
- String result = "";
- OutputStream out = httpExchange.getResponseBody();
- try {
+ StringBuffer result = new StringBuffer();
+ try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo = NetUtils.formData2Dic(queryString);
String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
String newLine = System.getProperty("line.separator");
- logger.info("showClientBySubsys,subsys:{}=================", subSystem);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("showClientBySubsys,subsys:{}", subSystem);
+ }
ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap = clientSessionGroupMapping.getSessionMap();
- if (!sessionMap.isEmpty()) {
+ if (sessionMap != null && !sessionMap.isEmpty()) {
for (Session session : sessionMap.values()) {
if (session.getClient().getSubsystem().equals(subSystem)) {
UserAgent userAgent = session.getClient();
- result += String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", userAgent.getPid(), userAgent
- .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose()) + newLine;
+ result.append(String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s",
+ userAgent.getPid(), userAgent.getHost(), userAgent.getPort(),
+ userAgent.getPath(), userAgent.getPurpose()))
+ .append(newLine);
}
}
}
NetUtils.sendSuccessResponseHeaders(httpExchange);
- out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+ out.write(result.toString().getBytes(Constants.DEFAULT_CHARSET));
} catch (Exception e) {
- logger.error("ShowClientBySystemAndHandler fail...", e);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- logger.warn("out close failed...", e);
- }
- }
+ LOGGER.error("ShowClientBySystemAndHandler fail...", e);
Review Comment:
... what does it mean? It is recommended that the error message should be a complete sentence, and express the exception message in as much detail as possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org
[GitHub] [incubator-eventmesh] walterlife commented on a diff in pull request #2554: [ISSUE #2545] refactor String concatenation '+=' in loop
Posted by GitBox <gi...@apache.org>.
walterlife commented on code in PR #2554:
URL: https://github.com/apache/incubator-eventmesh/pull/2554#discussion_r1045194603
##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java:
##########
@@ -58,38 +58,33 @@ public ShowClientBySystemHandler(EventMeshTCPServer eventMeshTCPServer, HttpHand
*/
@Override
public void handle(HttpExchange httpExchange) throws IOException {
- String result = "";
- OutputStream out = httpExchange.getResponseBody();
- try {
+ StringBuffer result = new StringBuffer();
+ try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo = NetUtils.formData2Dic(queryString);
String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
String newLine = System.getProperty("line.separator");
- logger.info("showClientBySubsys,subsys:{}=================", subSystem);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("showClientBySubsys,subsys:{}", subSystem);
+ }
ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap = clientSessionGroupMapping.getSessionMap();
- if (!sessionMap.isEmpty()) {
+ if (sessionMap != null && !sessionMap.isEmpty()) {
for (Session session : sessionMap.values()) {
if (session.getClient().getSubsystem().equals(subSystem)) {
UserAgent userAgent = session.getClient();
- result += String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", userAgent.getPid(), userAgent
- .getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose()) + newLine;
+ result.append(String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s",
+ userAgent.getPid(), userAgent.getHost(), userAgent.getPort(),
+ userAgent.getPath(), userAgent.getPurpose()))
+ .append(newLine);
}
}
}
NetUtils.sendSuccessResponseHeaders(httpExchange);
- out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+ out.write(result.toString().getBytes(Constants.DEFAULT_CHARSET));
} catch (Exception e) {
- logger.error("ShowClientBySystemAndHandler fail...", e);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- logger.warn("out close failed...", e);
- }
- }
+ LOGGER.error("ShowClientBySystemAndHandler fail...", e);
Review Comment:
....what does it mean. It is recommended that the error message should be a complete sentence, and express the exception message in as much detail as possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org
[GitHub] [incubator-eventmesh] codecov[bot] commented on pull request #2554: [ISSUE #2545] refactor String concatenation '+=' in loop
Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #2554:
URL: https://github.com/apache/incubator-eventmesh/pull/2554#issuecomment-1345500391
# [Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#2554](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b78930f) into [master](https://codecov.io/gh/apache/incubator-eventmesh/commit/c4dd6b73bab343fe8313c2176f3b909d60ce4e0e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c4dd6b7) will **decrease** coverage by `0.02%`.
> The diff coverage is `8.33%`.
```diff
@@ Coverage Diff @@
## master #2554 +/- ##
============================================
- Coverage 11.66% 11.63% -0.03%
+ Complexity 904 900 -4
============================================
Files 469 469
Lines 27901 27895 -6
Branches 3026 3018 -8
============================================
- Hits 3254 3245 -9
- Misses 24356 24362 +6
+ Partials 291 288 -3
```
| [Impacted Files](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...ntime/admin/handler/ShowClientBySystemHandler.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvU2hvd0NsaWVudEJ5U3lzdGVtSGFuZGxlci5qYXZh) | `13.79% <8.33%> (+0.45%)` | :arrow_up: |
| [...tandalone/broker/task/HistoryMessageClearTask.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL3Rhc2svSGlzdG9yeU1lc3NhZ2VDbGVhclRhc2suamF2YQ==) | `29.41% <0.00%> (-17.65%)` | :arrow_down: |
| [...mesh/connector/standalone/broker/MessageQueue.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL01lc3NhZ2VRdWV1ZS5qYXZh) | `32.46% <0.00%> (-7.80%)` | :arrow_down: |
| [...rg/apache/eventmesh/runtime/trace/LogExporter.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL3RyYWNlL0xvZ0V4cG9ydGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...ime/admin/handler/RedirectClientByPathHandler.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUmVkaXJlY3RDbGllbnRCeVBhdGhIYW5kbGVyLmphdmE=) | `84.78% <0.00%> (ø)` | |
| [...e/admin/handler/RedirectClientByIpPortHandler.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUmVkaXJlY3RDbGllbnRCeUlwUG9ydEhhbmRsZXIuamF2YQ==) | `31.37% <0.00%> (ø)` | |
| [...l/tcp/client/recommend/EventMeshRecommendImpl.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvdGNwL2NsaWVudC9yZWNvbW1lbmQvRXZlbnRNZXNoUmVjb21tZW5kSW1wbC5qYXZh) | `0.00% <0.00%> (ø)` | |
| [.../tcp/client/session/push/DownStreamMsgContext.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvdGNwL2NsaWVudC9zZXNzaW9uL3B1c2gvRG93blN0cmVhbU1zZ0NvbnRleHQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [.../trace/pinpoint/exporter/PinpointSpanExporter.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/2554/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXRyYWNlLXBsdWdpbi9ldmVudG1lc2gtdHJhY2UtcGlucG9pbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC90cmFjZS9waW5wb2ludC9leHBvcnRlci9QaW5wb2ludFNwYW5FeHBvcnRlci5qYXZh) | `69.38% <0.00%> (+0.46%)` | :arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org
[GitHub] [incubator-eventmesh] jonyangx merged pull request #2554: [ISSUE #2545] refactor String concatenation '+=' in loop
Posted by GitBox <gi...@apache.org>.
jonyangx merged PR #2554:
URL: https://github.com/apache/incubator-eventmesh/pull/2554
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org