Timo Heinonen created DOSGI-214:
-----------------------------------

             Summary: Endpoint publication to discovery does not always work
                 Key: DOSGI-214
                 URL: https://issues.apache.org/jira/browse/DOSGI-214
             Project: CXF Distributed OSGi
          Issue Type: Bug
          Components: DSW
    Affects Versions: 1.6.0
         Environment: Windows 7, Linux (OpenSuse), seems to happen more often 
with slower CPU computers
            Reporter: Timo Heinonen


TopologyManager bundle's EndpointListenerNotifier does not call all 
EndpointListener's at all times correctly and therefore some endpoints don't 
get published to discovery (zookeeper). 

I found following problems with the current implementation:
1) TopologyManagerExport.exportServiceUsingRemoteServiceAdmin():
In the end of the exportServiceUsingRemoteServiceAdmin() notifyListeners() is 
called before updating endpointregistry. This causes problem in 
EndpointListenerNotifier, because endpointRepository.getAllEndpoints() does not 
return correct state before endpoints are updated. Basically problem exists 
when ServiceTracker's addingService() is called simultaneously for discovery 
bundle's EndpointLIstener and other thread (call coming from 
TopologyManagerExport) calls notfiyListeners(). 
stEndpointListeners.getServiceReferences() does not yet return the endpoint 
listener of discovery bundle and therefore discovery is not notified. Also, 
addingService() call does not find endpoint from endpointRegistry and therefore 
does not publish it.

FIX: By changing the order of notifyListeners() and addEndpoints() in 
TopologyManagerExport the above is fixed.

2) EndpointListenerNotifier is not threadsafe although ServiceTracker is. 
stEndpointListeners.getServiceReferences() returns just added EndpointListener 
(the one from discovery bundle) only AFTER whole overrided addingService() 
method has finished. So following can happen:
a) addingService() is called with discovery bundle's EPL
b) super.addingService() call is finished and notifyListener() is called with 
no new Endpoint because TopologyManagerExport has not yet added it to 
endPointRepo
c) TopologyManagerExport calls addEndpoint() and notifyListeners() (in fixed 
order) and EndpointListenerNotifier does not notify discove EPL, because 
addingService() call has not yet returned and therefore 
stEndpointListeners.getServiceReferences() still returns 1 EPL (from 
topologyManager bundle)

FIX: Add synchronized (EndpointListenerNotifier.this) to both methods 
addingService and modifiedService. Also add synchronized (this) to 
notifyListeners() method so that lock guards call to 
stdEndpointListeners.getServiceReference(). 



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to