ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1517438 - in /ace/trunk/org.apache.ace.agent: build.xml src/org/apache/ace/agent/impl/Activator.java src/org/apache/ace/agent/impl/AgentContextImpl.java src/org/apache/ace/agent/impl/DeploymentHandlerImpl.java
Date Mon, 26 Aug 2013 06:58:49 GMT
Author: bramk
Date: Mon Aug 26 06:58:48 2013
New Revision: 1517438

URL: http://svn.apache.org/r1517438
Log:
ACE-347 Extracted internal interface / Added context setters

Modified:
    ace/trunk/org.apache.ace.agent/build.xml
    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/DeploymentHandlerImpl.java

Modified: ace/trunk/org.apache.ace.agent/build.xml
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/build.xml?rev=1517438&r1=1517437&r2=1517438&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/build.xml (original)
+++ ace/trunk/org.apache.ace.agent/build.xml Mon Aug 26 06:58:48 2013
@@ -1,4 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project name="project" default="build"> 
-	<import file="../cnf/build.xml"/>
+<project name="project" default="build">
+
+	<!-- -->
+
+	<import file="../cnf/build.xml" />
 </project>

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=1517438&r1=1517437&r2=1517438&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 Mon Aug 26
06:58:48 2013
@@ -31,13 +31,8 @@ import java.util.concurrent.ScheduledExe
 import java.util.concurrent.ThreadFactory;
 
 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.FeedbackHandler;
 import org.apache.ace.agent.IdentificationHandler;
 import org.apache.felix.deploymentadmin.DeploymentAdminImpl;
 import org.apache.felix.dm.Component;
@@ -63,8 +58,7 @@ public class Activator extends Dependenc
     private AgentContextImpl m_agentContext;
     private AgentControl m_agentControl;
     private ScheduledExecutorService m_executorService;
-    private AgentUpdateHandlerImpl m_agentUpdateHandler; // we use the implementation type
here on purpose
-    private DeploymentAdmin m_internalDeploymentAdmin;
+    private DeploymentAdmin m_deploymentAdmin;
     private Component m_agentControlComponent = null;
     private EventLoggerImpl m_eventLoggerImpl;
     private DefaultController m_defaultController;
@@ -77,27 +71,26 @@ public class Activator extends Dependenc
 
         m_executorService = Executors.newScheduledThreadPool(1, new InternalThreadFactory());
 
-        m_internalDeploymentAdmin = new DeploymentAdminImpl();
-        configureField(m_internalDeploymentAdmin, BundleContext.class, context);
-        configureField(m_internalDeploymentAdmin, PackageAdmin.class, null);
-        configureField(m_internalDeploymentAdmin, EventAdmin.class, new InternalEventAdmin(m_internalEvents));
-        configureField(m_internalDeploymentAdmin, LogService.class, new InternalLogService(m_internalLogger,
"deployment"));
+        m_deploymentAdmin = new DeploymentAdminImpl();
+        configureField(m_deploymentAdmin, BundleContext.class, context);
+        configureField(m_deploymentAdmin, PackageAdmin.class, null);
+        configureField(m_deploymentAdmin, EventAdmin.class, new InternalEventAdmin(m_internalEvents));
+        configureField(m_deploymentAdmin, LogService.class, new InternalLogService(m_internalLogger,
"deployment"));
 
-        m_agentContext = new AgentContextImpl(context.getDataFile(""), m_internalLogger,
m_internalEvents);
+        m_agentContext = new AgentContextImpl(context.getDataFile(""));
         m_agentControl = new AgentControlImpl(m_agentContext);
-        m_agentUpdateHandler = new AgentUpdateHandlerImpl(context);
 
-        // TODO replace with setters
-        configureField(m_agentContext, AgentControl.class, m_agentControl);
-        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);
-        configureField(m_agentContext, FeedbackHandler.class, new FeedbackHandlerImpl());
+        m_agentContext.setLoggingHandler(m_internalLogger);
+        m_agentContext.setEventsHandler(m_internalEvents);
+        m_agentContext.setConfigurationHandler(new ConfigurationHandlerImpl());
+        m_agentContext.setExecutorService(m_executorService);
+        m_agentContext.setConnectionHandler(new ConnectionHandlerImpl());
+        m_agentContext.setIdentificationHandler(new IdentificationHandlerImpl());
+        m_agentContext.setDiscoveryHandler(new DiscoveryHandlerImpl());
+        m_agentContext.setDownloadHandler(new DownloadHandlerImpl());
+        m_agentContext.setDeploymentHandler(new DeploymentHandlerImpl(m_deploymentAdmin));
+        m_agentContext.setAgentUpdateHandler(new AgentUpdateHandlerImpl(context));
+        m_agentContext.setFeedbackHandler(new FeedbackHandlerImpl());
 
         Component agentContextComponent = createComponent()
             .setImplementation(m_agentContext)
@@ -135,14 +128,14 @@ public class Activator extends Dependenc
     synchronized void packageAdminAdded(PackageAdmin packageAdmin) {
         if (m_packageAdmin == null) {
             m_packageAdmin = packageAdmin;
-            configureField(m_internalDeploymentAdmin, PackageAdmin.class, packageAdmin);
+            configureField(m_deploymentAdmin, PackageAdmin.class, packageAdmin);
         }
     }
 
     synchronized void packageAdminRemoved(PackageAdmin packageAdmin) {
         if (m_packageAdmin == packageAdmin) {
             m_packageAdmin = null;
-            configureField(m_internalDeploymentAdmin, PackageAdmin.class, null);
+            configureField(m_deploymentAdmin, PackageAdmin.class, null);
         }
     }
 
@@ -150,7 +143,7 @@ public class Activator extends Dependenc
 
         m_internalLogger.logInfo("activator", "Agent starting...", null);
 
-        invokeMethod(m_internalDeploymentAdmin, "start", new Class<?>[] {}, new Object[]
{});
+        invokeMethod(m_deploymentAdmin, "start", new Class<?>[] {}, new Object[] {});
         m_agentContext.start();
 
         m_internalLogger.logInfo("activator", "Agent control service started", null);
@@ -207,14 +200,14 @@ public class Activator extends Dependenc
         }
 
         m_agentContext.stop();
-        invokeMethod(m_internalDeploymentAdmin, "stop", new Class<?>[] {}, new Object[]
{});
+        invokeMethod(m_deploymentAdmin, "stop", new Class<?>[] {}, new Object[] {});
         m_internalLogger.logInfo("activator", "Agent stopped", null);
     }
 
     /**
      * InternalEvents that posts events to internal handlers and external admins.
      */
-    static class InternalEvents {
+    static class InternalEvents implements EventsHandler {
 
         private final Map<EventHandler, String[]> m_eventHandlers = new HashMap<EventHandler,
String[]>();
 
@@ -287,7 +280,7 @@ public class Activator extends Dependenc
      * Internal logger that writes to system out for now. It minimizes work until it is determined
the loglevel is
      * loggable.
      */
-    static class InternalLogger {
+    static class InternalLogger implements LoggingHandler {
 
         private final int m_level;
 

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=1517438&r1=1517437&r2=1517438&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 Mon
Aug 26 06:58:48 2013
@@ -24,7 +24,6 @@ import java.util.concurrent.ScheduledExe
 
 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;
 import org.apache.ace.agent.ConnectionHandler;
@@ -33,8 +32,6 @@ import org.apache.ace.agent.DiscoveryHan
 import org.apache.ace.agent.DownloadHandler;
 import org.apache.ace.agent.FeedbackHandler;
 import org.apache.ace.agent.IdentificationHandler;
-import org.apache.ace.agent.impl.Activator.InternalEvents;
-import org.apache.ace.agent.impl.Activator.InternalLogger;
 
 /**
  * Implementation of the internal agent context service.
@@ -43,7 +40,6 @@ import org.apache.ace.agent.impl.Activat
 public class AgentContextImpl implements AgentContext {
 
     // All service are volatile because they may be updated at runtime.
-    private volatile AgentControl m_agentControl;
     private volatile ConfigurationHandler m_configurationHandler;
     private volatile IdentificationHandler m_identificationHandler;
     private volatile DiscoveryHandler m_discoveryHandler;
@@ -52,54 +48,47 @@ public class AgentContextImpl implements
     private volatile ConnectionHandler m_connectionHandler;
     private volatile AgentUpdateHandler m_agentUpdateHandler;
     private volatile FeedbackHandler m_feedbackHandler;
-
+    private volatile LoggingHandler m_loggingHandler;
+    private volatile EventsHandler m_eventsHandler;
     private volatile ScheduledExecutorService m_executorService;
 
-    private final InternalLogger m_logger;
-    private final InternalEvents m_events;
-
     private final File m_workDir;
 
-    public AgentContextImpl(File workDir, InternalLogger logger, InternalEvents events) {
-        m_logger = logger;
-        m_events = events;
+    public AgentContextImpl(File workDir) {
         m_workDir = workDir;
     }
 
     public void start() throws Exception {
-        startHandler(m_agentControl);
+        startHandler(m_executorService);
         startHandler(m_configurationHandler);
+        startHandler(m_loggingHandler);
+        startHandler(m_eventsHandler);
+        startHandler(m_connectionHandler);
+        startHandler(m_downloadHandler);
         startHandler(m_identificationHandler);
         startHandler(m_discoveryHandler);
-        startHandler(m_deploymentHandler);
-        startHandler(m_downloadHandler);
-        startHandler(m_connectionHandler);
         startHandler(m_agentUpdateHandler);
+        startHandler(m_deploymentHandler);
         startHandler(m_feedbackHandler);
-        startHandler(m_agentControl);
     }
 
     public void stop() throws Exception {
-        stopHandler(m_agentControl);
         stopHandler(m_feedbackHandler);
-        stopHandler(m_configurationHandler);
+        stopHandler(m_deploymentHandler);
         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);
+        stopHandler(m_eventsHandler);
+        stopHandler(m_loggingHandler);
+        stopHandler(m_configurationHandler);
+        stopHandler(m_executorService);
     }
 
-    private void stopHandler(Object handler) throws Exception {
-        if (handler instanceof AgentContextAware)
-            ((AgentContextAware) handler).stop();
+    @Override
+    public File getWorkDir() {
+        return m_workDir;
     }
 
     @Override
@@ -107,29 +96,44 @@ public class AgentContextImpl implements
         return m_identificationHandler;
     }
 
+    void setIdentificationHandler(IdentificationHandler identificationHandler) {
+        m_identificationHandler = identificationHandler;
+    }
+
     @Override
     public DiscoveryHandler getDiscoveryHandler() {
         return m_discoveryHandler;
     }
 
+    void setDiscoveryHandler(DiscoveryHandler discoveryHandler) {
+        m_discoveryHandler = discoveryHandler;
+    }
+
     @Override
     public ConnectionHandler getConnectionHandler() {
         return m_connectionHandler;
     }
 
+    void setConnectionHandler(ConnectionHandler connectionHandler) {
+        m_connectionHandler = connectionHandler;
+    }
+
     @Override
     public DeploymentHandler getDeploymentHandler() {
         return m_deploymentHandler;
     }
 
+    void setDeploymentHandler(DeploymentHandler deploymenthandler) {
+        m_deploymentHandler = deploymenthandler;
+    }
+
     @Override
     public DownloadHandler getDownloadHandler() {
         return m_downloadHandler;
     }
 
-    @Override
-    public ScheduledExecutorService getExecutorService() {
-        return m_executorService;
+    void setDownloadHandler(DownloadHandler downloadHandler) {
+        m_downloadHandler = downloadHandler;
     }
 
     @Override
@@ -137,64 +141,107 @@ public class AgentContextImpl implements
         return m_configurationHandler;
     }
 
+    void setConfigurationHandler(ConfigurationHandler configurationHandler) {
+        m_configurationHandler = configurationHandler;
+    }
+
     @Override
     public AgentUpdateHandler getAgentUpdateHandler() {
         return m_agentUpdateHandler;
     }
 
+    void setAgentUpdateHandler(AgentUpdateHandler agentUpdateHandler) {
+        m_agentUpdateHandler = agentUpdateHandler;
+    }
+
     @Override
     public FeedbackHandler getFeedbackHandler() {
         return m_feedbackHandler;
     }
 
+    void setFeedbackHandler(FeedbackHandler feedbackHandler) {
+        m_feedbackHandler = feedbackHandler;
+    }
+
     @Override
-    public File getWorkDir() {
-        return m_workDir;
+    public ScheduledExecutorService getExecutorService() {
+        return m_executorService;
+    }
+
+    void setExecutorService(ScheduledExecutorService executorService) {
+        m_executorService = executorService;
+    }
+
+    LoggingHandler getLoggingHandler() {
+        return m_loggingHandler;
+    }
+
+    void setLoggingHandler(LoggingHandler loggingHandler) {
+        m_loggingHandler = loggingHandler;
+    }
+
+    EventsHandler getEventHandler() {
+        return m_eventsHandler;
+    }
+
+    void setEventsHandler(EventsHandler eventsHandler) {
+        m_eventsHandler = eventsHandler;
     }
 
     @Override
     public void postEvent(String topic, Dictionary<String, String> payload) {
-        m_events.postEvent(topic, payload);
+        m_eventsHandler.postEvent(topic, payload);
     }
 
     @Override
     public void logDebug(String component, String message, Object... args) {
-        m_logger.logDebug(component, message, null, args);
+        m_loggingHandler.logDebug(component, message, null, args);
     }
 
     @Override
     public void logDebug(String component, String message, Throwable exception, Object...
args) {
-        m_logger.logDebug(component, message, exception, args);
+        m_loggingHandler.logDebug(component, message, exception, args);
     }
 
     @Override
     public void logInfo(String component, String message, Object... args) {
-        m_logger.logInfo(component, message, null, args);
+        m_loggingHandler.logInfo(component, message, null, args);
     }
 
     @Override
     public void logInfo(String component, String message, Throwable exception, Object...
args) {
-        m_logger.logInfo(component, message, exception, args);
+        m_loggingHandler.logInfo(component, message, exception, args);
     }
 
     @Override
     public void logWarning(String component, String message, Object... args) {
-        m_logger.logWarning(component, message, null, args);
+        m_loggingHandler.logWarning(component, message, null, args);
     }
 
     @Override
     public void logWarning(String component, String message, Throwable exception, Object...
args) {
-        m_logger.logWarning(component, message, exception, args);
+        m_loggingHandler.logWarning(component, message, exception, args);
     }
 
     @Override
     public void logError(String component, String message, Object... args) {
-        m_logger.logDebug(component, message, null, args);
+        m_loggingHandler.logDebug(component, message, null, args);
     }
 
     @Override
     public void logError(String component, String message, Throwable exception, Object...
args) {
-        m_logger.logDebug(component, message, exception, args);
+        m_loggingHandler.logDebug(component, message, exception, args);
     }
 
+    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();
+        }
+    }
 }

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=1517438&r1=1517437&r2=1517438&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
Mon Aug 26 06:58:48 2013
@@ -36,7 +36,7 @@ public class DeploymentHandlerImpl exten
 
     public static final String COMPONENT_IDENTIFIER = "deployment";
     public static final String CONFIG_KEY_BASE = ConfigurationHandlerImpl.CONFIG_KEY_NAMESPACE
+ "." + COMPONENT_IDENTIFIER;
-    
+
     private final DeploymentAdmin m_deploymentAdmin;
 
     public DeploymentHandlerImpl(DeploymentAdmin deploymentAdmin) {



Mime
View raw message