Skip to content

Commit

Permalink
Deprecated HystrixConfigurationJsonStream in favor of compositional s…
Browse files Browse the repository at this point in the history
…erialization
  • Loading branch information
Matt Jacobs committed Jun 22, 2016
1 parent f1bb9c9 commit bf924aa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.atomic.AtomicInteger;

/**
* Servlet that writes SSE JSON every time a request is made
*/
public class HystrixRequestEventsSseServlet extends HystrixSampleSseServlet {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.hystrix.config.HystrixConfiguration;
import com.netflix.hystrix.config.HystrixConfigurationStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.hystrix.metric.serial.SerialHystrixConfiguration;
import rx.Observable;
import rx.functions.Func1;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand All @@ -51,7 +49,6 @@
public class HystrixConfigSseServlet extends HystrixSampleSseServlet {

private static final long serialVersionUID = -3599771169762858235L;
private static final Logger logger = LoggerFactory.getLogger(HystrixConfigSseServlet.class);

/* used to track number of connections and throttle */
private static AtomicInteger concurrentConnections = new AtomicInteger(0);
Expand All @@ -65,12 +62,7 @@ public HystrixConfigSseServlet() {
super(sampleStream.map(new Func1<HystrixConfiguration, String>() {
@Override
public String call(HystrixConfiguration hystrixConfiguration) {
try {
return HystrixConfigurationJsonStream.convertToString(hystrixConfiguration);
} catch (IOException ioe) {
logger.error("IOException creating JSON from HystrixUtilization", ioe);
return "<IOException> : " + ioe.getMessage();
}
return SerialHystrixConfiguration.toJsonString(hystrixConfiguration);
}
}), pausePollerThreadDelayInMs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.netflix.hystrix.config.HystrixConfiguration;
import com.netflix.hystrix.config.HystrixConfigurationStream;
import com.netflix.hystrix.config.HystrixThreadPoolConfiguration;
import com.netflix.hystrix.metric.HystrixRequestEventsStream;
import rx.Observable;
import rx.functions.Func1;

Expand All @@ -40,7 +41,9 @@
* <li> Consumer of your choice that wants control over where to embed this stream
* </ul>
*
* @deprecated Instead, prefer mapping your preferred serialization on top of {@link HystrixConfigurationStream#observe()}.
*/
@Deprecated //since 1.5.4
public class HystrixConfigurationJsonStream {

private static final JsonFactory jsonFactory = new JsonFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -46,8 +47,34 @@ public static byte[] toBytes(HystrixConfiguration config) {

try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator json = cborFactory.createGenerator(bos);
JsonGenerator cbor = cborFactory.createGenerator(bos);

serializeConfiguration(config, cbor);

retVal = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
}

public static String toJsonString(HystrixConfiguration config) {
StringWriter jsonString = new StringWriter();

try {
JsonGenerator json = jsonFactory.createGenerator(jsonString);

serializeConfiguration(config, json);
} catch (Exception e) {
throw new RuntimeException(e);
}

return jsonString.getBuffer().toString();
}

private static void serializeConfiguration(HystrixConfiguration config, JsonGenerator json) {
try {
json.writeStartObject();
json.writeStringField("type", "HystrixConfig");
json.writeObjectFieldStart("commands");
Expand Down Expand Up @@ -76,14 +103,10 @@ public static byte[] toBytes(HystrixConfiguration config) {
json.writeEndObject();
json.writeEndObject();
json.close();


retVal = bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e);
}

return retVal;
}

public static HystrixConfiguration fromByteBuffer(ByteBuffer bb) {
Expand Down

0 comments on commit bf924aa

Please sign in to comment.