FELIX-2647 : Implement Coordinator Service - further fixes for the CT tests cases, 55 of 61 passing

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1551125 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
index 3bd2589..0b14a71 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
@@ -75,6 +75,8 @@
 
     private Thread associatedThread;
 
+    private final Object waitLock = new Object();
+
     public CoordinationImpl(final CoordinatorImpl owner, final long id, final String name, final long timeOutInMs)
     {
         this.owner = owner;
@@ -143,9 +145,9 @@
             this.owner.unregister(this, false);
             state = State.FAILED;
 
-            synchronized (this)
+            synchronized (this.waitLock)
             {
-                this.notifyAll();
+                this.waitLock.notifyAll();
             }
 
             return true;
@@ -190,9 +192,9 @@
 
             state = State.TERMINATED;
 
-            synchronized (this)
+            synchronized (this.waitLock)
             {
-                this.notifyAll();
+                this.waitLock.notifyAll();
             }
 
             if (partialFailure)
@@ -308,23 +310,25 @@
         {
             throw new IllegalArgumentException("Timeout must not be negative");
         }
-
-        synchronized (this)
+        if ( this.deadLine > 0 )
         {
-            if (isTerminated())
+            synchronized (this)
             {
-                throw new CoordinationException("Cannot extend timeout on terminated Coordination", this,
-                    (getFailure() != null) ? CoordinationException.FAILED : CoordinationException.ALREADY_ENDED, getFailure());
-            }
+                if (isTerminated())
+                {
+                    throw new CoordinationException("Cannot extend timeout on terminated Coordination", this,
+                        (getFailure() != null) ? CoordinationException.FAILED : CoordinationException.ALREADY_ENDED, getFailure());
+                }
 
-            if (timeOutInMs > 0)
-            {
-                this.deadLine += timeOutInMs;
-                scheduleTimeout(this.deadLine);
-            }
+                if (timeOutInMs > 0)
+                {
+                    this.deadLine += timeOutInMs;
+                    scheduleTimeout(this.deadLine);
+                }
 
-            return this.deadLine;
+            }
         }
+        return this.deadLine;
     }
 
     /**
@@ -346,13 +350,18 @@
     /**
      * @see org.osgi.service.coordinator.Coordination#join(long)
      */
-    public void join(long timeoutInMillis) throws InterruptedException
+    public void join(final long timeOutInMs) throws InterruptedException
     {
-        synchronized (this)
+        if ( timeOutInMs < 0 )
         {
-            if (!isTerminated())
+            throw new IllegalArgumentException("Timeout must not be negative");
+        }
+
+        if ( !isTerminated() )
+        {
+            synchronized ( this.waitLock )
             {
-                this.wait(timeoutInMillis);
+                this.waitLock.wait(timeOutInMs);
             }
         }
     }
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java
index 0a372bb..add4096 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationMgr.java
@@ -171,7 +171,7 @@
                 if (System.currentTimeMillis() > cutOff)
                 {
                     throw new CoordinationException("Timed out waiting to join coordinaton", c,
-                        CoordinationException.UNKNOWN);
+                        CoordinationException.FAILED, Coordination.TIMEOUT);
                 }
 
                 // check again
diff --git a/coordinator/src/test/java/org/apache/felix/coordinator/impl/CoordinatorImplTest.java b/coordinator/src/test/java/org/apache/felix/coordinator/impl/CoordinatorImplTest.java
index d2bf362..194c9cf 100644
--- a/coordinator/src/test/java/org/apache/felix/coordinator/impl/CoordinatorImplTest.java
+++ b/coordinator/src/test/java/org/apache/felix/coordinator/impl/CoordinatorImplTest.java
@@ -348,11 +348,11 @@
         Throwable p1PartFailure = p1.addParticipantFailure;
         if (p1PartFailure == null)
         {
-            fail("Expecting CoordinationException/UNKNOWN for second participation");
+            fail("Expecting CoordinationException/FAILED for second participation");
         }
         else if (p1PartFailure instanceof CoordinationException)
         {
-            assertEquals(CoordinationException.UNKNOWN, ((CoordinationException) p1PartFailure).getType());
+            assertEquals(CoordinationException.FAILED, ((CoordinationException) p1PartFailure).getType());
         }
         else
         {