Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,36 @@
import java.io.StringWriter;
import java.util.Collection;

public class RequestEventsJsonStream {
public class HystrixRequestEventsJsonStream {
private static final JsonFactory jsonFactory = new JsonFactory();

public Observable<HystrixRequestEvents> getStream() {
return HystrixRequestEventsStream.getInstance()
.observe();
}

public static String convertToJson(Collection<HystrixRequestEvents> requests) throws IOException {
public static String convertRequestsToJson(Collection<HystrixRequestEvents> requests) throws IOException {
StringWriter jsonString = new StringWriter();
JsonGenerator json = jsonFactory.createGenerator(jsonString);

json.writeStartArray();
for (HystrixRequestEvents request : requests) {
convertRequestToJson(json, request);
writeRequestAsJson(json, request);
}
json.writeEndArray();
json.close();
return jsonString.getBuffer().toString();
}

private static void convertRequestToJson(JsonGenerator json, HystrixRequestEvents request) throws IOException {
public static String convertRequestToJson(HystrixRequestEvents request) throws IOException {
StringWriter jsonString = new StringWriter();
JsonGenerator json = jsonFactory.createGenerator(jsonString);
writeRequestAsJson(json, request);
json.close();
return jsonString.getBuffer().toString();
}

private static void writeRequestAsJson(JsonGenerator json, HystrixRequestEvents request) throws IOException {
json.writeStartObject();
json.writeStringField("request", request.getRequestContext().toString());
json.writeObjectFieldStart("commands");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public class HystrixRequestEventsSseServlet extends HttpServlet {
DynamicPropertyFactory.getInstance().getIntProperty("hystrix.requests.stream.maxConcurrentConnections", 5);

private final LinkedBlockingQueue<HystrixRequestEvents> requestQueue = new LinkedBlockingQueue<HystrixRequestEvents>(DEFAULT_QUEUE_DEPTH);
private final RequestEventsJsonStream requestEventsJsonStream;
private final HystrixRequestEventsJsonStream requestEventsJsonStream;

public HystrixRequestEventsSseServlet() {
requestEventsJsonStream = new RequestEventsJsonStream();
requestEventsJsonStream = new HystrixRequestEventsJsonStream();
}

/**
Expand Down Expand Up @@ -183,7 +183,7 @@ public void onNext(HystrixRequestEvents requestEvents) {
} else {
List<HystrixRequestEvents> l = new ArrayList<HystrixRequestEvents>();
requestQueue.drainTo(l);
String requestEventsAsStr = RequestEventsJsonStream.convertToJson(l);
String requestEventsAsStr = HystrixRequestEventsJsonStream.convertRequestsToJson(l);
if (requestEventsAsStr != null) {
try {
writer.print("data: " + requestEventsAsStr + "\n\n");
Expand Down