use of org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper in project incubator-eventmesh by apache.
the class ShowListenClientByTopicHandler method handle.
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String result = "";
OutputStream out = httpExchange.getResponseBody();
try {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo = NetUtils.formData2Dic(queryString);
String topic = queryStringInfo.get(EventMeshConstants.MANAGE_TOPIC);
String newLine = System.getProperty("line.separator");
logger.info("showListeningClientByTopic,topic:{}=================", topic);
ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<String, ClientGroupWrapper> clientGroupMap = clientSessionGroupMapping.getClientGroupMap();
if (!clientGroupMap.isEmpty()) {
for (ClientGroupWrapper cgw : clientGroupMap.values()) {
Set<Session> listenSessionSet = cgw.getTopic2sessionInGroupMapping().get(topic);
if (listenSessionSet != null && listenSessionSet.size() > 0) {
result += String.format("group:%s", cgw.getGroup()) + newLine;
for (Session session : listenSessionSet) {
UserAgent userAgent = session.getClient();
result += String.format("pid=%s | ip=%s | port=%s | path=%s | version=%s", userAgent.getPid(), userAgent.getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getVersion()) + newLine;
}
}
}
}
httpExchange.sendResponseHeaders(200, 0);
out.write(result.getBytes());
} catch (Exception e) {
logger.error("ShowListenClientByTopicHandler fail...", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
logger.warn("out close failed...", e);
}
}
}
}
Aggregations