Return-Path: X-Original-To: apmail-ace-commits-archive@www.apache.org Delivered-To: apmail-ace-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B2099109F5 for ; Wed, 18 Sep 2013 08:08:36 +0000 (UTC) Received: (qmail 26192 invoked by uid 500); 18 Sep 2013 08:08:35 -0000 Delivered-To: apmail-ace-commits-archive@ace.apache.org Received: (qmail 26165 invoked by uid 500); 18 Sep 2013 08:08:33 -0000 Mailing-List: contact commits-help@ace.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ace.apache.org Delivered-To: mailing list commits@ace.apache.org Received: (qmail 26156 invoked by uid 99); 18 Sep 2013 08:08:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Sep 2013 08:08:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Sep 2013 08:08:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2505D238889B; Wed, 18 Sep 2013 08:08:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@ace.apache.org From: jawi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130918080809.2505D238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 null. */ void write(int type, Map 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 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 split(String value) { + Set trimmedValues = new HashSet(); + if (value != null) { + String[] rawValues = value.split(","); + for (String rawValue : rawValues) { + trimmedValues.add(rawValue.trim()); + } + } + return trimmedValues; + } + private final ConcurrentMap m_channels; public FeedbackHandlerImpl() { @@ -45,13 +57,13 @@ public class FeedbackHandlerImpl extends } @Override - public Set 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 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 split(String value) { - Set trimmedValues = new HashSet(); - 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 * or agent update is started. This is sent always prior to the beginning of an installation. */