ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1524327 - in /ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent: FeedbackChannel.java impl/DefaultController.java impl/EventLoggerImpl.java impl/FeedbackHandlerImpl.java impl/InternalConstants.java
Date Wed, 18 Sep 2013 08:08:08 GMT
Author: jawi
Date: Wed Sep 18 08:08:08 2013
New Revision: 1524327

URL: http://svn.apache.org/r1524327
Log:
ACE-323 - fixed the default feedback channel.

- there should always be an auditlog feedback channel;
- added some additional documentation to several methods.


Modified:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.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/EventLoggerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/InternalConstants.java

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java?rev=1524327&r1=1524326&r2=1524327&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java Wed Sep 18
08:08:08 2013
@@ -21,23 +21,26 @@ package org.apache.ace.agent;
 import java.io.IOException;
 import java.util.Map;
 
-
 /**
- *
+ * Represents a channel on which feedback information can be reported back to the server.
An agent can configure
+ * multiple feedback channels for reporting different pieces of information. By default,
one feedback channel is
+ * present, which is used for reporting the audit events.
  */
 public interface FeedbackChannel {
 
     /**
-     * Synchronizes the feedback with the current server. Ensures the server has at least
as much feedback data as we
-     * do.
+     * Synchronizes the current feedback with the server(s), ensuring that those servers
have the same (snapshot of)
+     * feedback data as the agent currently has.
      */
     void sendFeedback() throws RetryAfterException, IOException;
 
     /**
-     * Logs a new message to the channel.
+     * Logs a new message to this feedback channel.
      * 
      * @param type
+     *            the type of the log-event to write;
      * @param properties
+     *            the actual contents of the message to write, cannot be <code>null</code>.
      */
     void write(int type, Map<String, String> properties) throws IOException;
 }

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=1524327&r1=1524326&r2=1524327&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
Sep 18 08:08:08 2013
@@ -642,9 +642,10 @@ public class DefaultController extends C
     }
 
     private void runFeedback() throws RetryAfterException {
-        logDebug("Synchronizing feedback channels");
-
         Set<String> names = getFeedbackChannelNames();
+
+        logDebug("Synchronizing feedback channels: %s", names);
+
         for (String name : names) {
             FeedbackChannel channel = getFeedbackChannel(name);
             if (channel != null) {
@@ -655,7 +656,7 @@ public class DefaultController extends C
                 catch (IOException e) {
                     // Hopefully temporary problem due to remote IO or configuration. No
cause to abort the sync so we
                     // just log it as a warning.
-                    logWarning("Exception while sending feedback on channel: %s", e, name);
+                    logWarning("Exception while sending feedback for channel: %s", e, name);
                 }
             }
         }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/EventLoggerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/EventLoggerImpl.java?rev=1524327&r1=1524326&r2=1524327&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/EventLoggerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/EventLoggerImpl.java Wed
Sep 18 08:08:08 2013
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.ace.agent.AgentConstants;
 import org.apache.ace.agent.EventListener;
 import org.apache.ace.agent.FeedbackChannel;
 import org.apache.ace.log.AuditEvent;
@@ -35,15 +36,15 @@ import org.osgi.framework.FrameworkEvent
 import org.osgi.framework.FrameworkListener;
 
 /**
- * Service component that listens for
- * 
+ * Service component that listens for various events from the OSGi framework and writes those
events to the audit log
+ * feedback channel.
  */
 public class EventLoggerImpl extends ComponentBase implements BundleListener, FrameworkListener,
EventListener {
+    public static final String EVENTLOGGER_FEEDBACKCHANNEL = InternalConstants.AUDITLOG_FEEDBACK_CHANNEL;
 
-    public static final String EVENTLOGGER_FEEDBACKCHANNEL = "auditlog";
-    public static final String TOPIC_INSTALL = "org/osgi/service/deployment/INSTALL";
-    public static final String TOPIC_UNINSTALL = "org/osgi/service/deployment/UNINSTALL";
-    public static final String TOPIC_COMPLETE = "org/osgi/service/deployment/COMPLETE";
+    public static final String TOPIC_INSTALL = AgentConstants.EVENT_DEPLOYMENT_INSTALL;
+    public static final String TOPIC_UNINSTALL = AgentConstants.EVENT_DEPLOYMENT_UNINSTALL;
+    public static final String TOPIC_COMPLETE = AgentConstants.EVENT_DEPLOYMENT_COMPLETE;
 
     private final BundleContext m_bundleContext;
     private final AtomicBoolean m_isStarted;
@@ -230,9 +231,6 @@ public class EventLoggerImpl extends Com
             if (channel != null) {
                 channel.write(eventType, payload);
             }
-            else {
-//                logDebug("Feedback event *not* written as no channel is available!");
-            }
         }
         catch (IOException e) {
             logWarning("Failed to write feedback event!", e);

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackHandlerImpl.java?rev=1524327&r1=1524326&r2=1524327&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/FeedbackHandlerImpl.java
Wed Sep 18 08:08:08 2013
@@ -20,6 +20,7 @@ package org.apache.ace.agent.impl;
 
 import static org.apache.ace.agent.AgentConstants.EVENT_AGENT_CONFIG_CHANGED;
 import static org.apache.ace.agent.AgentConstants.CONFIG_FEEDBACK_CHANNELS;
+import static org.apache.ace.agent.impl.InternalConstants.*;
 
 import java.io.IOException;
 import java.util.HashSet;
@@ -36,6 +37,17 @@ import org.apache.ace.agent.FeedbackHand
  * Default implementation of the feedback handler.
  */
 public class FeedbackHandlerImpl extends ComponentBase implements FeedbackHandler, EventListener
{
+    private static Set<String> split(String value) {
+        Set<String> trimmedValues = new HashSet<String>();
+        if (value != null) {
+            String[] rawValues = value.split(",");
+            for (String rawValue : rawValues) {
+                trimmedValues.add(rawValue.trim());
+            }
+        }
+        return trimmedValues;
+    }
+
     private final ConcurrentMap<String, FeedbackChannelImpl> m_channels;
 
     public FeedbackHandlerImpl() {
@@ -45,13 +57,13 @@ public class FeedbackHandlerImpl extends
     }
 
     @Override
-    public Set<String> getChannelNames() throws IOException {
-        return m_channels.keySet();
+    public FeedbackChannel getChannel(String name) throws IOException {
+        return m_channels.get(name);
     }
 
     @Override
-    public FeedbackChannel getChannel(String name) throws IOException {
-        return m_channels.get(name);
+    public Set<String> getChannelNames() throws IOException {
+        return m_channels.keySet();
     }
 
     @Override
@@ -69,7 +81,7 @@ public class FeedbackHandlerImpl extends
 
                 for (String channelName : channelNames) {
                     try {
-                        m_channels.putIfAbsent(channelName, new FeedbackChannelImpl(getAgentContext(),
channelName));
+                        registerFeedbackChannel(channelName);
                         seen.remove(channelName);
                     }
                     catch (IOException exception) {
@@ -78,9 +90,8 @@ public class FeedbackHandlerImpl extends
                 }
 
                 for (String oldChannelName : seen) {
-                    FeedbackChannelImpl channel = m_channels.remove(oldChannelName);
                     try {
-                        channel.closeStore();
+                        unregisterFeedbackChannel(oldChannelName);
                     }
                     catch (IOException exception) {
                         logError("Failed to close feedback channel for '%s'", exception,
oldChannelName);
@@ -96,20 +107,34 @@ public class FeedbackHandlerImpl extends
     }
 
     @Override
+    protected void onStart() throws Exception {
+        // Make sure the default audit log is present...
+        registerFeedbackChannel(AUDITLOG_FEEDBACK_CHANNEL);
+    }
+
+    @Override
     protected void onStop() throws Exception {
         getEventsHandler().removeListener(this);
 
-        m_channels.clear();
+        for (String channelName : getChannelNames()) {
+            try {
+                unregisterFeedbackChannel(channelName);
+            }
+            catch (IOException exception) {
+                logWarning("Failed to close feedback channel '%s'", exception, channelName);
+            }
+        }
     }
 
-    private static Set<String> split(String value) {
-        Set<String> trimmedValues = new HashSet<String>();
-        if (value != null) {
-            String[] rawValues = value.split(",");
-            for (String rawValue : rawValues) {
-                trimmedValues.add(rawValue.trim());
-            }
+    private void registerFeedbackChannel(String channelName) throws IOException {
+        FeedbackChannelImpl channel = new FeedbackChannelImpl(getAgentContext(), channelName);
+        m_channels.putIfAbsent(channelName, channel);
+    }
+
+    private void unregisterFeedbackChannel(String oldChannelName) throws IOException {
+        FeedbackChannelImpl channel = m_channels.remove(oldChannelName);
+        if (channel != null) {
+            channel.closeStore();
         }
-        return trimmedValues;
     }
 }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/InternalConstants.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/InternalConstants.java?rev=1524327&r1=1524326&r2=1524327&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/InternalConstants.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/InternalConstants.java Wed
Sep 18 08:08:08 2013
@@ -23,6 +23,10 @@ package org.apache.ace.agent.impl;
  */
 public interface InternalConstants {
     /**
+     * The feedback channel for reporting the audit events of a target.
+     */
+    String AUDITLOG_FEEDBACK_CHANNEL = "auditlog";
+    /**
      * Internal event topic used by the default controller to fire events when the installation
of a deployment package
      * <em>or</em> agent update is started. This is sent always prior to the
beginning of an installation.
      */



Mime
View raw message