FELIX-3727 wait for actor to finish, and also avoid NPE
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1402234 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index 33b3a66..87b08e7 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -375,7 +375,8 @@
{
if ( m_configuration.getLogLevel() >= level )
{
- Object logger = ( m_logService != null ) ? m_logService.getService() : null;
+ ServiceTracker t = m_logService;
+ Object logger = ( t != null ) ? t.getService() : null;
if ( logger == null )
{
// output depending on level
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ComponentActorThread.java b/scr/src/main/java/org/apache/felix/scr/impl/ComponentActorThread.java
index b4e2347..a6149bc 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ComponentActorThread.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ComponentActorThread.java
@@ -84,16 +84,16 @@
task = ( Runnable ) tasks.removeFirst();
}
- // return if the task is this thread itself
- if ( task == TERMINATION_TASK )
- {
- Activator.log( LogService.LOG_DEBUG, null, "Shutting down ComponentActorThread", null );
- return;
- }
-
- // otherwise execute the task, log any issues
try
{
+ // return if the task is this thread itself
+ if ( task == TERMINATION_TASK )
+ {
+ Activator.log( LogService.LOG_DEBUG, null, "Shutting down ComponentActorThread", null );
+ return;
+ }
+
+ // otherwise execute the task, log any issues
Activator.log( LogService.LOG_DEBUG, null, "Running task: " + task, null );
task.run();
}
@@ -101,6 +101,13 @@
{
Activator.log( LogService.LOG_ERROR, null, "Unexpected problem executing task " + task, t );
}
+ finally
+ {
+ synchronized ( tasks )
+ {
+ tasks.notifyAll();
+ }
+ }
}
}
@@ -110,6 +117,20 @@
void terminate()
{
schedule( TERMINATION_TASK );
+ synchronized ( tasks )
+ {
+ while ( !tasks.isEmpty() )
+ {
+ try
+ {
+ tasks.wait();
+ }
+ catch ( InterruptedException e )
+ {
+ Activator.log( LogService.LOG_ERROR, null, "Interrupted exception waiting for queue to empty", e );
+ }
+ }
+ }
}