Github user cestella commented on a diff in the pull request:
https://github.com/apache/metron/pull/785#discussion_r145423853
--- Diff:
metron-interface/metron-rest/src/main/java/org/apache/metron/rest/util/ParserIndex.java
---
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.rest.util;
+
+import org.apache.metron.parsers.interfaces.MessageParser;
+import org.reflections.Reflections;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.invoke.MethodHandles;
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Index the parsers. Analyzing the classpath is a costly operation, so
caching it makes sense.
+ * Eventually, we will probably want to have a timer that periodically
reindexes so that new parsers show up.
+ */
+public enum ParserIndex {
+ INSTANCE;
+ private static final Logger LOG =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private static Set<Class<? extends MessageParser>> index;
+ private static Map<String, String> availableParsers ;
+
+ static {
+ load();
+ }
+
+ public synchronized Map<String, String> getIndex() {
+ if(availableParsers == null) {
+ load();
+ }
+ return availableParsers;
+ }
+
+ public synchronized Set<Class<? extends MessageParser>> getClasses() {
+ if(index == null) {
+ load();
+ }
+ return index;
+ }
+
+ public static void reload() {
+ load();
+ }
+
+ /**
+ * To handle the situation where classpath is specified in the manifest
of the jar, we have to augment the URLs.
+ * This happens as part of the surefire plugin as well as elsewhere in
the wild.
+ * @param classLoaders
+ * @return
--- End diff --
Agreed. I corrected it here. Thanks for pointing it out, mike.
---