You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by br...@apache.org on 2013/08/21 17:34:17 UTC

svn commit: r1516190 - in /ace/trunk/org.apache.ace.agent: src/org/apache/ace/agent/ src/org/apache/ace/agent/impl/ test/org/apache/ace/agent/impl/ test/org/apache/ace/agent/testutil/

Author: bramk
Date: Wed Aug 21 15:34:16 2013
New Revision: 1516190

URL: http://svn.apache.org/r1516190
Log:
ACE-347 Made handlers AgentContextAware

Added:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/AgentContext.java
      - copied, changed from r1516159, ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContext.java
Removed:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContext.java
Modified:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentControlImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConnectionHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DeploymentHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackChannelImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerImplTest.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationHandlerImplTest.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java

Copied: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/AgentContext.java (from r1516159, ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContext.java)
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/AgentContext.java?p2=ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/AgentContext.java&p1=ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContext.java&r1=1516159&r2=1516190&rev=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContext.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/AgentContext.java Wed Aug 21 15:34:16 2013
@@ -16,19 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.ace.agent.impl;
+package org.apache.ace.agent;
 
 import java.io.File;
 import java.util.concurrent.ScheduledExecutorService;
 
-import org.apache.ace.agent.AgentControl;
-import org.apache.ace.agent.AgentUpdateHandler;
-import org.apache.ace.agent.ConfigurationHandler;
-import org.apache.ace.agent.ConnectionHandler;
-import org.apache.ace.agent.DeploymentHandler;
-import org.apache.ace.agent.DiscoveryHandler;
-import org.apache.ace.agent.DownloadHandler;
-import org.apache.ace.agent.IdentificationHandler;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.service.log.LogService;
 

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java Wed Aug 21 15:34:16 2013
@@ -57,7 +57,7 @@ public class Activator extends Dependenc
     private final InternalLogService m_internalLogService = new InternalLogService();
 
     // managed state
-    private AgentContext m_agentContext;
+    private AgentContextImpl m_agentContext;
     private AgentControl m_agentControl;
     private ScheduledExecutorService m_executorService;
     private AgentUpdateHandlerImpl m_agentUpdateHandler; // we use the implementation type here on purpose
@@ -83,17 +83,17 @@ public class Activator extends Dependenc
 
         m_agentContext = new AgentContextImpl(context.getDataFile(""));
         m_agentControl = new AgentControlImpl(m_agentContext);
-        m_agentUpdateHandler = new AgentUpdateHandlerImpl(m_agentContext, context);
+        m_agentUpdateHandler = new AgentUpdateHandlerImpl(context);
 
         configureField(m_agentContext, AgentControl.class, m_agentControl);
         configureField(m_agentContext, EventAdmin.class, m_internalEventAdmin);
         configureField(m_agentContext, LogService.class, m_internalLogService);
-        configureField(m_agentContext, ConfigurationHandler.class, new ConfigurationHandlerImpl(m_agentContext));
-        configureField(m_agentContext, ConnectionHandler.class, new ConnectionHandlerImpl(m_agentContext));
-        configureField(m_agentContext, DeploymentHandler.class, new DeploymentHandlerImpl(m_agentContext, m_internalDeploymentAdmin));
-        configureField(m_agentContext, DiscoveryHandler.class, new DiscoveryHandlerImpl(m_agentContext));
-        configureField(m_agentContext, DownloadHandler.class, new DownloadHandlerImpl(m_agentContext));
-        configureField(m_agentContext, IdentificationHandler.class, new IdentificationHandlerImpl(m_agentContext));
+        configureField(m_agentContext, ConfigurationHandler.class, new ConfigurationHandlerImpl());
+        configureField(m_agentContext, ConnectionHandler.class, new ConnectionHandlerImpl());
+        configureField(m_agentContext, DeploymentHandler.class, new DeploymentHandlerImpl(m_internalDeploymentAdmin));
+        configureField(m_agentContext, DiscoveryHandler.class, new DiscoveryHandlerImpl());
+        configureField(m_agentContext, DownloadHandler.class, new DownloadHandlerImpl());
+        configureField(m_agentContext, IdentificationHandler.class, new IdentificationHandlerImpl());
         configureField(m_agentContext, ScheduledExecutorService.class, m_executorService);
         configureField(m_agentContext, AgentUpdateHandler.class, m_agentUpdateHandler);
 
@@ -165,7 +165,8 @@ public class Activator extends Dependenc
 
         m_internalLogService.log(LogService.LOG_INFO, "Starting agent...");
         invokeMethod(m_internalDeploymentAdmin, "start", new Class<?>[] {}, new Object[] {});
-        invokeMethod(m_agentContext, "start", new Class<?>[] {}, new Object[] {});
+
+        m_agentContext.start();
 
         m_internalLogService.log(LogService.LOG_DEBUG, "* agent control service registered");
         m_agentControlComponent = createComponent()
@@ -196,10 +197,6 @@ public class Activator extends Dependenc
         else {
             m_internalLogService.log(LogService.LOG_DEBUG, "* auditlog listener disabled");
         }
-        // at this point we know the agent has started, so any updater bundle that
-        // might still be running can be uninstalled
-        // FIXME move to handlers own life cycle
-        m_agentUpdateHandler.uninstallUpdaterBundle();
         m_internalLogService.log(LogService.LOG_INFO, "Agent started!");
     }
 
@@ -221,6 +218,7 @@ public class Activator extends Dependenc
             m_internalEventAdmin.unregisterHandler(m_eventLoggerImpl);
         }
 
+        m_agentContext.stop();
         invokeMethod(m_internalDeploymentAdmin, "stop", new Class<?>[] {}, new Object[] {});
         m_internalLogService.log(LogService.LOG_INFO, "Agent stopped!");
     }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java Wed Aug 21 15:34:16 2013
@@ -18,11 +18,11 @@
  */
 package org.apache.ace.agent.impl;
 
-import static org.apache.ace.agent.impl.ReflectionUtil.invokeMethod;
-
 import java.io.File;
 import java.util.concurrent.ScheduledExecutorService;
 
+import org.apache.ace.agent.AgentContext;
+import org.apache.ace.agent.AgentContextAware;
 import org.apache.ace.agent.AgentControl;
 import org.apache.ace.agent.AgentUpdateHandler;
 import org.apache.ace.agent.ConfigurationHandler;
@@ -48,8 +48,9 @@ public class AgentContextImpl implements
     private volatile DeploymentHandler m_deploymentHandler;
     private volatile DownloadHandler m_downloadHandler;
     private volatile ConnectionHandler m_connectionHandler;
-    private volatile ScheduledExecutorService m_executorService;
     private volatile AgentUpdateHandler m_agentUpdateHandler;
+
+    private volatile ScheduledExecutorService m_executorService;
     private volatile LogService m_logService;
     private volatile EventAdmin m_eventAdmin;
 
@@ -60,7 +61,37 @@ public class AgentContextImpl implements
     }
 
     public void start() throws Exception {
-        invokeMethod(m_configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        startHandler(m_agentControl);
+        startHandler(m_configurationHandler);
+        startHandler(m_identificationHandler);
+        startHandler(m_discoveryHandler);
+        startHandler(m_deploymentHandler);
+        startHandler(m_downloadHandler);
+        startHandler(m_connectionHandler);
+        startHandler(m_agentUpdateHandler);
+        startHandler(m_agentControl);
+    }
+
+    public void stop() throws Exception {
+        stopHandler(m_agentControl);
+        stopHandler(m_configurationHandler);
+        stopHandler(m_identificationHandler);
+        stopHandler(m_discoveryHandler);
+        stopHandler(m_deploymentHandler);
+        stopHandler(m_downloadHandler);
+        stopHandler(m_connectionHandler);
+        stopHandler(m_agentUpdateHandler);
+        stopHandler(m_agentControl);
+    }
+
+    private void startHandler(Object handler) throws Exception {
+        if (handler instanceof AgentContextAware)
+            ((AgentContextAware) handler).start(this);
+    }
+
+    private void stopHandler(Object handler) throws Exception {
+        if (handler instanceof AgentContextAware)
+            ((AgentContextAware) handler).stop();
     }
 
     @Override

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentControlImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentControlImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentControlImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentControlImpl.java Wed Aug 21 15:34:16 2013
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.AgentControl;
 import org.apache.ace.agent.AgentUpdateHandler;
 import org.apache.ace.agent.ConfigurationHandler;

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java Wed Aug 21 15:34:16 2013
@@ -43,17 +43,25 @@ import org.osgi.framework.Version;
 import org.osgi.util.tracker.ServiceTracker;
 
 public class AgentUpdateHandlerImpl extends UpdateHandlerBase implements AgentUpdateHandler {
+
     private static final int TIMEOUT = 15000;
     private static final String UPDATER_VERSION = "1.0.0";
     private static final String UPDATER_SYMBOLICNAME = "org.apache.ace.agent.updater";
+
     private BundleContext m_bundleContext;
 
-    public AgentUpdateHandlerImpl(AgentContext agentContext, BundleContext bundleContext) {
-        super(agentContext);
+    public AgentUpdateHandlerImpl(BundleContext bundleContext) {
         m_bundleContext = bundleContext;
     }
 
-    public void uninstallUpdaterBundle() throws BundleException {
+    @Override
+    public void onStart() throws Exception {
+        // at this point we know the agent has started, so any updater bundle that
+        // might still be running can be uninstalled
+        uninstallUpdaterBundle();
+    }
+
+    private void uninstallUpdaterBundle() throws BundleException {
         for (Bundle b : m_bundleContext.getBundles()) {
             if (UPDATER_SYMBOLICNAME.equals(b.getSymbolicName())) {
                 try {

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java Wed Aug 21 15:34:16 2013
@@ -37,7 +37,7 @@ import org.osgi.service.log.LogService;
  * Default configuration handler that reads the serverURL(s) from the configuration using key
  * {@link DISCOVERY_CONFIG_KEY}.
  */
-public class ConfigurationHandlerImpl implements ConfigurationHandler {
+public class ConfigurationHandlerImpl extends HandlerBase implements ConfigurationHandler {
 
     /** Directory name use for storage. It is relative to the agent context work directory. */
     public static final String CONFIG_STORAGE_SUBDIR = "config";
@@ -45,14 +45,10 @@ public class ConfigurationHandlerImpl im
     /** File name use for storage. */
     public static final String CONFIG_STORAGE_FILENAME = "config.properties";
 
-    private final AgentContext m_agentContext;
     private Properties m_configProps = null;
 
-    public ConfigurationHandlerImpl(AgentContext agentContext) {
-        m_agentContext = agentContext;
-    }
-
-    public void start() throws Exception {
+    @Override
+    public void onStart() {
         synchronized (this) {
             loadSystemProps();
         }
@@ -159,7 +155,7 @@ public class ConfigurationHandlerImpl im
             loadConfig();
         }
         catch (IOException e) {
-            m_agentContext.getLogService().log(LogService.LOG_ERROR, "Load config failed", e);
+            getAgentContext().getLogService().log(LogService.LOG_ERROR, "Load config failed", e);
             throw new IllegalStateException("Load config failed", e);
         }
     }
@@ -172,7 +168,7 @@ public class ConfigurationHandlerImpl im
             storeConfig();
         }
         catch (IOException e) {
-            m_agentContext.getLogService().log(LogService.LOG_ERROR, "Storing config failed", e);
+            getAgentContext().getLogService().log(LogService.LOG_ERROR, "Storing config failed", e);
             throw new IllegalStateException("Store config failed", e);
         }
     }
@@ -208,7 +204,7 @@ public class ConfigurationHandlerImpl im
     }
 
     private File getConfigDir() throws IOException {
-        File dir = new File(m_agentContext.getWorkDir(), CONFIG_STORAGE_SUBDIR);
+        File dir = new File(getAgentContext().getWorkDir(), CONFIG_STORAGE_SUBDIR);
         if (!dir.exists() && !dir.mkdir())
             throw new IOException("Unable to acces configuration directory: " + dir.getAbsolutePath());
         return dir;
@@ -218,5 +214,4 @@ public class ConfigurationHandlerImpl im
         if (value == null || value.equals(""))
             throw new IllegalArgumentException("Can not pass null as an argument");
     }
-
 }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConnectionHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConnectionHandlerImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConnectionHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConnectionHandlerImpl.java Wed Aug 21 15:34:16 2013
@@ -42,7 +42,7 @@ import org.apache.commons.codec.binary.B
  * Default connection handler with support for BASIC authentication and HTTPS client certificates.
  * 
  */
-public class ConnectionHandlerImpl implements ConnectionHandler {
+public class ConnectionHandlerImpl extends HandlerBase implements ConnectionHandler {
 
     public static final String PROP_AUTHTYPE = "agent.authType";
     public static final String PROP_AUTHUSER = "agent.authUser";
@@ -92,12 +92,6 @@ public class ConnectionHandlerImpl imple
         }
     }
 
-    private final AgentContext m_agentContext;
-
-    public ConnectionHandlerImpl(AgentContext agentContext) {
-        m_agentContext = agentContext;
-    }
-
     @Override
     public URLConnection getConnection(URL url) throws IOException {
         URLConnection connection = (HttpURLConnection) url.openConnection();
@@ -186,7 +180,7 @@ public class ConnectionHandlerImpl imple
     }
 
     private String getConfigStringValue(String key) {
-        return m_agentContext.getConfigurationHandler().get(key, null);
+        return getAgentContext().getConfigurationHandler().get(key, null);
     }
 
     private static KeyManager[] getKeyManagerFactory(String keystoreFile, String storePass) throws IOException, GeneralSecurityException {

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java Wed Aug 21 15:34:16 2013
@@ -25,6 +25,7 @@ import java.util.SortedSet;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.AgentControl;
 import org.apache.ace.agent.AgentUpdateHandler;
 import org.apache.ace.agent.ConfigurationHandler;

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DeploymentHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DeploymentHandlerImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DeploymentHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DeploymentHandlerImpl.java Wed Aug 21 15:34:16 2013
@@ -34,12 +34,9 @@ import org.osgi.service.deploymentadmin.
 
 public class DeploymentHandlerImpl extends UpdateHandlerBase implements DeploymentHandler {
 
-    private final AgentContext m_agentContext;
     private final DeploymentAdmin m_deploymentAdmin;
 
-    public DeploymentHandlerImpl(AgentContext agentContext, DeploymentAdmin deploymentAdmin) {
-        super(agentContext);
-        m_agentContext = agentContext;
+    public DeploymentHandlerImpl(DeploymentAdmin deploymentAdmin) {
         m_deploymentAdmin = deploymentAdmin;
     }
 

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java Wed Aug 21 15:34:16 2013
@@ -33,7 +33,7 @@ import org.osgi.service.log.LogService;
  * Default discovery handler that reads the serverURL(s) from the configuration using key {@link DISCOVERY_CONFIG_KEY}.
  * 
  */
-public class DiscoveryHandlerImpl implements DiscoveryHandler {
+public class DiscoveryHandlerImpl extends HandlerBase implements DiscoveryHandler {
 
     public static final String CONFIG_KEY_BASE = ConfigurationHandlerImpl.CONFIG_KEY_NAMESPACE + ".discovery";
 
@@ -44,18 +44,12 @@ public class DiscoveryHandlerImpl implem
     public static final String CONFIG_KEY_SERVERURLS = CONFIG_KEY_BASE + ".serverUrls";
     public static final String CONFIG_DEFAULT_SERVERURLS = "http://localhost:8080";
 
-    private final AgentContext m_agentContext;
-
-    public DiscoveryHandlerImpl(AgentContext agentContext) throws Exception {
-        m_agentContext = agentContext;
-    }
-
     // TODO Pretty naive implementation below. It always takes the first configured URL it can connect to and is not
     // thread-safe.
     @Override
     public URL getServerUrl() {
-        ConfigurationHandler configurationHandler = m_agentContext.getConfigurationHandler();
-        LogService logService = m_agentContext.getLogService();
+        ConfigurationHandler configurationHandler = getAgentContext().getConfigurationHandler();
+        LogService logService = getAgentContext().getLogService();
 
         String configValue = configurationHandler.get(CONFIG_KEY_SERVERURLS, CONFIG_DEFAULT_SERVERURLS);
         URL url = null;
@@ -90,7 +84,7 @@ public class DiscoveryHandlerImpl implem
     private final Map<String, CheckedURL> m_checkedURLs = new HashMap<String, DiscoveryHandlerImpl.CheckedURL>();
 
     private URL checkURL(String serverURL) {
-        LogService logService = m_agentContext.getLogService();
+        LogService logService = getAgentContext().getLogService();
 
         CheckedURL checked = m_checkedURLs.get(serverURL);
         if (checked != null && checked.timestamp > (System.currentTimeMillis() - CACHE_TIME)) {
@@ -113,7 +107,7 @@ public class DiscoveryHandlerImpl implem
     private void tryConnect(URL serverURL) throws IOException {
         URLConnection connection = null;
         try {
-            connection = m_agentContext.getConnectionHandler().getConnection(serverURL);
+            connection = getAgentContext().getConnectionHandler().getConnection(serverURL);
             connection.connect();
         }
         finally {

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandlerImpl.java Wed Aug 21 15:34:16 2013
@@ -25,13 +25,7 @@ import org.apache.ace.agent.DownloadHand
 import org.apache.ace.agent.DownloadHandler;
 import org.osgi.service.log.LogService;
 
-public class DownloadHandlerImpl implements DownloadHandler {
-
-    private final AgentContext m_agentContext;
-
-    public DownloadHandlerImpl(AgentContext agentContext) {
-        m_agentContext = agentContext;
-    }
+public class DownloadHandlerImpl extends HandlerBase implements DownloadHandler {
 
     @Override
     public DownloadHandle getHandle(URL url) {
@@ -47,18 +41,18 @@ public class DownloadHandlerImpl impleme
      * handle support methods
      */
     ExecutorService getExecutor() {
-        return m_agentContext.getExecutorService();
+        return getAgentContext().getExecutorService();
     }
 
     void logDebug(String message, Object... args) {
-        m_agentContext.getLogService().log(LogService.LOG_DEBUG, message);
+        getAgentContext().getLogService().log(LogService.LOG_DEBUG, message);
     }
 
     void logInfo(String message, Object... args) {
-        m_agentContext.getLogService().log(LogService.LOG_INFO, message);
+        getAgentContext().getLogService().log(LogService.LOG_INFO, message);
     }
 
     void logWarning(String message, Object... args) {
-        m_agentContext.getLogService().log(LogService.LOG_WARNING, message);
+        getAgentContext().getLogService().log(LogService.LOG_WARNING, message);
     }
 }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackChannelImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackChannelImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackChannelImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackChannelImpl.java Wed Aug 21 15:34:16 2013
@@ -43,6 +43,7 @@ import java.util.Map.Entry;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.ConnectionHandler;
 import org.apache.ace.agent.FeedbackChannel;
 import org.apache.ace.agent.RetryAfterException;

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java Wed Aug 21 15:34:16 2013
@@ -26,7 +26,7 @@ import org.apache.ace.agent.Identificati
  * {@link IDENTIFICATION_CONFIG_KEY}.
  * 
  */
-public class IdentificationHandlerImpl implements IdentificationHandler {
+public class IdentificationHandlerImpl extends HandlerBase implements IdentificationHandler {
 
     public static final String CONFIG_KEY_BASE = ConfigurationHandlerImpl.CONFIG_KEY_NAMESPACE + ".identification";
 
@@ -37,15 +37,9 @@ public class IdentificationHandlerImpl i
     public static final String CONFIG_KEY_IDENTIFICATION = CONFIG_KEY_BASE + ".agentId";
     public static final String CONFIG_DEFAULT_AGENTID = "defaultTargetID";
 
-    private final AgentContext m_agentContext;
-
-    public IdentificationHandlerImpl(AgentContext agentContext) {
-        m_agentContext = agentContext;
-    }
-
     @Override
     public String getAgentId() {
-        ConfigurationHandler configurationHandler = m_agentContext.getConfigurationHandler();
+        ConfigurationHandler configurationHandler = getAgentContext().getConfigurationHandler();
         String configValue = configurationHandler.get(CONFIG_KEY_IDENTIFICATION, CONFIG_DEFAULT_AGENTID);
         return configValue;
     }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java Wed Aug 21 15:34:16 2013
@@ -33,12 +33,7 @@ import org.apache.ace.agent.DownloadHand
 import org.apache.ace.agent.RetryAfterException;
 import org.osgi.framework.Version;
 
-public class UpdateHandlerBase {
-    protected AgentContext m_agentContext;
-
-    public UpdateHandlerBase(AgentContext agentContext) {
-        m_agentContext = agentContext;
-    }
+public class UpdateHandlerBase extends HandlerBase {
 
     protected SortedSet<Version> getAvailableVersions(URL endpoint) throws RetryAfterException, IOException {
         SortedSet<Version> versions = new TreeSet<Version>();
@@ -116,16 +111,16 @@ public class UpdateHandlerBase {
     }
 
     protected DownloadHandle getDownloadHandle(URL packageURL) {
-        return m_agentContext.getDownloadHandler().getHandle(packageURL);
+        return getAgentContext().getDownloadHandler().getHandle(packageURL);
     }
 
     protected String getIdentification() {
-        return m_agentContext.getIdentificationHandler().getAgentId();
+        return getAgentContext().getIdentificationHandler().getAgentId();
     }
 
     protected URL getServerURL() throws RetryAfterException {
         // FIXME not sure if this is the proper place
-        URL serverURL = m_agentContext.getDiscoveryHandler().getServerUrl();
+        URL serverURL = getAgentContext().getDiscoveryHandler().getServerUrl();
         if (serverURL == null) {
             throw new RetryAfterException(10);
         }
@@ -133,6 +128,6 @@ public class UpdateHandlerBase {
     }
 
     private URLConnection getConnection(URL url) throws IOException {
-        return m_agentContext.getConnectionHandler().getConnection(url);
+        return getAgentContext().getConnectionHandler().getConnection(url);
     }
 }

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java Wed Aug 21 15:34:16 2013
@@ -23,9 +23,9 @@ import static org.testng.Assert.assertEq
 import static org.testng.Assert.assertNotNull;
 
 import java.io.File;
-import java.io.IOException;
 import java.lang.reflect.Method;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.ConfigurationHandler;
 import org.apache.ace.agent.testutil.BaseAgentTest;
 import org.testng.annotations.AfterMethod;
@@ -56,10 +56,10 @@ public class ConfigurationHandlerImplTes
     }
 
     @Test
-    public void testConfigClean() throws IOException {
+    public void testConfigClean() throws Exception {
 
-        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         assertNotNull(configurationHandler.keySet());
         assertEquals(0, configurationHandler.keySet().size());
@@ -67,8 +67,8 @@ public class ConfigurationHandlerImplTes
 
         // should be persisted
 
-        configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         assertNotNull(configurationHandler.keySet());
         assertEquals(0, configurationHandler.keySet().size());
@@ -76,7 +76,7 @@ public class ConfigurationHandlerImplTes
     }
 
     @Test
-    public void testConfigSystemProps() throws IOException {
+    public void testConfigSystemProps() throws Exception {
 
         String systemKey1 = ConfigurationHandlerImpl.CONFIG_KEY_NAMESPACE + "key1";
         String systemKey2 = ConfigurationHandlerImpl.CONFIG_KEY_NAMESPACE + "key2";
@@ -84,8 +84,8 @@ public class ConfigurationHandlerImplTes
         System.setProperty(systemKey1, "value1");
         System.setProperty(systemKey2, "value2");
 
-        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         assertNotNull(configurationHandler.keySet());
         assertEquals(2, configurationHandler.keySet().size());
@@ -97,8 +97,8 @@ public class ConfigurationHandlerImplTes
         System.clearProperty(systemKey1);
         System.clearProperty(systemKey2);
 
-        configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         assertNotNull(configurationHandler.keySet());
         assertEquals(2, configurationHandler.keySet().size());
@@ -113,8 +113,8 @@ public class ConfigurationHandlerImplTes
         configurationHandler.put(systemKey1, "newvalue1");
         configurationHandler.put(systemKey2, "newvalue2");
 
-        configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         assertNotNull(configurationHandler.keySet());
         assertEquals(2, configurationHandler.keySet().size());
@@ -128,8 +128,8 @@ public class ConfigurationHandlerImplTes
         System.setProperty(systemKey1 + ConfigurationHandlerImpl.CONFIG_KEY_OVERRIDEPOSTFIX, "true");
         System.setProperty(systemKey2 + ConfigurationHandlerImpl.CONFIG_KEY_OVERRIDEPOSTFIX, "true");
 
-        configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         assertNotNull(configurationHandler.keySet());
         assertEquals(2, configurationHandler.keySet().size());
@@ -138,10 +138,10 @@ public class ConfigurationHandlerImplTes
     }
 
     @Test
-    public void testConfigBooleanProps() throws IOException {
+    public void testConfigBooleanProps() throws Exception {
 
-        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         configurationHandler.putBoolean("boolean1", true);
         configurationHandler.putBoolean("boolean2", false);
@@ -154,10 +154,10 @@ public class ConfigurationHandlerImplTes
     }
 
     @Test
-    public void testConfigLongProps() throws IOException {
+    public void testConfigLongProps() throws Exception {
 
-        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_agentContext);
-        ReflectionUtil.invokeMethod(configurationHandler, "start", new Class<?>[] {}, new Object[] {});
+        ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl();
+        startHandler(configurationHandler, m_agentContext);
 
         configurationHandler.putLong("long1", 42);
         configurationHandler.putLong("long2", 4l);

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConnectionHandlerImplTest.java Wed Aug 21 15:34:16 2013
@@ -29,14 +29,13 @@ import static org.testng.Assert.assertEq
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.ConfigurationHandler;
 import org.apache.ace.agent.ConnectionHandler;
 import org.apache.ace.agent.testutil.BaseAgentTest;
@@ -72,13 +71,14 @@ public class ConnectionHandlerImplTest e
 
     }
 
-    private Map<String, String> m_configuration = new HashMap<String, String>();
-    private ConnectionHandler m_connectionHandler;
     private TestWebServer m_webServer;
     private String m_user = "Mickey";
     private String m_pass = "Mantle";
     private URL m_basicAuthURL;
+
+    private AgentContext m_agentContext;
     private ConfigurationHandler m_configurationHandler;
+    private ConnectionHandler m_connectionHandler;
 
     @BeforeTest
     public void setUpAgain() throws Exception {
@@ -90,15 +90,17 @@ public class ConnectionHandlerImplTest e
         m_webServer.start();
 
         m_configurationHandler = addTestMock(ConfigurationHandler.class);
-        AgentContext agentContext = addTestMock(AgentContext.class);
-        m_connectionHandler = new ConnectionHandlerImpl(agentContext);
-
-        expect(agentContext.getConfigurationHandler()).andReturn(m_configurationHandler).anyTimes();
+        m_agentContext = addTestMock(AgentContext.class);
+        expect(m_agentContext.getConfigurationHandler()).andReturn(m_configurationHandler).anyTimes();
         replayTestMocks();
+
+        m_connectionHandler = new ConnectionHandlerImpl();
+        startHandler(m_connectionHandler, m_agentContext);
     }
 
     @AfterTest
     public void tearDownAgain() throws Exception {
+        stopHandler(m_connectionHandler);
         m_webServer.stop();
         verifyTestMocks();
     }
@@ -110,7 +112,7 @@ public class ConnectionHandlerImplTest e
         replay(m_configurationHandler);
         HttpURLConnection connection = (HttpURLConnection) m_connectionHandler.getConnection(m_basicAuthURL);
         assertEquals(connection.getResponseCode(), HttpServletResponse.SC_FORBIDDEN);
-        
+
     }
 
     @Test

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/CustomControllerTest.java Wed Aug 21 15:34:16 2013
@@ -30,6 +30,7 @@ import java.net.URL;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.AgentControl;
 import org.apache.ace.agent.DeploymentHandler;
 import org.apache.ace.agent.DownloadHandle;

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerImplTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerImplTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DeploymentHandlerImplTest.java Wed Aug 21 15:34:16 2013
@@ -46,7 +46,9 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.ace.agent.AgentConstants;
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.ConfigurationHandler;
+import org.apache.ace.agent.DeploymentHandler;
 import org.apache.ace.agent.DiscoveryHandler;
 import org.apache.ace.agent.IdentificationHandler;
 import org.apache.ace.agent.testutil.BaseAgentTest;
@@ -103,7 +105,6 @@ public class DeploymentHandlerImplTest e
         }
     }
 
-    private DeploymentHandlerImpl m_deploymentHandler;
     private TestWebServer m_webserver;
     private File m_200file;
     private Version m_version1 = Version.parseVersion("1.0.0");
@@ -111,6 +112,8 @@ public class DeploymentHandlerImplTest e
     private Version m_version3 = Version.parseVersion("3.0.0");
     long m_remotePackageSize = 0l;
 
+    private DeploymentHandler m_deploymentHandler;
+
     @BeforeTest
     public void setUpOnceAgain() throws Exception {
 
@@ -168,14 +171,20 @@ public class DeploymentHandlerImplTest e
         expect(agentContext.getIdentificationHandler()).andReturn(identificationHandler).anyTimes();
         expect(agentContext.getDiscoveryHandler()).andReturn(discoveryHandler).anyTimes();
         expect(agentContext.getConfigurationHandler()).andReturn(configurationHandler).anyTimes();
-        expect(agentContext.getConnectionHandler()).andReturn(new ConnectionHandlerImpl(agentContext)).anyTimes();
+
+        ConnectionHandlerImpl connectionHandler = new ConnectionHandlerImpl();
+        connectionHandler.start(agentContext);
+        expect(agentContext.getConnectionHandler()).andReturn(connectionHandler).anyTimes();
 
         replayTestMocks();
-        m_deploymentHandler = new DeploymentHandlerImpl(agentContext, deploymentAdmin);
+
+        m_deploymentHandler = new DeploymentHandlerImpl(deploymentAdmin);
+        startHandler(m_deploymentHandler, agentContext);
     }
 
     @AfterTest
     public void tearDownOnceAgain() throws Exception {
+        stopHandler(m_deploymentHandler);
         verifyTestMocks();
         m_webserver.stop();
     }

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java Wed Aug 21 15:34:16 2013
@@ -29,6 +29,7 @@ import static org.testng.Assert.assertNu
 
 import java.net.URL;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.ConfigurationHandler;
 import org.apache.ace.agent.ConnectionHandler;
 import org.apache.ace.agent.DiscoveryHandler;
@@ -49,7 +50,8 @@ public class DiscoveryHandlerImplTest ex
     private URL m_availableURL;
     private URL m_unavailableURL;
     private DiscoveryHandler m_discoveryHandler;
-    private ConfigurationHandler configurationHandler;
+    private ConfigurationHandler m_configurationHandler;
+    private ConnectionHandler m_connectionHandler;
 
     @BeforeTest
     public void setUpAgain() throws Exception {
@@ -60,104 +62,111 @@ public class DiscoveryHandlerImplTest ex
         m_unavailableURL = new URL("http://localhost:9999");
 
         AgentContext agentContext = addTestMock(AgentContext.class);
+
         LogService logService = addTestMock(LogService.class);
         resetToNice(logService);
-        m_discoveryHandler = new DiscoveryHandlerImpl(agentContext);
-        configurationHandler = addTestMock(ConfigurationHandler.class);
-        ConnectionHandler connectionHandler = new ConnectionHandlerImpl(agentContext);
-        expect(agentContext.getConfigurationHandler()).andReturn(configurationHandler).anyTimes();
-        expect(agentContext.getConnectionHandler()).andReturn(connectionHandler).anyTimes();
+
+        m_discoveryHandler = new DiscoveryHandlerImpl();
+        m_connectionHandler = new ConnectionHandlerImpl();
+        m_configurationHandler = addTestMock(ConfigurationHandler.class);
+
+        expect(agentContext.getConfigurationHandler()).andReturn(m_configurationHandler).anyTimes();
+        expect(agentContext.getConnectionHandler()).andReturn(m_connectionHandler).anyTimes();
         expect(agentContext.getLogService()).andReturn(logService).anyTimes();
 
         replayTestMocks();
+        startHandler(m_connectionHandler, agentContext);
+        startHandler(m_discoveryHandler, agentContext);
     }
 
     @AfterTest
     public void tearDownAgain() throws Exception {
-        m_webServer.stop();
+        stopHandler(m_connectionHandler);
+        stopHandler(m_discoveryHandler);
         verifyTestMocks();
+        m_webServer.stop();
     }
 
     @Test
     public void testAvailableURL() throws Exception {
-        reset(configurationHandler);
-        expect(configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
+        reset(m_configurationHandler);
+        expect(m_configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
             .andReturn(null).anyTimes();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn(m_availableURL.toExternalForm()).anyTimes();
-        replay(configurationHandler);
+        replay(m_configurationHandler);
         assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
     }
 
     @Test
     public void testUnavailableURL_unavailable() throws Exception {
-        reset(configurationHandler);
-        expect(configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
+        reset(m_configurationHandler);
+        expect(m_configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
             .andReturn(null).anyTimes();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn(m_unavailableURL.toExternalForm()).anyTimes();
-        replay(configurationHandler);
+        replay(m_configurationHandler);
         assertNull(m_discoveryHandler.getServerUrl());
     }
 
     @Test
     public void testUnavailableAfterConfigUpdate() throws Exception {
-        reset(configurationHandler);
-        expect(configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
+        reset(m_configurationHandler);
+        expect(m_configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
             .andReturn(null).anyTimes();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn(m_availableURL.toExternalForm()).once();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn(m_unavailableURL.toExternalForm()).once();
-        replay(configurationHandler);
+        replay(m_configurationHandler);
         assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
         assertNull(m_discoveryHandler.getServerUrl());
     }
 
     @Test
     public void testAvailableAfterConfigUpdate() throws Exception {
-        reset(configurationHandler);
-        expect(configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
+        reset(m_configurationHandler);
+        expect(m_configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
             .andReturn(null).anyTimes();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn(m_unavailableURL.toExternalForm()).once();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn(m_availableURL.toExternalForm()).once();
-        replay(configurationHandler);
+        replay(m_configurationHandler);
         assertNull(m_discoveryHandler.getServerUrl());
         assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
     }
 
     @Test
     public void testAvailableAfterUnavailableURL() throws Exception {
-        reset(configurationHandler);
-        expect(configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
+        reset(m_configurationHandler);
+        expect(m_configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
             .andReturn(null).anyTimes();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn(m_unavailableURL.toExternalForm() + "," + m_availableURL.toExternalForm()).once();
-        replay(configurationHandler);
+        replay(m_configurationHandler);
         assertEquals(m_discoveryHandler.getServerUrl(), m_availableURL);
     }
 
     @Test
     public void testEmptyURLConfig() throws Exception {
-        reset(configurationHandler);
-        expect(configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
+        reset(m_configurationHandler);
+        expect(m_configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
             .andReturn(null).anyTimes();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn("").once();
-        replay(configurationHandler);
+        replay(m_configurationHandler);
         assertNull(m_discoveryHandler.getServerUrl());
     }
 
     @Test
     public void testBadURLConfig() throws Exception {
-        reset(configurationHandler);
-        expect(configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
+        reset(m_configurationHandler);
+        expect(m_configurationHandler.get(eq(ConnectionHandlerImpl.PROP_AUTHTYPE), anyObject(String.class)))
             .andReturn(null).anyTimes();
-        expect(configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
+        expect(m_configurationHandler.get(eq(DiscoveryHandlerImpl.CONFIG_KEY_SERVERURLS), anyObject(String.class)))
             .andReturn("foobar").once();
-        replay(configurationHandler);
+        replay(m_configurationHandler);
         assertNull(m_discoveryHandler.getServerUrl());
     }
 }

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandlerTest.java Wed Aug 21 15:34:16 2013
@@ -18,11 +18,14 @@
  */
 package org.apache.ace.agent.impl;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.notNull;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
-import static org.testng.Assert.*;
+import static org.testng.Assert.assertSame;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -45,9 +48,11 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.DownloadHandle;
 import org.apache.ace.agent.DownloadHandle.CompletedListener;
 import org.apache.ace.agent.DownloadHandle.ProgressListener;
+import org.apache.ace.agent.DownloadHandler;
 import org.apache.ace.agent.DownloadResult;
 import org.apache.ace.agent.DownloadState;
 import org.apache.ace.agent.testutil.BaseAgentTest;
@@ -78,7 +83,7 @@ public class DownloadHandlerTest extends
         }
     }
 
-    private DownloadHandlerImpl m_handler;
+    private DownloadHandler m_downloadHandler;
     private TestWebServer m_webServer;
     private URL m_200url;
     private File m_200file;
@@ -113,25 +118,27 @@ public class DownloadHandlerTest extends
 
         AgentContext agentContext = addTestMock(AgentContext.class);
         expect(agentContext.getExecutorService()).andReturn(executorService).anyTimes();
-        
+
         LogService logService = addTestMock(LogService.class);
         expect(agentContext.getLogService()).andReturn(logService).anyTimes();
         logService.log(anyInt(), notNull(String.class));
         expectLastCall().anyTimes();
 
         replayTestMocks();
-        m_handler = new DownloadHandlerImpl(agentContext);
+        m_downloadHandler = new DownloadHandlerImpl();
+        startHandler(m_downloadHandler, agentContext);
     }
 
     @AfterTest
     public void tearDownOnceAgain() throws Exception {
+        stopHandler(m_downloadHandler);
         verifyTestMocks();
         m_webServer.stop();
     }
 
     @Test
     public void testSuccessful_noresume_result() throws Exception {
-        final DownloadHandle handle = m_handler.getHandle(m_200url).start();
+        final DownloadHandle handle = m_downloadHandler.getHandle(m_200url).start();
         final DownloadResult result = handle.result();
         assertSuccessFul(result, 200, m_200digest);
     }
@@ -140,7 +147,7 @@ public class DownloadHandlerTest extends
     public void testSuccessful_noresume_listener() throws Exception {
         final CountDownLatch latch = new CountDownLatch(1);
         final List<DownloadResult> holder = new ArrayList<DownloadResult>();
-        final DownloadHandle handle = m_handler.getHandle(m_200url)
+        final DownloadHandle handle = m_downloadHandler.getHandle(m_200url)
             .setCompletionListener(new CompletedListener() {
                 @Override
                 public void completed(DownloadResult result) {
@@ -155,7 +162,7 @@ public class DownloadHandlerTest extends
 
     @Test
     public void testSuccessful_resume_result() throws Exception {
-        final DownloadHandle handle = m_handler.getHandle(m_200url);
+        final DownloadHandle handle = m_downloadHandler.getHandle(m_200url);
         handle.setProgressListener(new ProgressListener() {
             @Override
             public void progress(long contentLength, long progress) {
@@ -169,7 +176,7 @@ public class DownloadHandlerTest extends
 
     @Test
     public void testFailedIO_nostatus_result() throws Exception {
-        DownloadHandle handle = m_handler.getHandle(m_200url, 2048);
+        DownloadHandle handle = m_downloadHandler.getHandle(m_200url, 2048);
 
         DownloadResult result = ((DownloadHandleImpl) handle).start(DownloadCallableImpl.FAIL_OPENCONNECTION).result();
         assertFailed(result, 0);
@@ -197,13 +204,13 @@ public class DownloadHandlerTest extends
 
     @Test
     public void testFailed404_noresume_result() throws Exception {
-        final DownloadResult result = m_handler.getHandle(m_404url).start().result();
+        final DownloadResult result = m_downloadHandler.getHandle(m_404url).start().result();
         assertFailed(result, 404);
     }
 
     @Test
     public void testFailed503_noresume_result() throws Exception {
-        DownloadResult result = m_handler.getHandle(m_503url).start().result();
+        DownloadResult result = m_downloadHandler.getHandle(m_503url).start().result();
         assertFailed(result, 503);
         assertNotNull(result.getHeaders().get("Retry-After"), "Expected a Retry-After header from error servlet");
         assertNotNull(result.getHeaders().get("Retry-After").get(0), "Expected a Retry-After header from error servlet");

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationHandlerImplTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationHandlerImplTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/IdentificationHandlerImplTest.java Wed Aug 21 15:34:16 2013
@@ -26,6 +26,7 @@ import static org.easymock.EasyMock.rese
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
 
+import org.apache.ace.agent.AgentContext;
 import org.apache.ace.agent.ConfigurationHandler;
 import org.apache.ace.agent.IdentificationHandler;
 import org.apache.ace.agent.testutil.BaseAgentTest;
@@ -44,14 +45,17 @@ public class IdentificationHandlerImplTe
     @BeforeTest
     public void setUpAgain() throws Exception {
         AgentContext agentContext = addTestMock(AgentContext.class);
-        m_identificationHandler = new IdentificationHandlerImpl(agentContext);
+        m_identificationHandler = new IdentificationHandlerImpl();
         m_configurationHandler = addTestMock(ConfigurationHandler.class);
         expect(agentContext.getConfigurationHandler()).andReturn(m_configurationHandler).anyTimes();
         replayTestMocks();
+
+        startHandler(m_identificationHandler, agentContext);
     }
 
     @AfterTest
     public void tearDownAgain() throws Exception {
+        stopHandler(m_identificationHandler);
         verifyTestMocks();
     }
 

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java?rev=1516190&r1=1516189&r2=1516190&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java Wed Aug 21 15:34:16 2013
@@ -27,12 +27,15 @@ import java.util.HashSet;
 import java.util.Set;
 import java.util.Stack;
 
+import org.apache.ace.agent.AgentContext;
+import org.apache.ace.agent.AgentContextAware;
+
 /**
  * Simple base class.
  */
 public abstract class BaseAgentTest {
 
-    Set<Object> m_mocks = new HashSet<Object>();
+    private Set<Object> m_mocks = new HashSet<Object>();
 
     protected <T extends Object> T addTestMock(Class<T> clazz) {
         T mock = createMock(clazz);
@@ -58,6 +61,16 @@ public abstract class BaseAgentTest {
         return new File("generated");
     }
 
+    protected void startHandler(Object handler, AgentContext agentContext) throws Exception {
+        if (handler instanceof AgentContextAware)
+            ((AgentContextAware) handler).start(agentContext);
+    }
+
+    protected void stopHandler(Object handler) throws Exception {
+        if (handler instanceof AgentContextAware)
+            ((AgentContextAware) handler).stop();
+    }
+
     protected void cleanDir(File dir) {
         if (!dir.isDirectory())
             throw new IllegalStateException();