Search in sources :

Example 1 with ClientGroupWrapper

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);
            }
        }
    }
}
Also used : ClientGroupWrapper(org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper) OutputStream(java.io.OutputStream) UserAgent(org.apache.eventmesh.common.protocol.tcp.UserAgent) ClientSessionGroupMapping(org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping) IOException(java.io.IOException) IOException(java.io.IOException) Session(org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 UserAgent (org.apache.eventmesh.common.protocol.tcp.UserAgent)1 ClientGroupWrapper (org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper)1 ClientSessionGroupMapping (org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping)1 Session (org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session)1