// add the default serializers compiled with OpenTSDB
if (serializers == null) {
serializers = new ArrayList<HttpSerializer>(1);
}
final HttpSerializer default_serializer = new HttpJsonSerializer();
serializers.add(default_serializer);
serializer_map_content_type =
new HashMap<String, Constructor<? extends HttpSerializer>>();
serializer_map_query_string =
new HashMap<String, Constructor<? extends HttpSerializer>>();
serializer_status = new ArrayList<HashMap<String, Object>>();
for (HttpSerializer serializer : serializers) {
final Constructor<? extends HttpSerializer> ctor =
serializer.getClass().getDeclaredConstructor(HttpQuery.class);
// check for collisions before adding serializers to the maps
Constructor<? extends HttpSerializer> map_ctor =
serializer_map_content_type.get(serializer.requestContentType());
if (map_ctor != null) {
final String err = "Serializer content type collision between \"" +
serializer.getClass().getCanonicalName() + "\" and \"" +
map_ctor.getClass().getCanonicalName() + "\"";
LOG.error(err);
throw new IllegalStateException(err);
}
serializer_map_content_type.put(serializer.requestContentType(), ctor);
map_ctor = serializer_map_query_string.get(serializer.shortName());
if (map_ctor != null) {
final String err = "Serializer name collision between \"" +
serializer.getClass().getCanonicalName() + "\" and \"" +
map_ctor.getClass().getCanonicalName() + "\"";
LOG.error(err);
throw new IllegalStateException(err);
}
serializer_map_query_string.put(serializer.shortName(), ctor);
// initialize the plugins
serializer.initialize(tsdb);
// write the status for any serializers OTHER than the default
if (serializer.shortName().equals("json")) {
continue;
}
HashMap<String, Object> status = new HashMap<String, Object>();
status.put("version", serializer.version());
status.put("class", serializer.getClass().getCanonicalName());
status.put("serializer", serializer.shortName());
status.put("request_content_type", serializer.requestContentType());
status.put("response_content_type", serializer.responseContentType());
HashSet<String> parsers = new HashSet<String>();
HashSet<String> formats = new HashSet<String>();
Method[] methods = serializer.getClass().getDeclaredMethods();
for (Method m : methods) {
if (Modifier.isPublic(m.getModifiers())) {
if (m.getName().startsWith("parse")) {
parsers.add(m.getName().substring(5));
} else if (m.getName().startsWith("format")) {
formats.add(m.getName().substring(6));
}
}
}
status.put("parsers", parsers);
status.put("formatters", formats);
serializer_status.add(status);
}
// add the base class to the status map so users can see everything that
// is implemented
HashMap<String, Object> status = new HashMap<String, Object>();
// todo - set the OpenTSDB version
//status.put("version", BuildData.version);
final Class<?> base_serializer =
Class.forName("net.opentsdb.tsd.HttpSerializer");
status.put("class", default_serializer.getClass().getCanonicalName());
status.put("serializer", default_serializer.shortName());
status.put("request_content_type", default_serializer.requestContentType());
status.put("response_content_type", default_serializer.responseContentType());
ArrayList<String> parsers = new ArrayList<String>();
ArrayList<String> formats = new ArrayList<String>();
Method[] methods = base_serializer.getDeclaredMethods();
for (Method m : methods) {