From b5a7c6659ae462bc199e686dd35502f1582c534f Mon Sep 17 00:00:00 2001 From: Richard Peter Date: Tue, 15 Apr 2014 14:28:03 -0500 Subject: [PATCH] Issue #2726: Update endpoint pattern and remove System.out.printlns Change-Id: I6d54cf695b8e339f9ac84b0a901cd47118e1872d Former-commit-id: 45121892a7a33d06f2ec4a90f250164f3842f4bc [formerly 294b02e2e52c34c80933246070b159364ba83933] [formerly ba1f83db17abbee47003d54cff5e5aaeb5419ef4] [formerly 45121892a7a33d06f2ec4a90f250164f3842f4bc [formerly 294b02e2e52c34c80933246070b159364ba83933] [formerly ba1f83db17abbee47003d54cff5e5aaeb5419ef4] [formerly 7e3d7103676935ba81f2c472f27bea4b91e4e5e5 [formerly ba1f83db17abbee47003d54cff5e5aaeb5419ef4 [formerly a724d7a0ed98f8f2860325a8578cf38e71e3ffcf]]]] Former-commit-id: 7e3d7103676935ba81f2c472f27bea4b91e4e5e5 Former-commit-id: c58fb27c2a7c2f22456ed6f82cd88ec10921963d [formerly e8db16d08b778105e6a0c6eb063665d990edaf74] [formerly 09f8e1ae46a1c33d27814d0fb0458b71dd76f203 [formerly 4736c51a1062af482456d600067336d9750d731e]] Former-commit-id: 719f2c9c90cf9060d27492d3ca4a4e8567659a83 [formerly 9aa3af42270434540c99b41e275d8530d4fdabce] Former-commit-id: 84896dd87f05cfa6be70de11918eeb1cb35bc79d --- .../META-INF/MANIFEST.MF | 1 + .../src/com/raytheon/uf/edex/esb/Main.java | 88 +++++++++++-------- .../raytheon/uf/edex/esb/camel/Executor.java | 79 ++++++++--------- .../edex/esb/camel/context/ContextData.java | 21 +---- 4 files changed, 93 insertions(+), 96 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/META-INF/MANIFEST.MF index 300e7c7726..d50e09c69a 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/META-INF/MANIFEST.MF @@ -6,3 +6,4 @@ Bundle-Version: 1.12.1174.qualifier Bundle-Vendor: Raytheon Main-Class: com.raytheon.uf.edex.esb.Main Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Require-Bundle: org.slf4j diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/src/com/raytheon/uf/edex/esb/Main.java b/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/src/com/raytheon/uf/edex/esb/Main.java index 8dc121d339..02fbcd6644 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/src/com/raytheon/uf/edex/esb/Main.java +++ b/edexOsgi/com.raytheon.uf.edex.esb.camel.launcher/src/com/raytheon/uf/edex/esb/Main.java @@ -32,11 +32,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.StringTokenizer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Provides a launcher for starting the ESB * @@ -47,8 +49,9 @@ import java.util.StringTokenizer; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Nov 14, 2008 chammack Initial creation - * Feb 15, 2013 1638 mschenke Removed reference to unused "stop" method + * Nov 14, 2008 chammack Initial creation. + * Feb 15, 2013 1638 mschenke Removed reference to unused "stop" method. + * Apr 15, 2014 2726 rjpeter Use slf4j logger. * * * @author chammack @@ -61,14 +64,16 @@ public class Main { private File edexHome; - private Set classPath = new HashSet(); + private final Set classPath = new HashSet(); - private Set extensions = new HashSet(); + private final Set extensions = new HashSet(); private ClassLoader classLoader; private static final int MAXIMUM_RECURSION_DEPTH = 6; + private static final Logger logger = LoggerFactory.getLogger(Main.class); + public static void main(String[] args) { boolean valid = true; @@ -82,9 +87,11 @@ public class Main { } if (!valid) { - System.out.println("Invalid or missing arguments."); - System.out.println("Usage: edex [operation]"); - System.out.println(" where operation is start."); + StringBuilder msg = new StringBuilder(200); + msg.append("Invalid or missing arguments.") + .append("\nUsage: edex [operation]") + .append("\n where operation is start."); + logger.error(msg.toString()); System.exit(0); } @@ -121,10 +128,12 @@ public class Main { try { fr = new FileReader(banner); br = new BufferedReader(fr); + StringBuilder msg = new StringBuilder(250); while (br.ready()) { String line = br.readLine(); - System.out.println(line); + msg.append("\n").append(line); } + logger.info(msg.toString()); } catch (Throwable e) { // ignore } finally { @@ -136,12 +145,13 @@ public class Main { } } - if (fr != null) + if (fr != null) { try { fr.close(); } catch (RuntimeException e) { // ignore } + } } @@ -152,16 +162,17 @@ public class Main { } System.exit(0); } catch (ClassNotFoundException e) { - System.out.println("Could not load class: " + e.getMessage()); + logger.error("Could not load class", e); if (cl != null) { - System.out.println("Class loader setup: "); - printClassLoaderTree(cl); + StringBuilder msg = new StringBuilder(1000); + msg.append("Class loader setup:"); + printClassLoaderTree(cl, msg); + logger.info(msg.toString()); } System.exit(1); } catch (Throwable e) { - e.printStackTrace(); - printClassLoaderTree(cl); + logger.error("Error occurred during startup: ", e); System.exit(1); } } @@ -173,13 +184,12 @@ public class Main { ArrayList urls = new ArrayList(500); - for (Iterator iter = classPath.iterator(); iter.hasNext();) { - File dir = iter.next(); + for (File dir : classPath) { try { urls.add(dir.toURI().toURL()); } catch (MalformedURLException e) { - System.out.println("Bad directory entry: " + dir - + ":: Skipping."); + logger.warn("Bad directory entry: " + dir + + ":: Skipping.", e); } } @@ -188,6 +198,7 @@ public class Main { // Sort the dirs so that classpath built is // consistently in the same order Arrays.sort(extensionsArray, new Comparator() { + @Override public int compare(File f1, File f2) { return f1.getPath().compareTo(f2.getPath()); } @@ -201,19 +212,20 @@ public class Main { // Sort the jars so that classpath built is // consistently in the same order Arrays.sort(files, new Comparator() { + @Override public int compare(File f1, File f2) { return f1.getName().compareTo(f2.getName()); } }); - for (int j = 0; j < files.length; j++) { - if (files[j].getName().endsWith(".zip") - || files[j].getName().endsWith(".jar")) { + for (File file : files) { + if (file.getName().endsWith(".zip") + || file.getName().endsWith(".jar")) { try { - urls.add(files[j].toURI().toURL()); + urls.add(file.toURI().toURL()); } catch (MalformedURLException e) { - System.out.println("Bad jar entry: " - + dir + ":: Skipping."); + logger.warn("Bad jar entry: " + dir + + ":: Skipping.", e); } } } @@ -241,10 +253,8 @@ public class Main { } } } else { - System.out - .println("WARNING: " - + file - + " exceeded maximum recursion depth. Not traversing further."); + logger.warn(file + + ": exceeded maximum recursion depth. Not traversing further."); } } @@ -281,7 +291,7 @@ public class Main { } public void addClassPathList(String fileList) { - if (fileList != null && fileList.length() > 0) { + if ((fileList != null) && (fileList.length() > 0)) { StringTokenizer tokenizer = new StringTokenizer(fileList, ";"); while (tokenizer.hasMoreTokens()) { addClassPath(new File(tokenizer.nextToken())); @@ -303,28 +313,30 @@ public class Main { * @param cl * @return depth */ - private static int printClassLoaderTree(ClassLoader cl) { + private static int printClassLoaderTree(ClassLoader cl, StringBuilder msg) { int depth = 0; if (cl.getParent() != null) { - depth = printClassLoaderTree(cl.getParent()) + 1; + depth = printClassLoaderTree(cl.getParent(), msg) + 1; } - StringBuffer indent = new StringBuffer(); + StringBuilder indent = new StringBuilder(2 * depth); for (int i = 0; i < depth; i++) { indent.append(" "); } if (cl instanceof URLClassLoader) { URLClassLoader ucl = (URLClassLoader) cl; - System.out.println(indent + cl.getClass().getName() + " {"); + msg.append("\n").append(indent).append(cl.getClass().getName()) + .append(" {"); URL[] urls = ucl.getURLs(); - for (int i = 0; i < urls.length; i++) { - System.out.println(indent + " " + urls[i]); + for (URL url : urls) { + msg.append("\n").append(indent).append(" ").append(url); } - System.out.println(indent + "}"); + msg.append("\n").append(indent).append("}"); } else { - System.out.println(indent + cl.getClass().getName()); + msg.append("\n").append(indent).append(cl.getClass().getName()); } + return depth; } diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java b/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java index 2a11413746..4b6fb4a58a 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java +++ b/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/Executor.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.CountDownLatch; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.raytheon.uf.common.time.util.TimeUtil; @@ -67,6 +69,9 @@ public class Executor { private static final CountDownLatch shutdownLatch = new CountDownLatch(1); + private static final Logger logger = LoggerFactory + .getLogger(Executor.class); + public static void start() throws Exception { final long t0 = System.currentTimeMillis(); @@ -76,24 +81,23 @@ public class Executor { ContextManager ctxMgr = ContextManager.getInstance(); long t1 = System.currentTimeMillis(); - System.out - .println("**************************************************"); - System.out - .println("* EDEX ESB is shutting down *"); - System.out - .println("**************************************************"); + StringBuilder msg = new StringBuilder(250); + msg.append( + "\n**************************************************") + .append("\n* EDEX ESB is shutting down *") + .append("\n**************************************************"); + logger.info(msg.toString()); ctxMgr.stopContexts(); long t2 = System.currentTimeMillis(); - System.out - .println("**************************************************"); - System.out - .println("* EDEX ESB is shut down *"); - System.out.println("* Total time to shutdown: " - + TimeUtil.prettyDuration(t2 - t1)); - System.out.println("* EDEX ESB uptime: " - + TimeUtil.prettyDuration(t2 - t0)); - System.out - .println("**************************************************"); + msg.setLength(0); + msg.append("\n**************************************************"); + msg.append("\n* EDEX ESB is shut down *"); + msg.append("\n* Total time to shutdown: ") + .append(TimeUtil.prettyDuration(t2 - t1)).append(""); + msg.append("\n* EDEX ESB uptime: ") + .append(TimeUtil.prettyDuration(t2 - t0)).append(""); + msg.append("\n**************************************************"); + logger.info(msg.toString()); shutdownLatch.countDown(); } }); @@ -137,29 +141,24 @@ public class Executor { String modeName = System.getProperty("edex.run.mode"); if ((modeName != null) && (modeName.length() > 0)) { - System.out.println("EDEX run configuration: " + modeName); + logger.info("EDEX run configuration: " + modeName); } else { - System.out - .println("No EDEX run configuration specified, defaulting to use all discovered spring XML files"); + logger.info("No EDEX run configuration specified, defaulting to use all discovered spring XML files"); } - System.out.println("EDEX site configuration: " + logger.info("EDEX site configuration: " + System.getProperty("aw.site.identifier")); List discoveredPlugins = EDEXModesUtil.extractSpringXmlFiles( xmlFiles, modeName); - System.out.println(); - System.out.println(" "); - System.out.println("EDEX configuration files: "); - System.out.println("-----------------------"); - System.out.println(printList(springList)); - System.out.println(" "); - System.out.println(" "); - System.out.println("Spring-enabled Plugins:"); - System.out.println("-----------------------"); - System.out.println(printList(discoveredPlugins)); - System.out.println(" "); - System.out.println(" "); + StringBuilder msg = new StringBuilder(1000); + msg.append("\n\nEDEX configuration files: "); + msg.append("\n-----------------------"); + msg.append("\n").append(printList(springList)); + msg.append("\n\nSpring-enabled Plugins:"); + msg.append("\n-----------------------"); + msg.append("\n").append(printList(discoveredPlugins)).append("\n"); + logger.info(msg.toString()); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( xmlFiles.toArray(new String[xmlFiles.size()])); @@ -171,14 +170,14 @@ public class Executor { ctxMgr.startContexts(); long t1 = System.currentTimeMillis(); - System.out - .println("**************************************************"); - System.out - .println("* EDEX ESB is now operational *"); - System.out.println("* Total startup time: " - + TimeUtil.prettyDuration(t1 - t0)); - System.out - .println("**************************************************"); + msg.setLength(0); + msg.append("\n**************************************************"); + msg.append("\n* EDEX ESB is now operational *"); + msg.append("\n* Total startup time: ").append( + TimeUtil.prettyDuration(t1 - t0)); + msg.append("\n**************************************************"); + logger.info(msg.toString()); + msg = null; System.setProperty("System.status", "Operational"); EDEXUtil.notifyIsRunning(); diff --git a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/context/ContextData.java b/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/context/ContextData.java index 8070afe4a5..ef38e8babf 100644 --- a/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/context/ContextData.java +++ b/edexOsgi/com.raytheon.uf.edex.esb.camel/src/com/raytheon/uf/edex/esb/camel/context/ContextData.java @@ -21,11 +21,9 @@ package com.raytheon.uf.edex.esb.camel.context; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -46,7 +44,7 @@ import com.raytheon.uf.edex.core.EdexException; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Apr 10, 2014 2726 rjpeter Initial creation + * Apr 10, 2014 2726 rjpeter Initial creation. * * * @@ -54,18 +52,6 @@ import com.raytheon.uf.edex.core.EdexException; * @version 1.0 */ public class ContextData { - /** - * Set of endpoint types that allow multiple consumers. - */ - private static final Set MULTIPLE_CONSUMER_TYPES; - - static { - Set multipleConsumerTypes = new HashSet(1, 1); - multipleConsumerTypes.add("topic"); - MULTIPLE_CONSUMER_TYPES = Collections - .unmodifiableSet(multipleConsumerTypes); - } - private final List contexts; private final Map consumerRouteMapping; @@ -77,7 +63,7 @@ public class ContextData { * the endpoint URI. */ private static final Pattern endpointUriParsePattern = Pattern - .compile("(?:[^:]+:)*([^:]+):(?://)?([^?]+)\\??.*$"); + .compile("([^:]+)://([^?]+)"); /** * Parses passed contexts for route and endpoint data about all contexts. @@ -126,8 +112,7 @@ public class ContextData { Route prev = routeMapping.put(endpointName, route); if ((prev != null) - && !MULTIPLE_CONSUMER_TYPES - .contains(typeAndName.getFirst())) { + && !endpointName.startsWith("topic:")) { throw new ConfigurationException( "Two contexts listen to the same endpoint name [" + endpointName