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 + ")");
}
}
}
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.");
}
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);
}
}
}
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();
}
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;
}
Aggregations