use of org.apache.thrift.TException in project pinpoint by naver.
the class AgentCommandController method getActiveThreadLightDump.
@RequestMapping(value = "/activeThreadLightDump", method = RequestMethod.GET)
public ModelAndView getActiveThreadLightDump(@RequestParam(value = "applicationName") String applicationName, @RequestParam(value = "agentId") String agentId, @RequestParam(value = "limit", required = false, defaultValue = "-1") int limit, @RequestParam(value = "threadName", required = false) String[] threadNameList, @RequestParam(value = "localTraceId", required = false) Long[] localTraceIdList) throws TException {
if (!webProperties.isEnableActiveThreadDump()) {
return createResponse(false, "Disable activeThreadDump option. 'config.enable.activeThreadDump=false'");
}
AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId);
if (agentInfo == null) {
return createResponse(false, String.format("Can't find suitable Agent(%s/%s)", applicationName, agentId));
}
TCmdActiveThreadLightDump threadDump = new TCmdActiveThreadLightDump();
if (limit > 0) {
threadDump.setLimit(limit);
}
if (threadNameList != null) {
threadDump.setThreadNameList(Arrays.asList(threadNameList));
}
if (localTraceIdList != null) {
threadDump.setLocalTraceIdList(Arrays.asList(localTraceIdList));
}
try {
PinpointRouteResponse pinpointRouteResponse = agentService.invoke(agentInfo, threadDump);
if (isSuccessResponse(pinpointRouteResponse)) {
TBase<?, ?> result = pinpointRouteResponse.getResponse();
if (result instanceof TCmdActiveThreadLightDumpRes) {
TCmdActiveThreadLightDumpRes activeThreadDumpResponse = (TCmdActiveThreadLightDumpRes) result;
List<TActiveThreadLightDump> activeThreadDumps = activeThreadDumpResponse.getThreadDumps();
AgentActiveThreadDumpFactory factory = new AgentActiveThreadDumpFactory();
AgentActiveThreadDumpList activeThreadDumpList = factory.create2(activeThreadDumps);
Map<String, Object> responseData = createResponseData(activeThreadDumpList, activeThreadDumpResponse.getType(), activeThreadDumpResponse.getSubType(), activeThreadDumpResponse.getVersion());
return createResponse(true, responseData);
}
}
return handleFailedResponse(pinpointRouteResponse);
} catch (TException e) {
return createResponse(false, e.getMessage());
}
}
use of org.apache.thrift.TException in project pinpoint by naver.
the class SpanStreamSendDataPlaner method getSpanChunkBuffer0.
private byte[] getSpanChunkBuffer0() {
if (spanChunkBuffer == null) {
final TSpanChunk spanChunk = toSpanChunk(span);
HeaderTBaseSerializer serializer = new HeaderTBaseSerializerFactory(false, SpanStreamSendDataFactory.DEFAULT_UDP_MAX_BUFFER_SIZE, false).createSerializer();
byte[] spanChunkBuffer;
try {
spanChunkBuffer = serializer.serialize(spanChunk);
this.spanChunkBuffer = spanChunkBuffer;
this.spanChunkSize = serializer.getInterBufferSize();
} catch (TException e) {
logger.warn("Spanchunk serializer failed. {}.", spanChunk);
}
}
if (spanChunkBuffer == null) {
return new byte[0];
}
return spanChunkBuffer;
}
use of org.apache.thrift.TException in project pinpoint by naver.
the class BufferedUdpDataSender method startScheduledFlush.
private Thread startScheduledFlush() {
final ThreadFactory threadFactory = new PinpointThreadFactory(SCHEDULED_FLUSH, true);
final Thread thread = threadFactory.newThread(new Runnable() {
@Override
public void run() {
final Thread currentThread = Thread.currentThread();
while (!currentThread.isInterrupted()) {
try {
chunkHeaderBufferedSerializer.flush();
} catch (TException e) {
logger.warn("Failed to flush. caused={}", e.getMessage(), e);
}
try {
TimeUnit.MILLISECONDS.sleep(1000);
} catch (InterruptedException ignored) {
currentThread.interrupt();
}
}
logger.info("stop ScheduledFlush {} - {}", currentThread.getName(), currentThread.getId());
}
});
logger.info("stop ScheduledFlush {} - {}", thread.getName(), thread.getId());
thread.start();
return thread;
}
use of org.apache.thrift.TException in project pinpoint by naver.
the class ActiveThreadCountWorker method active0.
private boolean active0(AgentInfo agentInfo) {
synchronized (lock) {
boolean active = false;
try {
ClientStreamChannelContext clientStreamChannelContext = agentService.openStream(agentInfo, COMMAND_INSTANCE, messageListener, stateChangeListener);
if (clientStreamChannelContext == null) {
setDefaultErrorMessage(StreamCode.CONNECTION_NOT_FOUND.name());
workerActiveManager.addReactiveWorker(agentInfo);
} else {
if (clientStreamChannelContext.getCreateFailPacket() == null) {
streamChannel = clientStreamChannelContext.getStreamChannel();
setDefaultErrorMessage(TRouteResult.TIMEOUT.name());
active = true;
} else {
StreamCreateFailPacket createFailPacket = clientStreamChannelContext.getCreateFailPacket();
setDefaultErrorMessage(createFailPacket.getCode().name());
}
}
} catch (TException exception) {
setDefaultErrorMessage(TRouteResult.NOT_SUPPORTED_REQUEST.name());
}
return active;
}
}
use of org.apache.thrift.TException in project druid by druid-io.
the class ThriftDeserialization method detectAndDeserialize.
/**
* Deserializes byte-array into thrift object.
* <p>
* Supporting binary, compact and json protocols,
* and the byte array could be or not be encoded by Base64.
*
* @param bytes the byte-array to deserialize
* @param thriftObj the output thrift object
*
* @return the output thrift object, or null if error occurs
*/
public static <T extends TBase> T detectAndDeserialize(final byte[] bytes, final T thriftObj) throws TException {
Preconditions.checkNotNull(thriftObj);
try {
final byte[] src = decodeB64IfNeeded(bytes);
final TProtocolFactory protocolFactory = TProtocolUtil.guessProtocolFactory(src, null);
Preconditions.checkNotNull(protocolFactory);
if (protocolFactory instanceof TCompactProtocol.Factory) {
DESERIALIZER_COMPACT.get().deserialize(thriftObj, src);
} else if (protocolFactory instanceof TBinaryProtocol.Factory) {
DESERIALIZER_BINARY.get().deserialize(thriftObj, src);
} else {
DESERIALIZER_JSON.get().deserialize(thriftObj, src);
}
} catch (final IllegalArgumentException e) {
throw new TException(e);
}
return thriftObj;
}
Aggregations