Loads the serializer maps with present, implemented serializers. If no plugins are loaded, only the default implementations will be available. This method also builds the status map that users can access via the API to see what has been implemented. WARNING: The TSDB should have called on
(final TSDB tsdb)
| 788 | * @since 2.0 |
| 789 | */ |
| 790 | public static void initializeSerializerMaps(final TSDB tsdb) |
| 791 | throws SecurityException, NoSuchMethodException, ClassNotFoundException { |
| 792 | List<HttpSerializer> serializers = |
| 793 | PluginLoader.loadPlugins(HttpSerializer.class); |
| 794 | |
| 795 | // add the default serializers compiled with OpenTSDB |
| 796 | if (serializers == null) { |
| 797 | serializers = new ArrayList<HttpSerializer>(1); |
| 798 | } |
| 799 | final HttpSerializer default_serializer = new HttpJsonSerializer(); |
| 800 | serializers.add(default_serializer); |
| 801 | |
| 802 | serializer_map_content_type = |
| 803 | new HashMap<String, Constructor<? extends HttpSerializer>>(); |
| 804 | serializer_map_query_string = |
| 805 | new HashMap<String, Constructor<? extends HttpSerializer>>(); |
| 806 | serializer_status = new ArrayList<HashMap<String, Object>>(); |
| 807 | |
| 808 | for (HttpSerializer serializer : serializers) { |
| 809 | final Constructor<? extends HttpSerializer> ctor = |
| 810 | serializer.getClass().getDeclaredConstructor(HttpQuery.class); |
| 811 | |
| 812 | // check for collisions before adding serializers to the maps |
| 813 | Constructor<? extends HttpSerializer> map_ctor = |
| 814 | serializer_map_content_type.get(serializer.requestContentType()); |
| 815 | if (map_ctor != null) { |
| 816 | final String err = "Serializer content type collision between \"" + |
| 817 | serializer.getClass().getCanonicalName() + "\" and \"" + |
| 818 | map_ctor.getClass().getCanonicalName() + "\""; |
| 819 | LOG.error(err); |
| 820 | throw new IllegalStateException(err); |
| 821 | } |
| 822 | serializer_map_content_type.put(serializer.requestContentType(), ctor); |
| 823 | |
| 824 | map_ctor = serializer_map_query_string.get(serializer.shortName()); |
| 825 | if (map_ctor != null) { |
| 826 | final String err = "Serializer name collision between \"" + |
| 827 | serializer.getClass().getCanonicalName() + "\" and \"" + |
| 828 | map_ctor.getClass().getCanonicalName() + "\""; |
| 829 | LOG.error(err); |
| 830 | throw new IllegalStateException(err); |
| 831 | } |
| 832 | serializer_map_query_string.put(serializer.shortName(), ctor); |
| 833 | |
| 834 | // initialize the plugins |
| 835 | serializer.initialize(tsdb); |
| 836 | |
| 837 | // write the status for any serializers OTHER than the default |
| 838 | if (serializer.shortName().equals("json")) { |
| 839 | continue; |
| 840 | } |
| 841 | HashMap<String, Object> status = new HashMap<String, Object>(); |
| 842 | status.put("version", serializer.version()); |
| 843 | status.put("class", serializer.getClass().getCanonicalName()); |
| 844 | status.put("serializer", serializer.shortName()); |
| 845 | status.put("request_content_type", serializer.requestContentType()); |
| 846 | status.put("response_content_type", serializer.responseContentType()); |
| 847 |