use of oap.zabbix.Request in project oap by oaplatform.
the class ZabbixAppender method dispatchEvents.
private void dispatchEvents() throws InterruptedException, IOException {
ILoggingEvent event = deque.takeFirst();
val events = new ArrayList<ILoggingEvent>();
events.add(event);
val list = new ArrayList<Data>();
addEvent(event, list);
while ((event = deque.pollFirst()) != null) {
events.add(event);
addEvent(event, list);
}
val request = new Request(list);
try {
if (!socketConnectionCouldBeEstablished()) {
throw new ConnectException();
}
addInfo(peerId + "connection established");
val outputStream = socket.getOutputStream();
val inputStream = socket.getInputStream();
addInfo("zabbixRequest = " + request);
ZabbixRequest.writeExternal(request, outputStream);
outputStream.flush();
val buf = new byte[1024];
val responseBaos = new ByteArrayOutputStream();
while (true) {
int read = inputStream.read(buf);
if (read <= 0) {
break;
}
responseBaos.write(buf, 0, read);
}
val bResponse = responseBaos.toByteArray();
if (bResponse.length < 13) {
addInfo("response.length < 13");
} else {
String jsonString = new String(bResponse, 13, bResponse.length - 13, StandardCharsets.UTF_8);
addInfo("response = " + jsonString);
}
} catch (IOException e) {
tryReAddingEventsToFrontOfQueue(events);
throw e;
} finally {
CloseUtil.closeQuietly(socket);
socket = null;
addInfo(peerId + "connection closed");
}
}
Aggregations