use of org.eclipse.jetty.util.MultiException in project hbase by apache.
the class HttpServer method stop.
/**
* stop the server
*/
public void stop() throws Exception {
MultiException exception = null;
for (ListenerInfo li : listeners) {
if (!li.isManaged) {
continue;
}
try {
li.listener.close();
} catch (Exception e) {
LOG.error("Error while stopping listener for webapp" + webAppContext.getDisplayName(), e);
exception = addMultiException(exception, e);
}
}
try {
// clear & stop webAppContext attributes to avoid memory leaks.
webAppContext.clearAttributes();
webAppContext.stop();
} catch (Exception e) {
LOG.error("Error while stopping web app context for webapp " + webAppContext.getDisplayName(), e);
exception = addMultiException(exception, e);
}
try {
webServer.stop();
} catch (Exception e) {
LOG.error("Error while stopping web server for webapp " + webAppContext.getDisplayName(), e);
exception = addMultiException(exception, e);
}
if (exception != null) {
exception.ifExceptionThrow();
}
}
use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class AnnotationConfiguration method scanForAnnotations.
/**
* Perform scanning of classes for annotations
*
* @param context the context for the scan
* @throws Exception if unable to scan
*/
protected void scanForAnnotations(WebAppContext context) throws Exception {
AnnotationParser parser = createAnnotationParser();
_parserTasks = new ArrayList<ParserTask>();
long start = 0;
if (LOG.isDebugEnabled())
LOG.debug("Annotation scanning commencing: webxml={}, metadatacomplete={}, configurationDiscovered={}, multiThreaded={}, maxScanWait={}", context.getServletContext().getEffectiveMajorVersion(), context.getMetaData().isMetaDataComplete(), context.isConfigurationDiscovered(), isUseMultiThreading(context), getMaxScanWait(context));
parseContainerPath(context, parser);
//email from Rajiv Mordani jsrs 315 7 April 2010
// If there is a <others/> then the ordering should be
// WEB-INF/classes the order of the declared elements + others.
// In case there is no others then it is
// WEB-INF/classes + order of the elements.
parseWebInfClasses(context, parser);
parseWebInfLib(context, parser);
start = System.nanoTime();
//execute scan, either effectively synchronously (1 thread only), or asynchronously (limited by number of processors available)
final Semaphore task_limit = (isUseMultiThreading(context) ? new Semaphore(Runtime.getRuntime().availableProcessors()) : new Semaphore(1));
final CountDownLatch latch = new CountDownLatch(_parserTasks.size());
final MultiException me = new MultiException();
for (final ParserTask p : _parserTasks) {
task_limit.acquire();
context.getServer().getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
p.call();
} catch (Exception e) {
me.add(e);
} finally {
task_limit.release();
latch.countDown();
}
}
});
}
boolean timeout = !latch.await(getMaxScanWait(context), TimeUnit.SECONDS);
long elapsedMs = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
LOG.info("Scanning elapsed time={}ms", elapsedMs);
if (LOG.isDebugEnabled()) {
for (ParserTask p : _parserTasks) LOG.debug("Scanned {} in {}ms", p.getResource(), TimeUnit.MILLISECONDS.convert(p.getStatistic().getElapsed(), TimeUnit.NANOSECONDS));
LOG.debug("Scanned {} container path jars, {} WEB-INF/lib jars, {} WEB-INF/classes dirs in {}ms for context {}", _containerPathStats.getTotal(), _webInfLibStats.getTotal(), _webInfClassesStats.getTotal(), elapsedMs, context);
}
if (timeout)
me.add(new Exception("Timeout scanning annotations"));
me.ifExceptionThrow();
}
use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class AnnotationParser method parse.
/**
* Parse the given classes
*
* @param handlers the set of handlers to look for class in
* @param classNames the class names
* @throws Exception if unable to parse
*/
public void parse(Set<? extends Handler> handlers, List<String> classNames) throws Exception {
MultiException me = new MultiException();
for (String s : classNames) {
try {
if (!isParsed(s)) {
s = s.replace('.', '/') + ".class";
URL resource = Loader.getResource(s);
if (resource != null) {
Resource r = Resource.newResource(resource);
try (InputStream is = r.getInputStream()) {
scanClass(handlers, null, is);
}
}
}
} catch (Exception e) {
me.add(new RuntimeException("Error scanning class " + s, e));
}
}
me.ifExceptionThrow();
}
use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class AnnotationParser method parseJar.
/**
* Parse a resource that is a jar file.
*
* @param handlers the handlers to look for classes in
* @param jarResource the jar resource to parse
* @throws Exception if unable to parse
*/
protected void parseJar(Set<? extends Handler> handlers, Resource jarResource) throws Exception {
if (jarResource == null)
return;
if (jarResource.toString().endsWith(".jar")) {
if (LOG.isDebugEnabled()) {
LOG.debug("Scanning jar {}", jarResource);
}
;
//treat it as a jar that we need to open and scan all entries from
InputStream in = jarResource.getInputStream();
if (in == null)
return;
MultiException me = new MultiException();
JarInputStream jar_in = new JarInputStream(in);
try {
JarEntry entry = jar_in.getNextJarEntry();
while (entry != null) {
try {
parseJarEntry(handlers, jarResource, entry);
} catch (Exception e) {
me.add(new RuntimeException("Error scanning entry " + entry.getName() + " from jar " + jarResource, e));
}
entry = jar_in.getNextJarEntry();
}
} catch (Exception e) {
me.add(new RuntimeException("Error scanning jar " + jarResource, e));
} finally {
jar_in.close();
}
me.ifExceptionThrow();
}
}
use of org.eclipse.jetty.util.MultiException in project jetty.project by eclipse.
the class WebAppContext method destroy.
/* ------------------------------------------------------------ */
@Override
public void destroy() {
// Prepare for configuration
MultiException mx = new MultiException();
if (_configurations != null) {
for (int i = _configurations.size(); i-- > 0; ) {
try {
_configurations.get(i).destroy(this);
} catch (Exception e) {
mx.add(e);
}
}
}
_configurations.clear();
super.destroy();
mx.ifExceptionThrowRuntime();
}
Aggregations