Esempio n. 1
0
int phase1_stop(phase1_cmp_t *cmp) {
	printf("stop phase1\n");
    cmp->running = false;
    celixThread_kill(cmp->thread, SIGUSR1);
    celixThread_join(cmp->thread, NULL);
    return 0;
}
/**
 * Destroys and frees up memory for a given endpoint_discovery_poller struct.
 */
celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poller) {
    celix_status_t status;

    poller->running = false;

    celixThread_join(poller->pollerThread, NULL);

    hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
	while (hashMapIterator_hasNext(iterator)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);

		if ( endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, (char*) hashMapEntry_getKey(entry)) == CELIX_SUCCESS) {
			hashMapIterator_destroy(iterator);
			iterator = hashMapIterator_create(poller->entries);
		}
	}
	hashMapIterator_destroy(iterator);

	status = celixThreadMutex_lock(&poller->pollerLock);

	if (status != CELIX_SUCCESS) {
		return CELIX_BUNDLE_EXCEPTION;
	}

	hashMap_destroy(poller->entries, true, false);

    status = celixThreadMutex_unlock(&poller->pollerLock);

    poller->loghelper = NULL;

    free(poller);

	return status;
}
Esempio n. 3
0
void etcdWriter_destroy(etcd_writer_pt writer) {
	char dir[MAX_ROOTNODE_LENGTH];
	const char *rootPath = etcdWriter_getRootPath(writer->pubsub_discovery->context);

	writer->running = false;
	celixThread_join(writer->writerThread, NULL);

	celixThreadMutex_lock(&writer->localPubsLock);
	for(int i = 0; i < arrayList_size(writer->localPubs); i++) {
		pubsub_endpoint_pt pubEP = (pubsub_endpoint_pt)arrayList_get(writer->localPubs,i);
		memset(dir,0,MAX_ROOTNODE_LENGTH);
		snprintf(dir,MAX_ROOTNODE_LENGTH,"%s/%s/%s/%s",rootPath,pubEP->scope,pubEP->topic,pubEP->frameworkUUID);
		etcd_del(dir);
		pubsubEndpoint_destroy(pubEP);
	}
	arrayList_destroy(writer->localPubs);

	celixThreadMutex_unlock(&writer->localPubsLock);
	celixThreadMutex_destroy(&(writer->localPubsLock));

	free(writer);
}
Esempio n. 4
0
celix_status_t etcdWatcher_destroy(etcd_watcher_pt watcher) {
    celix_status_t status = CELIX_SUCCESS;
    char localNodePath[MAX_LOCALNODE_LENGTH];

    celixThreadMutex_lock(&(watcher->watcherLock));
    watcher->running = false;
    celixThreadMutex_unlock(&(watcher->watcherLock));

    watcher->running = false;

    celixThread_join(watcher->watcherThread, NULL);
    celixThreadMutex_destroy(&(watcher->watcherLock));

    // remove own registration
    status = etcdWatcher_getLocalNodePath(watcher->node_discovery->context, watcher->node_discovery->ownNode, &localNodePath[0]);

    if (status != CELIX_SUCCESS || etcd_del(localNodePath) == false) {
        printf("Cannot remove local discovery registration.");
    }

    free(watcher);

    return status;
}
Esempio n. 5
0
celix_status_t pubsub_topicSubscriptionStop(topic_subscription_pt ts){
	celix_status_t status = CELIX_SUCCESS;
	struct epoll_event ev;
	memset(&ev, 0, sizeof(ev));

	ts->running = false;

	pthread_kill(ts->recv_thread.thread,SIGUSR1);

	celixThread_join(ts->recv_thread,NULL);

	status = serviceTracker_close(ts->tracker);

	celixThreadMutex_lock(&ts->socketMap_lock);
	hash_map_iterator_pt it = hashMapIterator_create(ts->socketMap);
	while(hashMapIterator_hasNext(it)) {
		hash_map_entry_pt entry = hashMapIterator_nextEntry(it);
		char *url = hashMapEntry_getKey(entry);
		int *s = hashMapEntry_getValue(entry);
		memset(&ev, 0, sizeof(ev));
		if(epoll_ctl(ts->topicEpollFd, EPOLL_CTL_DEL, *s, &ev) == -1) {
			printf("in if error()\n");
			perror("epoll_ctl() EPOLL_CTL_DEL");
			status += CELIX_SERVICE_EXCEPTION;
		}
		free(s);
		free(url);
		//hashMapIterator_remove(it);
	}
	hashMapIterator_destroy(it);
	hashMap_clear(ts->socketMap, false, false);
	celixThreadMutex_unlock(&ts->socketMap_lock);


	return status;
}
Esempio n. 6
0
celix_status_t etcdWatcher_destroy(etcd_watcher_pt watcher) {
    celix_status_t status = CELIX_SUCCESS;
    char localNodePath[MAX_LOCALNODE_LENGTH];

    watcher->running = false;

    celixThread_join(watcher->watcherThread, NULL);

    // register own framework
    status = etcdWatcher_getLocalNodePath(watcher->discovery->context, &localNodePath[0]);

    if (status != CELIX_SUCCESS || etcd_del(localNodePath) == false)
    {
        logHelper_log(*watcher->loghelper, OSGI_LOGSERVICE_WARNING, "Cannot remove local discovery registration.");
    }

    watcher->loghelper = NULL;

    hashMap_destroy(watcher->entries, true, true);

    free(watcher);

    return status;
}