[MRM-1066] Shutdown of Tomcat causes Exception when running Archiva Project

o log error instead of printing stack trace
o clean up code


git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@952943 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2010-06-09 10:22:49 +00:00
parent b9b2c5ca0c
commit c49ad562ff
1 changed files with 30 additions and 26 deletions

View File

@ -20,6 +20,8 @@ package org.apache.maven.archiva.web.startup;
*/ */
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
@ -34,6 +36,8 @@ import org.codehaus.plexus.spring.PlexusWebApplicationContext;
import org.codehaus.plexus.taskqueue.Task; import org.codehaus.plexus.taskqueue.Task;
import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor; import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
import org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor; import org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.support.WebApplicationContextUtils;
@ -48,14 +52,12 @@ import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
public class ArchivaStartup public class ArchivaStartup
implements ServletContextListener implements ServletContextListener
{ {
private ThreadedTaskQueueExecutor tqeDbScanning; private List<ThreadedTaskQueueExecutor> executors;
private ThreadedTaskQueueExecutor tqeRepoScanning;
private ThreadedTaskQueueExecutor tqeIndexing;
private ArchivaTaskScheduler taskScheduler; private ArchivaTaskScheduler taskScheduler;
private Logger log = LoggerFactory.getLogger( ArchivaStartup.class );
public void contextInitialized( ServletContextEvent contextEvent ) public void contextInitialized( ServletContextEvent contextEvent )
{ {
WebApplicationContext wac = WebApplicationContext wac =
@ -69,15 +71,16 @@ public class ArchivaStartup
taskScheduler = taskScheduler =
(ArchivaTaskScheduler) wac.getBean( PlexusToSpringUtils.buildSpringId( ArchivaTaskScheduler.class ) ); (ArchivaTaskScheduler) wac.getBean( PlexusToSpringUtils.buildSpringId( ArchivaTaskScheduler.class ) );
tqeDbScanning = executors = new ArrayList<ThreadedTaskQueueExecutor>();
(ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId( TaskQueueExecutor.class, executors.add( (ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId(
"database-update" ) ); TaskQueueExecutor.class,
tqeRepoScanning = "database-update" ) ) );
(ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId( TaskQueueExecutor.class, executors.add( (ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId(
"repository-scanning" ) ); TaskQueueExecutor.class,
tqeIndexing = "repository-scanning" ) ) );
(ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId( TaskQueueExecutor.class, executors.add( (ThreadedTaskQueueExecutor) wac.getBean( PlexusToSpringUtils.buildSpringId(
"indexing" ) ); TaskQueueExecutor.class,
"indexing" ) ) );
try try
{ {
@ -104,9 +107,10 @@ public class ArchivaStartup
if ( applicationContext != null && applicationContext instanceof PlexusWebApplicationContext ) if ( applicationContext != null && applicationContext instanceof PlexusWebApplicationContext )
{ {
// stop task queue executors // stop task queue executors
stopTaskQueueExecutor( tqeDbScanning ); for( ThreadedTaskQueueExecutor executor : executors )
stopTaskQueueExecutor( tqeRepoScanning ); {
stopTaskQueueExecutor( tqeIndexing ); stopTaskQueueExecutor( executor );
}
// stop the DefaultArchivaTaskScheduler and its scheduler // stop the DefaultArchivaTaskScheduler and its scheduler
if ( taskScheduler != null && taskScheduler instanceof DefaultArchivaTaskScheduler ) if ( taskScheduler != null && taskScheduler instanceof DefaultArchivaTaskScheduler )
@ -117,7 +121,7 @@ public class ArchivaStartup
} }
catch ( StoppingException e ) catch ( StoppingException e )
{ {
e.printStackTrace(); log.error( "Unable to stop Archiva task scheduler.", e );
} }
} }
@ -132,7 +136,7 @@ public class ArchivaStartup
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace(); log.error( "Error occurred while stopping scheduler.", e );
} }
// close the application context // close the application context
@ -159,9 +163,9 @@ public class ArchivaStartup
service.shutdown(); service.shutdown();
} }
} }
catch ( Exception e ) catch ( StoppingException e )
{ {
e.printStackTrace(); log.error( "Unable to stop task queue executor.", e );
} }
} }
} }
@ -177,7 +181,7 @@ public class ArchivaStartup
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace(); log.error( "Error occurred while retrievin executor service.", e );
} }
return service; return service;
} }