FELIX-2647 : Implement Coordinator Service - remove unused code

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1553646 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/coordinator/pom.xml b/coordinator/pom.xml
index fee9584..8762423 100644
--- a/coordinator/pom.xml
+++ b/coordinator/pom.xml
@@ -61,7 +61,6 @@
                             org.osgi.service.coordinator
                         </Export-Package>
                         <Private-Package>
-                            org.apache.felix.jmx.service.coordinator,
                             org.apache.felix.coordinator.impl.*
                         </Private-Package>
                         <Bundle-Activator>
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java
index 14fe169..d3f8533 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/Activator.java
@@ -34,24 +34,12 @@
 
     private CoordinationMgr mgr;
 
-//    private ServiceTracker mbeanServerTracker;
-
     private ServiceRegistration coordinatorService;
 
     public void start(BundleContext context)
     {
         mgr = new CoordinationMgr();
-/*
-        try
-        {
-            mbeanServerTracker = new MBeanServerTracker(context, mgr);
-            mbeanServerTracker.open();
-        }
-        catch (MalformedObjectNameException e)
-        {
-            // TODO log
-        }
-*/
+
         final ServiceFactory factory = new CoordinatorFactory(mgr);
         final Hashtable<String, String> props = new Hashtable<String, String>();
         props.put(Constants.SERVICE_DESCRIPTION, "Coordinator Service Implementation");
@@ -66,13 +54,7 @@
             coordinatorService.unregister();
             coordinatorService = null;
         }
-/*
-        if (mbeanServerTracker != null)
-        {
-            mbeanServerTracker.close();
-            mbeanServerTracker = null;
-        }
-*/
+
         mgr.cleanUp();
     }
 
@@ -97,52 +79,4 @@
         }
 
     }
-/*
-    static final class MBeanServerTracker extends ServiceTracker
-    {
-
-        private final CoordinationMgr mgr;
-
-        private final ObjectName objectName;
-
-        MBeanServerTracker(final BundleContext context, final CoordinationMgr mgr) throws MalformedObjectNameException
-        {
-            super(context, MBeanServer.class.getName(), null);
-            this.mgr = mgr;
-            this.objectName = new ObjectName(CoordinatorMBean.OBJECTNAME);
-        }
-
-        @Override
-        public Object addingService(ServiceReference reference)
-        {
-            MBeanServer server = (MBeanServer) super.addingService(reference);
-
-            try
-            {
-                server.registerMBean(mgr, objectName);
-            }
-            catch (Exception e)
-            {
-                // TODO: log
-            }
-
-            return server;
-        }
-
-        @Override
-        public void removedService(ServiceReference reference, Object service)
-        {
-            try
-            {
-                ((MBeanServer) service).unregisterMBean(objectName);
-            }
-            catch (Exception e)
-            {
-                // TODO: log
-            }
-
-            super.removedService(reference, service);
-        }
-    }
-*/
 }
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 e0b5e18..f4e512a 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
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.coordinator.impl;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
@@ -32,10 +31,6 @@
 import java.util.TimerTask;
 import java.util.concurrent.atomic.AtomicLong;
 
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.TabularData;
-
-import org.apache.felix.jmx.service.coordinator.CoordinatorMBean;
 import org.osgi.framework.Bundle;
 import org.osgi.service.coordinator.Coordination;
 import org.osgi.service.coordinator.CoordinationException;
@@ -43,17 +38,9 @@
 
 /**
  * The <code>CoordinationMgr</code> is the actual back-end manager of all
- * Coordinations created by the Coordinator implementation. The methods in this
- * class fall into three categories:
- * <ul>
- * <li>Actual implementations of the Coordinator interface on behalf of the
- * per-bundle Coordinator service instances</li>
- * <li>Implementation of the CoordinatorMBean interface allowing JMX management
- * of the coordinations</li>
- * <li>Management support to timeout and cleanup coordinations</li>
- * </ul>
+ * Coordinations created by the Coordinator implementation.
  */
-public class CoordinationMgr implements CoordinatorMBean
+public class CoordinationMgr
 {
 
     private ThreadLocal<Stack<CoordinationImpl>> perThreadStack;
@@ -67,13 +54,6 @@
     private final Timer coordinationTimer;
 
     /**
-     * Default coordination timeout. Currently hard coded to be 30s (the
-     * specified minimum timeout). Should be made configurable, but not less
-     * than 30s.
-     */
-    private long defaultTimeOut = 30 * 1000L;
-
-    /**
      * Wait at most 60 seconds for participant to be eligible for participation
      * in a coordination.
      *
@@ -135,9 +115,8 @@
         return stack;
     }
 
-    void configure(final long coordinationTimeout, final long participationTimeout)
+    void configure(final long participationTimeout)
     {
-        this.defaultTimeOut = coordinationTimeout;
         this.participationTimeOut = participationTimeout;
     }
 
@@ -158,12 +137,14 @@
         synchronized (participants)
         {
             // wait for participant to be released
-            long cutOff = System.currentTimeMillis() + participationTimeOut;
-            long waitTime = (participationTimeOut > 500) ? participationTimeOut / 500 : participationTimeOut;
-            // TODO - the above wait time looks wrong e.g. if it's 800, the wait time 1ms
+            long completeWaitTime = participationTimeOut;
+            long cutOff = System.currentTimeMillis() + completeWaitTime;
+
             CoordinationImpl current = participants.get(p);
             while (current != null && current != c)
             {
+                final long waitTime = (completeWaitTime > 500) ? 500 : completeWaitTime;
+                completeWaitTime = completeWaitTime - waitTime;
                 if (current.getThread() != null && current.getThread() == c.getThread())
                 {
                     throw new CoordinationException("Participant " + p + " already participating in Coordination "
@@ -296,79 +277,6 @@
         }
     }
 
-    // ---------- CoordinatorMBean interface
-
-    public TabularData listCoordinations(String regexFilter)
-    {
-        return null;
-/*
-        Pattern p = Pattern.compile(regexFilter);
-        TabularData td = new TabularDataSupport(COORDINATIONS_TYPE);
-        for (CoordinationImpl c : coordinations.values())
-        {
-            if (p.matcher(c.getName()).matches())
-            {
-                try
-                {
-                    td.put(fromCoordination(c));
-                }
-                catch (OpenDataException e)
-                {
-                    // TODO: log
-                }
-            }
-        }
-        return td;
-*/
-    }
-
-    public CompositeData getCoordination(long id) throws IOException
-    {
-        return null;
-        /*
-        Coordination c = getCoordinationById(id);
-        if (c != null)
-        {
-            try
-            {
-                return fromCoordination((CoordinationImpl) c);
-            }
-            catch (OpenDataException e)
-            {
-                throw new IOException(e.toString());
-            }
-        }
-        throw new IOException("No such Coordination " + id);
-        */
-    }
-
-    public boolean fail(long id, String reason)
-    {
-        Coordination c = getCoordinationById(id);
-        if (c != null)
-        {
-            return c.fail(new Exception(reason));
-        }
-        return false;
-    }
-
-    public void addTimeout(long id, long timeout)
-    {
-        Coordination c = getCoordinationById(id);
-        if (c != null)
-        {
-            c.extendTimeout(timeout);
-        }
-    }
-/*
-    private CompositeData fromCoordination(final CoordinationImpl c) throws OpenDataException
-    {
-        return new CompositeDataSupport(COORDINATION_TYPE, new String[]
-            { ID, NAME, TIMEOUT }, new Object[]
-            { c.getId(), c.getName(), c.getDeadLine() });
-    }
-    */
-
 	public Coordination getEnclosingCoordination(final CoordinationImpl c)
 	{
         final Stack<CoordinationImpl> stack = this.getThreadStack(false);
diff --git a/coordinator/src/main/java/org/apache/felix/jmx/service/coordinator/CoordinatorMBean.java b/coordinator/src/main/java/org/apache/felix/jmx/service/coordinator/CoordinatorMBean.java
deleted file mode 100644
index 61e3ce4..0000000
--- a/coordinator/src/main/java/org/apache/felix/jmx/service/coordinator/CoordinatorMBean.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) OSGi Alliance (2004, 2010). All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.jmx.service.coordinator;
-
-import java.io.IOException;
-
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.TabularData;
-
-import org.osgi.service.coordinator.Coordination;
-
-/**
- * This MBean provides the management interface to the OSGi Coordinator Service
- *
- * @ThreadSafe
- * @Provisional
- */
-@Deprecated
-public interface CoordinatorMBean
-{
-
-    /**
-     * User Admin MBean object name.
-     */
-    public static final String OBJECTNAME = "osgi.compendium:service=coordinator,version=1.0";
-
-    /**
-     * The key NAME, used in NAME_ITEM.
-     */
-    public static final String NAME = "Name";
-
-    /**
-     * The item for the user name for an authorization object. The key is NAME
-     * and the type is SimpleType.STRING.
-     */
-//    public static final org.osgi.jmx.Item NAME_ITEM = new Item(NAME, null, SimpleType.STRING, (String[]) null);
-
-    /**
-     * The key ID, used in ID_ITEM.
-     */
-    public static final String ID = "Id";
-
-    /**
-     * The item for the id of an Coordination object. The key is ID and the type
-     * is SimpleType.LONG. The id must be generated by the Mbean and map to a
-     * unique Coordination (which should no be pinned in memory because of
-     * this).
-     */
-//    public static final org.osgi.jmx.Item ID_ITEM = new Item(ID, null, SimpleType.LONG, (String[]) null);
-
-    /**
-     * The key TIMEOUT, used in TIMEOUT_ITEM.
-     */
-    public static final String TIMEOUT = "Timeout";
-
-    /**
-     * The item for the id of an Coordination object. The key is TIMEOUT and the
-     * type is SimpleType.LONG.
-     */
-//    public static final org.osgi.jmx.Item TIMEOUT_ITEM = new Item(TIMEOUT, null, SimpleType.LONG, (String[]) null);
-
-    /**
-     * The key COORDINATION, used in COORDINATION_TYPE
-     */
-    public static final String COORDINATION = "Coordination";
-
-    /**
-     * Interface Coordination
-    public static final CompositeType COORDINATION_TYPE = Item
-        .compositeType("", null, ID_ITEM, NAME_ITEM, TIMEOUT_ITEM);
-     */
-
-    /**
-     * The key COORDINATIONS, used in COORDINATIONS_TYPE
-     * <p>
-     * fmeschbe note: This constant is added because it is needed for the
-     * {@link #COORDINATIONS_TYPE} definition
-     */
-    public static final String COORDINATIONS = "Coordinations";
-
-    /**
-     * Defines a list of COORDINATION_TYPE
-     * <p>
-     * fmeschbe note: The draft 2 spec defines this to be ArrayType but to use
-     * it for {@link #listCoordinations(String)} this constant must be a
-     * <code>TabularType</code>.
-    public static final TabularType COORDINATIONS_TYPE = Item.tabularType(COORDINATIONS, null, COORDINATION_TYPE, ID,
-        NAME, TIMEOUT);
-     */
-
-    /**
-     * List the current coordinations. The Composite Data is typed by
-     * COORDINATIONS_TYPE.
-     *
-     * @param regexFilter a regular expression filter on the coordination name
-     * @return the Coordinations typed by COORDINATIONS_TYPE.
-     * @throws IOException if the operation fails
-     */
-    TabularData listCoordinations(String regexFilter) throws IOException;
-
-    /**
-     * Get a Coordination. The Composite Data is typed by COORDINATION_TYPE.
-     *
-     * @param id The id of a Coordination
-     * @return the Coordinations typed by COORDINATION_TYPE.
-     * @throws IOException if the operation fails
-     */
-    CompositeData getCoordination(long id) throws IOException;
-
-    /**
-     * Fail a Coordination.
-     *
-     * @param id The id of the coordination to be failed.
-     * @param reason The reason the coordination should be failed. The
-     *            implementation of the MBean should create a
-     *            Throwable/Exception with this reason in order to fail the
-     *            specified Coordination
-     * @return true if the coordination was failed by this call, otherwise
-     *         false.
-     * @throws IOException
-     * @see Coordination#fail(Throwable)
-     */
-    boolean fail(long id, String reason) throws IOException;
-
-    /**
-     * Set/Change the timeout of a Coordination.
-     *
-     * @param id The id of the Coordination
-     * @param timeout The nr of milliseconds for the next timeout.
-     * @throws IOException
-     */
-    void addTimeout(long id, long timeout) throws IOException;
-}
diff --git a/coordinator/src/main/java/org/apache/felix/jmx/service/coordinator/package-info.java b/coordinator/src/main/java/org/apache/felix/jmx/service/coordinator/package-info.java
deleted file mode 100644
index 2c3417e..0000000
--- a/coordinator/src/main/java/org/apache/felix/jmx/service/coordinator/package-info.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) OSGi Alliance (2004, 2010). All Rights Reserved.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * OSGi JMX Coordination Package Version 1.0.
- * <p>
- * Bundles wishing to use this package must list the package in the
- * Import-Package header of the bundle's manifest.
- * <p>
- * This package has two types of users: the consumers that use the API in this
- * package and the providers that implement the API in this package.
- * <p>
- * Example import for consumers using the API in this package: <blockquote>
- * <code>Import-Package: org.apache.felix.jmx.service.coordination; version="[1.0,2.0)"; status="provisional"</code>
- * </blockquote>
- * <p>
- * Example import for providers implementing the API in this package:
- * <blockquote>
- * <code>Import-Package: org.apache.felix.jmx.service.coordination; version="[1.0,1.1)"; status="provisional"</code>
- * </blockquote>
- * 
- * @Provisional
- */
-@Deprecated
-package org.apache.felix.jmx.service.coordinator;
-
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 294957a..ecd94da 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
@@ -307,7 +307,7 @@
         final MockParticipant p1 = new MockParticipant();
 
         // ensure short timeout for participation
-        mgr.configure(60000, 200);
+        mgr.configure(200);
 
         final Coordination c1 = coordinator.create(name1, 0);
         c1.addParticipant(p1);