use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.
the class AgentEventServiceImpl method createAgentEvents.
private List<AgentEvent> createAgentEvents(List<AgentEventBo> agentEventBos, boolean includeEventMessage) {
if (CollectionUtils.isEmpty(agentEventBos)) {
return Collections.emptyList();
}
List<AgentEvent> agentEvents = new ArrayList<>(agentEventBos.size());
PriorityQueue<DurationalAgentEvent> durationalAgentEvents = new PriorityQueue<>(agentEventBos.size(), AgentEvent.EVENT_TIMESTAMP_ASC_COMPARATOR);
for (AgentEventBo agentEventBo : agentEventBos) {
if (agentEventBo.getEventType().isCategorizedAs(AgentEventTypeCategory.DURATIONAL)) {
durationalAgentEvents.add(createDurationalAgentEvent(agentEventBo, includeEventMessage));
} else {
agentEvents.add(createAgentEvent(agentEventBo, includeEventMessage));
}
}
long durationStartTimestamp = DurationalAgentEvent.UNKNOWN_TIMESTAMP;
while (!durationalAgentEvents.isEmpty()) {
DurationalAgentEvent currentEvent = durationalAgentEvents.remove();
if (durationStartTimestamp == DurationalAgentEvent.UNKNOWN_TIMESTAMP) {
durationStartTimestamp = currentEvent.getEventTimestamp();
}
currentEvent.setDurationStartTimestamp(durationStartTimestamp);
DurationalAgentEvent nextEvent = durationalAgentEvents.peek();
if (nextEvent != null) {
long nextEventTimestamp = nextEvent.getEventTimestamp();
currentEvent.setDurationEndTimestamp(nextEventTimestamp);
durationStartTimestamp = nextEventTimestamp;
}
agentEvents.add(currentEvent);
}
return agentEvents;
}
use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.
the class AgentEventServiceImpl method getAgentEvent.
@Override
public AgentEvent getAgentEvent(String agentId, long eventTimestamp, int eventTypeCode) {
if (agentId == null) {
throw new NullPointerException("agentId must not be null");
}
if (eventTimestamp < 0) {
throw new IllegalArgumentException("eventTimeTimestamp must not be less than 0");
}
final AgentEventType eventType = AgentEventType.getTypeByCode(eventTypeCode);
if (eventType == null) {
throw new IllegalArgumentException("invalid eventTypeCode [" + eventTypeCode + "]");
}
final boolean includeEventMessage = true;
AgentEventBo agentEventBo = this.agentEventDao.getAgentEvent(agentId, eventTimestamp, eventType);
if (agentEventBo != null) {
return createAgentEvent(agentEventBo, includeEventMessage);
}
return null;
}
use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.
the class AgentEventServiceImpl method getAgentEvents.
@Override
public List<AgentEvent> getAgentEvents(String agentId, Range range, int... excludeEventTypeCodes) {
if (agentId == null) {
throw new NullPointerException("agentId must not be null");
}
final boolean includeEventMessage = false;
Set<AgentEventType> excludeEventTypes = EnumSet.noneOf(AgentEventType.class);
for (int excludeEventTypeCode : excludeEventTypeCodes) {
AgentEventType excludeEventType = AgentEventType.getTypeByCode(excludeEventTypeCode);
if (excludeEventType != null) {
excludeEventTypes.add(excludeEventType);
}
}
List<AgentEventBo> agentEventBos = this.agentEventDao.getAgentEvents(agentId, range, excludeEventTypes);
List<AgentEvent> agentEvents = createAgentEvents(agentEventBos, includeEventMessage);
Collections.sort(agentEvents, AgentEvent.EVENT_TIMESTAMP_ASC_COMPARATOR);
return agentEvents;
}
use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.
the class AgentEventHandlerTest method handler_should_handle_events_with_empty_message_body.
@Test
public void handler_should_handle_events_with_empty_message_body() throws Exception {
// given
final AgentEventType expectedEventType = AgentEventType.AGENT_CONNECTED;
ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
// when
this.agentEventHandler.handleEvent(this.pinpointServer, TEST_EVENT_TIMESTAMP, expectedEventType);
verify(this.agentEventDao, times(1)).insert(argCaptor.capture());
// then
AgentEventBo actualAgentEventBo = argCaptor.getValue();
assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
assertEquals(expectedEventType, actualAgentEventBo.getEventType());
assertNull(actualAgentEventBo.getEventBody());
}
use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.
the class AgentEventHandlerTest method handler_should_handle_serialization_of_messages_appropriately.
@Test
public void handler_should_handle_serialization_of_messages_appropriately() throws Exception {
// given
final AgentEventType expectedEventType = AgentEventType.OTHER;
final String expectedMessageBody = "test event message";
final byte[] expectedMessageBodyBytes = BytesUtils.toBytes(expectedMessageBody);
ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
when(this.agentEventMessageSerializer.serialize(expectedEventType, expectedMessageBody)).thenReturn(expectedMessageBodyBytes);
// when
this.agentEventHandler.handleEvent(this.pinpointServer, TEST_EVENT_TIMESTAMP, expectedEventType, expectedMessageBody);
verify(this.agentEventDao, times(1)).insert(argCaptor.capture());
// then
AgentEventBo actualAgentEventBo = argCaptor.getValue();
assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
assertEquals(expectedEventType, actualAgentEventBo.getEventType());
assertEquals(expectedMessageBodyBytes, actualAgentEventBo.getEventBody());
}
Aggregations