Skip to content

Commit

Permalink
CELIX-276: added handling of importedServices when rsa gets removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetri committed Oct 16, 2015
1 parent f60ca0d commit 48558e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
Expand Up @@ -32,6 +32,8 @@
#include "bundle_context.h"
#include "log_helper.h"

#define OSGI_RSA_REMOTE_SERVICE_ADMIN "remote_service_admin"

typedef struct topology_manager *topology_manager_pt;

celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper, topology_manager_pt *manager);
Expand Down
2 changes: 1 addition & 1 deletion remote_services/topology_manager/private/src/activator.c
Expand Up @@ -124,7 +124,7 @@ static celix_status_t bundleActivator_createRSATracker(struct activator *activat
status = serviceTrackerCustomizer_create(activator->manager, topologyManager_rsaAdding, topologyManager_rsaAdded, topologyManager_rsaModified, topologyManager_rsaRemoved, &customizer);

if (status == CELIX_SUCCESS) {
status = serviceTracker_create(activator->context, "remote_service_admin", customizer, tracker);
status = serviceTracker_create(activator->context, OSGI_RSA_REMOTE_SERVICE_ADMIN, customizer, tracker);
}

return status;
Expand Down
47 changes: 30 additions & 17 deletions remote_services/topology_manager/private/src/topology_manager.c
Expand Up @@ -214,12 +214,7 @@ celix_status_t topologyManager_rsaAdded(void * handle, service_reference_pt refe

if (status == CELIX_SUCCESS) {
hash_map_pt imports = hashMapEntry_getValue(entry);

if (imports == NULL) {
imports = hashMap_create(NULL, NULL, NULL, NULL);
}

hashMap_put(imports, service, import);
hashMap_put(imports, rsa, import);
}
}

Expand All @@ -244,10 +239,6 @@ celix_status_t topologyManager_rsaAdded(void * handle, service_reference_pt refe
if (status == CELIX_SUCCESS) {
hash_map_pt exports = hashMapEntry_getValue(entry);

if (exports == NULL) {
exports = hashMap_create(NULL, NULL, NULL, NULL);
}

hashMap_put(exports, rsa, endpoints);
status = topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
}
Expand Down Expand Up @@ -317,6 +308,30 @@ celix_status_t topologyManager_rsaRemoved(void * handle, service_reference_pt re

status = celixThreadMutex_unlock(&manager->exportedServicesLock);

status = celixThreadMutex_lock(&manager->importedServicesLock);

iter = hashMapIterator_create(manager->importedServices);

while (hashMapIterator_hasNext(iter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
endpoint_description_pt ep = hashMapEntry_getKey(entry);
hash_map_pt imports = hashMapEntry_getValue(entry);

import_registration_pt import = hashMap_get(imports, rsa);

if (import != NULL) {
status = rsa->importRegistration_close(rsa->admin, import);

if (status == CELIX_SUCCESS) {
hashMap_remove(imports, rsa);
}
}
}

hashMapIterator_destroy(iter);

status = celixThreadMutex_unlock(&manager->importedServicesLock);

logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Removed RSA");

status = celixThreadMutex_lock(&manager->rsaListLock);
Expand Down Expand Up @@ -610,7 +625,7 @@ celix_status_t topologyManager_endpointListenerAdded(void* handle, service_refer
}

celix_status_t topologyManager_endpointListenerModified(void * handle, service_reference_pt reference, void * service) {
celix_status_t status;
celix_status_t status = CELIX_SUCCESS;

status = topologyManager_endpointListenerRemoved(handle, reference, service);
if (status == CELIX_SUCCESS) {
Expand All @@ -621,7 +636,7 @@ celix_status_t topologyManager_endpointListenerModified(void * handle, service_r
}

celix_status_t topologyManager_endpointListenerRemoved(void * handle, service_reference_pt reference, void * service) {
celix_status_t status;
celix_status_t status = CELIX_SUCCESS;
topology_manager_pt manager = handle;

celixThreadMutex_lock(&manager->listenerListLock);
Expand All @@ -638,7 +653,7 @@ celix_status_t topologyManager_endpointListenerRemoved(void * handle, service_re
}

celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager, remote_service_admin_service_pt rsa, array_list_pt registrations) {
celix_status_t status;
celix_status_t status = CELIX_SUCCESS;

celixThreadMutex_lock(&manager->listenerListLock);

Expand Down Expand Up @@ -705,12 +720,10 @@ celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_p
if (status == CELIX_SUCCESS) {
status = epl->endpointRemoved(epl->handle, endpoint, NULL);
}

hashMapIterator_destroy(iter);


}

hashMapIterator_destroy(iter);

celixThreadMutex_unlock(&manager->listenerListLock);

return status;
Expand Down

0 comments on commit 48558e8

Please sign in to comment.