Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 67579 invoked from network); 8 Apr 2008 11:46:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Apr 2008 11:46:05 -0000 Received: (qmail 57616 invoked by uid 500); 8 Apr 2008 11:46:05 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 57586 invoked by uid 500); 8 Apr 2008 11:46:05 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 57577 invoked by uid 99); 8 Apr 2008 11:46:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Apr 2008 04:46:05 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Apr 2008 11:45:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5BCFC1A9832; Tue, 8 Apr 2008 04:45:41 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r645864 - in /felix/trunk/ipojo/core/src/main: java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java resources/metadata.xml Date: Tue, 08 Apr 2008 11:45:40 -0000 To: commits@felix.apache.org From: clement@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080408114541.5BCFC1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: clement Date: Tue Apr 8 04:45:40 2008 New Revision: 645864 URL: http://svn.apache.org/viewvc?rev=645864&view=rev Log: Avoid the architecture service to publish non-service interfaces (FieldInterceptor and MethodInterceptor) Handle correctly ManagedService configuration deletion. Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java felix/trunk/ipojo/core/src/main/resources/metadata.xml Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java?rev=645864&r1=645863&r2=645864&view=diff ============================================================================== --- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java (original) +++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java Tue Apr 8 04:45:40 2008 @@ -24,7 +24,6 @@ import org.apache.felix.ipojo.ConfigurationException; import org.apache.felix.ipojo.HandlerFactory; -import org.apache.felix.ipojo.InstanceManager; import org.apache.felix.ipojo.PrimitiveHandler; import org.apache.felix.ipojo.architecture.ComponentTypeDescription; import org.apache.felix.ipojo.architecture.PropertyDescription; @@ -57,19 +56,29 @@ private ProvidedServiceHandler m_providedServiceHandler; /** - * Properties propagated at the last "updated". + * Properties propagated during the last instance "update". */ - private Dictionary m_propagated = new Properties(); + private Dictionary m_propagatedFromInstance = new Properties(); /** * Properties to propagate. */ private Dictionary m_toPropagate = new Properties(); + + /** + * Properties propagated from the configuration admin. + */ + private Dictionary m_propagatedFromCA; + + /** + * Check if the instance was already reconfigured by the configuration admin. + */ + private boolean m_configurationAlreadyPushed; /** * should the component propagate configuration ? */ - private boolean m_isConfigurable; + private boolean m_mustPropagate; /** * Service Registration to publish the service registration. @@ -174,11 +183,11 @@ Element[] configurables = confs[0].getElements("Property"); // Check if the component is dynamically configurable - m_isConfigurable = false; + m_mustPropagate = false; String propa = confs[0].getAttribute("propagation"); if (propa != null && propa.equalsIgnoreCase("true")) { - m_isConfigurable = true; - m_toPropagate = configuration; + m_mustPropagate = true; + m_toPropagate = configuration; // Instance configuration to propagate. } // Check if the component support ConfigurationADmin reconfiguration @@ -219,10 +228,11 @@ /** * Stop method. + * This method is synchronized to avoid the configuration admin pushing a configuration during the un-registration. * Do nothing. * @see org.apache.felix.ipojo.Handler#stop() */ - public void stop() { + public synchronized void stop() { if (m_sr != null) { m_sr.unregister(); m_sr = null; @@ -231,15 +241,16 @@ /** * Start method. + * This method is synchronized to avoid the config admin pushing a configuration before ending the method. * Propagate properties if the propagation is activated. * @see org.apache.felix.ipojo.Handler#start() */ - public void start() { + public synchronized void start() { // Get the provided service handler : m_providedServiceHandler = (ProvidedServiceHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":provides"); // Propagation - if (m_isConfigurable) { + if (m_mustPropagate) { for (int i = 0; i < m_configurableProperties.length; i++) { m_toPropagate.put(m_configurableProperties[i].getName(), m_configurableProperties[i].getValue()); } @@ -255,21 +266,21 @@ } } - /** - * Handler state changed. - * @param state : the new instance state. - * @see org.apache.felix.ipojo.CompositeHandler#stateChanged(int) - */ - public void stateChanged(int state) { - if (state == InstanceManager.VALID) { - start(); - return; - } - if (state == InstanceManager.INVALID) { - stop(); - return; - } - } +// /** +// * Handler state changed. +// * @param state : the new instance state. +// * @see org.apache.felix.ipojo.CompositeHandler#stateChanged(int) +// */ +// public void stateChanged(int state) { +// if (state == InstanceManager.VALID) { +// start(); +// return; +// } +// if (state == InstanceManager.INVALID) { +// stop(); +// return; +// } +// } /** * Add the given property metadata to the property metadata list. @@ -310,7 +321,19 @@ * @param configuration : the new configuration * @see org.apache.felix.ipojo.Handler#reconfigure(java.util.Dictionary) */ - public void reconfigure(Dictionary configuration) { + public synchronized void reconfigure(Dictionary configuration) { + Properties props = reconfigureProperties(configuration); + propagate(props, m_propagatedFromInstance); + m_propagatedFromInstance = props; + } + + /** + * Reconfigured configuration properties and returns non matching properties. + * When called, it must hold the monitor lock. + * @param configuration : new configuration + * @return the properties that does not match with configuration properties + */ + private Properties reconfigureProperties(Dictionary configuration) { Properties toPropagate = new Properties(); Enumeration keysEnumeration = configuration.keys(); while (keysEnumeration.hasMoreElements()) { @@ -342,17 +365,29 @@ } } - // Propagation of the properties to service registrations : - if (m_providedServiceHandler != null && !toPropagate.isEmpty()) { - m_providedServiceHandler.removeProperties(m_propagated); - - // Remove the name, the pid and the managed service pid props - toPropagate.remove("name"); - toPropagate.remove("managed.service.pid"); - toPropagate.remove(Constants.SERVICE_PID); + return toPropagate; - m_providedServiceHandler.addProperties(toPropagate); - m_propagated = toPropagate; + } + + /** + * Removes the old properties from the provided services and propagate new properties. + * @param newProps : new properties to propagate + * @param oldProps : old properties to remove + */ + private void propagate(Dictionary newProps, Dictionary oldProps) { + if (m_mustPropagate && m_providedServiceHandler != null) { + if (oldProps != null) { + m_providedServiceHandler.removeProperties(oldProps); + } + + if (newProps != null) { + // Remove the name, the pid and the managed service pid props + newProps.remove("name"); + newProps.remove("managed.service.pid"); + newProps.remove(Constants.SERVICE_PID); + // Propagation of the properties to service registrations : + m_providedServiceHandler.addProperties(newProps); + } } } @@ -373,12 +408,24 @@ /** * Managed Service method. * This method is called when the instance is reconfigured by the ConfigurationAdmin. - * @param arg0 : pushed configuration. + * When called, it must hold the monitor lock. + * @param conf : pushed configuration. * @throws org.osgi.service.cm.ConfigurationException the reconfiguration failed. * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ - public void updated(Dictionary arg0) throws org.osgi.service.cm.ConfigurationException { - reconfigure(arg0); + public synchronized void updated(Dictionary conf) throws org.osgi.service.cm.ConfigurationException { + if (conf == null && ! m_configurationAlreadyPushed) { + return; // First call + } else if (conf != null) { // Configuration push + Properties props = reconfigureProperties(conf); + propagate(props, m_propagatedFromCA); + m_propagatedFromCA = props; + m_configurationAlreadyPushed = true; + } else if (conf == null && m_configurationAlreadyPushed) { // Configuration deletion + propagate(null, m_propagatedFromCA); + m_propagatedFromCA = null; + m_configurationAlreadyPushed = false; + } } } Modified: felix/trunk/ipojo/core/src/main/resources/metadata.xml URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/resources/metadata.xml?rev=645864&r1=645863&r2=645864&view=diff ============================================================================== --- felix/trunk/ipojo/core/src/main/resources/metadata.xml (original) +++ felix/trunk/ipojo/core/src/main/resources/metadata.xml Tue Apr 8 04:45:40 2008 @@ -20,7 +20,7 @@ - +