You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2007/02/06 14:57:10 UTC

svn commit: r504139 - /incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java

Author: rickhall
Date: Tue Feb  6 05:57:09 2007
New Revision: 504139

URL: http://svn.apache.org/viewvc?view=rev&rev=504139
Log:
Applied patch (FELIX-202) to resolve a synchronization bug.

Modified:
    incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?view=diff&rev=504139&r1=504138&r2=504139
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java Tue Feb  6 05:57:09 2007
@@ -80,11 +80,6 @@
     private ProvidedServiceHandler m_handler;
 
     /**
-     * State of the provided service.
-     */
-    private int m_state;
-
-    /**
      * Properties Array.
      */
     private Property[] m_properties = new Property[0];
@@ -205,8 +200,8 @@
      * The service object must be able to serve this service.
      * To avoid cycle in Check Context, the registred service is set to registred before the real registration.
      */
-    protected void registerService() {
-        if (m_state != REGISTERED) {
+    protected synchronized void registerService() {
+        if (m_serviceRegistration == null) {
             String spec = "";
             for (int i = 0; i < m_serviceSpecification.length; i++) {
                 spec = spec + m_serviceSpecification[i] + ", ";
@@ -214,25 +209,21 @@
             // Contruct the service properties list
             Properties serviceProperties = getServiceProperties();
 
-            m_state = REGISTERED;
-            synchronized (this) {
-                m_serviceRegistration =
+            m_serviceRegistration =
                     m_handler.getInstanceManager().getContext().registerService(
                     		m_serviceSpecification, this, serviceProperties);
-            }
         }
     }
 
     /**
      * Unregister the service.
      */
-    protected void unregisterService() {
-        if (m_state == REGISTERED) {
+    protected synchronized void unregisterService() {
+        if (m_serviceRegistration != null) {
             try {
                 m_serviceRegistration.unregister();
-                m_serviceRegistration = null;
             } catch (Exception e) { return; }
-            m_state = UNREGISTERED;
+            m_serviceRegistration = null;
         }
     }
 
@@ -240,7 +231,8 @@
      * @return The state of the provided service.
      */
     public int getState() {
-        return m_state;
+    	if(m_serviceRegistration == null) { return UNREGISTERED; }
+    	else { return REGISTERED; }
     }
 
     /**
@@ -277,8 +269,7 @@
      * Update the service properties.
      * The new list of properties is sended to the service registry.
      */
-    public void update() {
-
+    public synchronized void update() {
         // Contruct the service properties list
         Properties serviceProperties = getServiceProperties();
         
@@ -287,11 +278,9 @@
         }
 
         // Update the service registration
-        if (m_state == REGISTERED) {
-            synchronized (this) {
+        if (m_serviceRegistration != null) {
                 m_serviceRegistration.setProperties(serviceProperties);
             }
-        }
     }
 
     /**