celix_status_t pubsub_discovery_uninterestedInTopic(void *handle, const char* scope, const char* topic) { pubsub_discovery_pt pubsub_discovery = (pubsub_discovery_pt) handle; char *scope_topic_key = createScopeTopicKey(scope, topic); celixThreadMutex_lock(&pubsub_discovery->watchersMutex); hash_map_entry_pt entry = hashMap_getEntry(pubsub_discovery->watchers, scope_topic_key); if(entry) { struct watcher_info * wi = hashMapEntry_getValue(entry); wi->nr_references--; if(wi->nr_references == 0) { char *key = hashMapEntry_getKey(entry); hashMap_remove(pubsub_discovery->watchers, scope_topic_key); free(key); free(scope_topic_key); etcdWatcher_stop(wi->watcher); etcdWatcher_destroy(wi->watcher); free(wi); } } else { fprintf(stderr, "[DISC] Inconsistency error: Removing unknown topic %s\n", topic); } celixThreadMutex_unlock(&pubsub_discovery->watchersMutex); return CELIX_SUCCESS; }
celix_status_t pubsub_discovery_stop(pubsub_discovery_pt ps_discovery) { celix_status_t status = CELIX_SUCCESS; const char* fwUUID = NULL; bundleContext_getProperty(ps_discovery->context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID); if (fwUUID == NULL) { printf("PSD: Cannot retrieve fwUUID.\n"); return CELIX_INVALID_BUNDLE_CONTEXT; } celixThreadMutex_lock(&ps_discovery->watchersMutex); hash_map_iterator_pt iter = hashMapIterator_create(ps_discovery->watchers); while (hashMapIterator_hasNext(iter)) { struct watcher_info * wi = hashMapIterator_nextValue(iter); etcdWatcher_stop(wi->watcher); } hashMapIterator_destroy(iter); celixThreadMutex_lock(&ps_discovery->discoveredPubsMutex); /* Unexport all publishers for the local framework, and also delete from ETCD publisher belonging to the local framework */ iter = hashMapIterator_create(ps_discovery->discoveredPubs); while (hashMapIterator_hasNext(iter)) { array_list_pt pubEP_list = (array_list_pt) hashMapIterator_nextValue(iter); int i; for (i = 0; i < arrayList_size(pubEP_list); i++) { pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt) arrayList_get(pubEP_list, i); if (strcmp(pubEP->frameworkUUID, fwUUID) == 0) { etcdWriter_deletePublisherEndpoint(ps_discovery->writer, pubEP); } else { pubsub_discovery_informPublishersListeners(ps_discovery, pubEP, false); arrayList_remove(pubEP_list, i); pubsubEndpoint_destroy(pubEP); i--; } } } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&ps_discovery->discoveredPubsMutex); etcdWriter_destroy(ps_discovery->writer); iter = hashMapIterator_create(ps_discovery->watchers); while (hashMapIterator_hasNext(iter)) { struct watcher_info * wi = hashMapIterator_nextValue(iter); etcdWatcher_destroy(wi->watcher); } hashMapIterator_destroy(iter); hashMap_destroy(ps_discovery->watchers, true, true); celixThreadMutex_unlock(&ps_discovery->watchersMutex); return status; }
celix_status_t discovery_stop(discovery_pt discovery) { celix_status_t status; status = etcdWatcher_destroy(discovery->watcher); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } status = endpointDiscoveryServer_destroy(discovery->server); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } status = endpointDiscoveryPoller_destroy(discovery->poller); if (status != CELIX_SUCCESS) { return CELIX_BUNDLE_EXCEPTION; } hash_map_iterator_pt iter; celixThreadMutex_lock(&discovery->discoveredServicesMutex); iter = hashMapIterator_create(discovery->discoveredServices); while (hashMapIterator_hasNext(iter)) { hash_map_entry_pt entry = hashMapIterator_nextEntry(iter); endpoint_description_pt endpoint = hashMapEntry_getValue(entry); discovery_informEndpointListeners(discovery, endpoint, false); } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&discovery->discoveredServicesMutex); logHelper_stop(discovery->loghelper); return status; }