private static void checkForCycles(Object value, Deque<Object> objectStack) throws InvalidEventException { for (Object o : objectStack) { if (value == o) { List<Object> path = Lists.reverse(Lists.newArrayList(objectStack)); throw new InvalidEventException("Cycle detected in event data: %s", path); } } } }
private static void checkForCycles(Object value, Deque<Object> objectStack) throws InvalidEventException { for (Object o : objectStack) { if (value == o) { List<Object> path = Lists.reverse(Lists.newArrayList(objectStack)); throw new InvalidEventException("Cycle detected in event data: %s", path); } } } }
private Object getValue(Object event) throws InvalidEventException { try { return method.invoke(event); } catch (Exception e) { throw new InvalidEventException(firstNonNull(e.getCause(), e), "Unable to get value of event field %s: Exception occurred while invoking [%s]", name, method.toGenericString()); } }
private Object getValue(Object event) throws InvalidEventException { try { return method.invoke(event); } catch (Exception e) { throw new InvalidEventException(firstNonNull(e.getCause(), e), "Unable to get value of event field %s: Exception occurred while invoking [%s]", name, method.toGenericString()); } }
public <T> void serialize(T event, @Nullable String token, JsonGenerator jsonGenerator) throws IOException { checkNotNull(event, "event is null"); checkNotNull(jsonGenerator, "jsonGenerator is null"); JsonSerializer<T> serializer = getSerializer(event, token); if (serializer == null) { throw new InvalidEventException("Event class [%s] has not been registered as an event", event.getClass().getName()); } serializer.serialize(event, jsonGenerator, null); }
public <T> void serialize(T event, @Nullable TraceToken token, JsonGenerator jsonGenerator) throws IOException { requireNonNull(event, "event is null"); requireNonNull(jsonGenerator, "jsonGenerator is null"); JsonSerializer<T> serializer = getSerializer(event, token); if (serializer == null) { throw new InvalidEventException("Event class [%s] has not been registered as an event", event.getClass().getName()); } serializer.serialize(event, jsonGenerator, null); }
<T> Writer createEventWriter(final Iterator<T> eventIterator, final TraceToken token, final OutputStream out) throws IOException { requireNonNull(eventIterator, "eventIterator is null"); requireNonNull(out, "out is null"); JsonGenerator jsonGenerator = jsonFactory.createGenerator(out, JsonEncoding.UTF8); jsonGenerator.writeStartArray(); return () -> { if (eventIterator.hasNext()) { T event = eventIterator.next(); JsonSerializer<T> serializer = getSerializer(event, token); if (serializer == null) { throw new InvalidEventException("Event class [%s] has not been registered as an event", event.getClass().getName()); } serializer.serialize(event, jsonGenerator, null); } else { jsonGenerator.writeEndArray(); jsonGenerator.flush(); out.close(); } }; }