Merge "Issue #2726: Update endpoint pattern and remove System.out.printlns" into development

Former-commit-id: 7c6bf2a9dd197896a1117c29928e6626a09826e3
This commit is contained in:
Nate Jensen 2014-04-15 16:08:26 -05:00 committed by Gerrit Code Review
commit ec96b9a261
4 changed files with 93 additions and 96 deletions

View file

@ -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

View file

@ -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.
* </pre>
*
* @author chammack
@ -61,14 +64,16 @@ public class Main {
private File edexHome;
private Set<File> classPath = new HashSet<File>();
private final Set<File> classPath = new HashSet<File>();
private Set<File> extensions = new HashSet<File>();
private final Set<File> extensions = new HashSet<File>();
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<URL> urls = new ArrayList<URL>(500);
for (Iterator<File> 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<File>() {
@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<File>() {
@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;
}

View file

@ -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<String> 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();

View file

@ -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.
*
* </pre>
*
@ -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<String> MULTIPLE_CONSUMER_TYPES;
static {
Set<String> multipleConsumerTypes = new HashSet<String>(1, 1);
multipleConsumerTypes.add("topic");
MULTIPLE_CONSUMER_TYPES = Collections
.unmodifiableSet(multipleConsumerTypes);
}
private final List<CamelContext> contexts;
private final Map<String, Route> 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