Search in sources :

Example 1 with StreamChannel

use of com.navercorp.pinpoint.rpc.stream.StreamChannel in project pinpoint by naver.

the class ActiveThreadCountResponseAggregator method registerWorkerAndConnectStream.

private StreamChannel registerWorkerAndConnectStream(AgentInfo agentInfo) {
    String agentId = agentInfo.getAgentId();
    synchronized (workerManagingLock) {
        ActiveThreadCountWorker worker = activeThreadCountWorkerRepository.get(agentId);
        if (worker == null) {
            worker = new ActiveThreadCountWorker(agentService, agentInfo, this, workerActiveManager);
            StreamChannel streamChannel = worker.connect(agentInfo);
            activeThreadCountWorkerRepository.put(agentId, worker);
            return streamChannel;
        } else {
            throw new IllegalArgumentException("Already registered agentId(" + agentId + ")");
        }
    }
}
Also used : StreamChannel(com.navercorp.pinpoint.rpc.stream.StreamChannel)

Example 2 with StreamChannel

use of com.navercorp.pinpoint.rpc.stream.StreamChannel in project pinpoint by naver.

the class ActiveThreadCountResponseAggregator method addWebSocketSession.

@Override
public void addWebSocketSession(WebSocketSession webSocketSession) {
    if (webSocketSession == null) {
        return;
    }
    logger.info("addWebSocketSession. applicationName:{}, webSocketSession:{}", applicationName, webSocketSession);
    List<AgentInfo> agentInfoList = agentService.getRecentAgentInfoList(applicationName, DEFAULT_AGENT_LOOKUP_TIME);
    synchronized (workerManagingLock) {
        if (isStopped) {
            return;
        }
        Map<AgentInfo, StreamChannel> streamChannelMap = new HashMap<>(agentInfoList.size());
        for (AgentInfo agentInfo : agentInfoList) {
            AgentStatus agentStatus = agentInfo.getStatus();
            if (agentStatus != null && agentStatus.getState() != AgentLifeCycleState.UNKNOWN) {
                StreamChannel streamChannel = registerWorkerAndConnectStream(agentInfo);
                streamChannelMap.put(agentInfo, streamChannel);
            } else if (agentService.isConnected(agentInfo)) {
                StreamChannel streamChannel = registerWorkerAndConnectStream(agentInfo);
                streamChannelMap.put(agentInfo, streamChannel);
            }
        }
        long maxAwaitTimeout = 3000;
        long currentTimeMillis = System.currentTimeMillis();
        for (Map.Entry<AgentInfo, StreamChannel> agentInfoStreamChannelEntry : streamChannelMap.entrySet()) {
            AgentInfo agentInfo = agentInfoStreamChannelEntry.getKey();
            StreamChannel streamChannel = agentInfoStreamChannelEntry.getValue();
            long diff = System.currentTimeMillis() - currentTimeMillis;
            long awaitTimeout = Math.max(maxAwaitTimeout - diff, 500);
            activeWorker(agentInfo, streamChannel, awaitTimeout);
        }
        final boolean added = webSocketSessions.add(webSocketSession);
        if (added && webSocketSessions.size() == 1) {
            workerActiveManager.startAgentCheckJob();
        }
    }
    logger.info("addWebSocketSession() completed.");
}
Also used : AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StreamChannel(com.navercorp.pinpoint.rpc.stream.StreamChannel)

Example 3 with StreamChannel

use of com.navercorp.pinpoint.rpc.stream.StreamChannel in project pinpoint by naver.

the class ActiveThreadCountResponseAggregator method activeWorker.

private void activeWorker(AgentInfo agentInfo) {
    String agentId = agentInfo.getAgentId();
    synchronized (workerManagingLock) {
        ActiveThreadCountWorker worker = activeThreadCountWorkerRepository.get(agentId);
        if (worker == null) {
            worker = new ActiveThreadCountWorker(agentService, agentInfo, this, workerActiveManager);
            StreamChannel streamChannel = worker.connect(agentInfo);
            worker.active(streamChannel, 3000);
            activeThreadCountWorkerRepository.put(agentId, worker);
        } else {
            worker.reactive(agentInfo);
        }
    }
}
Also used : StreamChannel(com.navercorp.pinpoint.rpc.stream.StreamChannel)

Example 4 with StreamChannel

use of com.navercorp.pinpoint.rpc.stream.StreamChannel in project pinpoint by naver.

the class PinpointGrpcServer method handleStreamCreateMessage.

// 2nd message : server(agent) -> client(collector)
public boolean handleStreamCreateMessage(int streamId, StreamObserver<Empty> connectionObserver) {
    if (isInfo) {
        logger.info("handleStreamCreateMessage. streamId:{}", streamId);
    }
    StreamChannel streamChannel = streamChannelRepository.getStreamChannel(streamId);
    if (streamChannel == null) {
        logger.warn("Can't find suitable streamChannel.(streamId:{})", streamId);
        return false;
    }
    GrpcClientStreamChannel grpcClientStreamChannel = (GrpcClientStreamChannel) streamChannel;
    grpcClientStreamChannel.setConnectionObserver(connectionObserver);
    return grpcClientStreamChannel.changeStateConnected();
}
Also used : ClientStreamChannel(com.navercorp.pinpoint.rpc.stream.ClientStreamChannel) StreamChannel(com.navercorp.pinpoint.rpc.stream.StreamChannel)

Example 5 with StreamChannel

use of com.navercorp.pinpoint.rpc.stream.StreamChannel in project pinpoint by naver.

the class ActiveThreadCountWorker method connect.

@Override
public StreamChannel connect(AgentInfo agentInfo) {
    if (!applicationName.equals(agentInfo.getApplicationName())) {
        return null;
    }
    if (!agentId.equals(agentInfo.getAgentId())) {
        return null;
    }
    synchronized (lock) {
        if (!started) {
            started = true;
            logger.info("ActiveThreadCountWorker start. applicationName:{}, agentId:{}", applicationName, agentId);
            StreamChannel streamChannel = null;
            try {
                streamChannel = connect0(agentInfo);
                return streamChannel;
            } catch (StreamException streamException) {
                if (streamChannel != null) {
                    streamChannel.close(streamException.getStreamCode());
                }
                StreamCode streamCode = streamException.getStreamCode();
                if (streamCode == StreamCode.CONNECTION_NOT_FOUND) {
                    workerActiveManager.addReactiveWorker(agentInfo);
                }
                setDefaultErrorMessage(streamCode.name());
            } catch (TException exception) {
                if (streamChannel != null) {
                    streamChannel.close(StreamCode.TYPE_UNKNOWN);
                }
                setDefaultErrorMessage(TRouteResult.NOT_SUPPORTED_REQUEST.name());
            }
        }
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) ClientStreamChannel(com.navercorp.pinpoint.rpc.stream.ClientStreamChannel) StreamChannel(com.navercorp.pinpoint.rpc.stream.StreamChannel) StreamCode(com.navercorp.pinpoint.rpc.packet.stream.StreamCode) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Aggregations

StreamChannel (com.navercorp.pinpoint.rpc.stream.StreamChannel)5 ClientStreamChannel (com.navercorp.pinpoint.rpc.stream.ClientStreamChannel)2 StreamCode (com.navercorp.pinpoint.rpc.packet.stream.StreamCode)1 StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)1 AgentInfo (com.navercorp.pinpoint.web.vo.AgentInfo)1 AgentStatus (com.navercorp.pinpoint.web.vo.AgentStatus)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TException (org.apache.thrift.TException)1