You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by jo...@apache.org on 2022/12/11 14:19:41 UTC
[incubator-eventmesh] branch master updated: [ISSUE #2545] refactor String concatenation '+=' in loop (#2554)
This is an automated email from the ASF dual-hosted git repository.
jonyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 85d7d10aa [ISSUE #2545] refactor String concatenation '+=' in loop (#2554)
85d7d10aa is described below
commit 85d7d10aa26e91f1438550e127d9b4274b9cf2b3
Author: jonyangx <ya...@gmail.com>
AuthorDate: Sun Dec 11 22:19:36 2022 +0800
[ISSUE #2545] refactor String concatenation '+=' in loop (#2554)
* fix issue2545
* fix issue2545
* delete redundant code
---
.../admin/handler/ShowClientBySystemHandler.java | 31 +++++++++-------------
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
index 9b73f9411..8163a4f80 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
@@ -41,7 +41,7 @@ import com.sun.net.httpserver.HttpExchange;
@EventHttpHandler(path = "/clientManage/showClientBySystem")
public class ShowClientBySystemHandler extends AbstractHttpHandler {
- private static final Logger logger = LoggerFactory.getLogger(ShowClientBySystemHandler.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ShowClientBySystemHandler.class);
private final EventMeshTCPServer eventMeshTCPServer;
@@ -58,38 +58,31 @@ public class ShowClientBySystemHandler extends AbstractHttpHandler {
*/
@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));
- } catch (Exception e) {
- logger.error("ShowClientBySystemAndHandler fail...", e);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- logger.warn("out close failed...", e);
- }
- }
+ out.write(result.toString().getBytes(Constants.DEFAULT_CHARSET));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org