celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1651123 - in /celix/trunk: framework/private/src/ remote_services/discovery/private/src/ remote_services/topology_manager/private/include/ remote_services/topology_manager/private/src/
Date Mon, 12 Jan 2015 15:31:05 GMT
Author: abroekhuis
Date: Mon Jan 12 15:31:05 2015
New Revision: 1651123

URL: http://svn.apache.org/r1651123
Log:
CELIX-201: Fixed topology restart.
- Incorrect pointers used in discovery, which would result in a segfault in the manager
- Remove logger creation from the manager and reused the one created by the activator
- Added function to close imports when manager is stopped
- Fixed some memory leaks in the framework

Modified:
    celix/trunk/framework/private/src/framework.c
    celix/trunk/remote_services/discovery/private/src/discovery.c
    celix/trunk/remote_services/topology_manager/private/include/topology_manager.h
    celix/trunk/remote_services/topology_manager/private/src/activator.c
    celix/trunk/remote_services/topology_manager/private/src/topology_manager.c

Modified: celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/framework.c?rev=1651123&r1=1651122&r2=1651123&view=diff
==============================================================================
--- celix/trunk/framework/private/src/framework.c (original)
+++ celix/trunk/framework/private/src/framework.c Mon Jan 12 15:31:05 2015
@@ -276,6 +276,7 @@ celix_status_t framework_destroy(framewo
 	bundleCache_destroy(&framework->cache);
 
 	unsetenv(OSGI_FRAMEWORK_FRAMEWORK_UUID);
+
 	free(framework);
 
 	return status;
@@ -1999,6 +2000,9 @@ static void *framework_shutdown(void *fr
 
     hashMapIterator_destroy(iter);
 
+    pthread_cancel(fw->dispatcherThread.thread);
+    celixThread_join(fw->dispatcherThread, NULL);
+
 	err = celixThreadMutex_lock(&fw->mutex);
 	if (err != 0) {
 		fw_log(fw->logger, OSGI_FRAMEWORK_LOG_ERROR,  "Error locking the framework, cannot exit
clean.");
@@ -2019,10 +2023,10 @@ static void *framework_shutdown(void *fr
 	}
 	err = celixThreadMutex_unlock(&fw->mutex);
 	if (err != 0) {
-		fw_log(fw->logger, OSGI_FRAMEWORK_LOG_ERROR,  "Error unlocking the framework, cannot
exit clean.");
+//		fw_log(fw->logger, OSGI_FRAMEWORK_LOG_ERROR,  "Error unlocking the framework, cannot
exit clean.");
 	}
 
-	fw_log(fw->logger, OSGI_FRAMEWORK_LOG_INFO, "FRAMEWORK: Shutdown done\n");
+//	fw_log(fw->logger, OSGI_FRAMEWORK_LOG_INFO, "FRAMEWORK: Shutdown done\n");
 	celixThread_exit((void *) CELIX_SUCCESS);
 
 	return NULL;

Modified: celix/trunk/remote_services/discovery/private/src/discovery.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery/private/src/discovery.c?rev=1651123&r1=1651122&r2=1651123&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery/private/src/discovery.c (original)
+++ celix/trunk/remote_services/discovery/private/src/discovery.c Mon Jan 12 15:31:05 2015
@@ -97,7 +97,7 @@ celix_status_t discovery_endpointListene
 
 		hash_map_iterator_pt iter = hashMapIterator_create(discovery->discoveredServices);
 		while (hashMapIterator_hasNext(iter)) {
-			endpoint_description_pt endpoint = hashMapIterator_nextKey(iter);
+			endpoint_description_pt endpoint = hashMapIterator_nextValue(iter);
 
 			bool matchResult = false;
 			filter_match(filter, endpoint->properties, &matchResult);
@@ -106,7 +106,7 @@ celix_status_t discovery_endpointListene
 
 				logHelper_log(discovery->loghelper, OSGI_LOGSERVICE_INFO, "EndpointListener Added
- Add Scope");
 
-				listener->endpointAdded(listener, endpoint, NULL);
+				listener->endpointAdded(listener->handle, endpoint, NULL);
 			}
 		}
 		hashMapIterator_destroy(iter);
@@ -200,6 +200,8 @@ celix_status_t discovery_addDiscoveredEn
 
 	status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
 
+	printf("Add new endpoint: %p\n", endpoint);
+
 	char* endpointId = endpoint->id;
 	bool exists = hashMap_get(discovery->discoveredServices, endpointId) != NULL;
 	if (!exists) {
@@ -221,6 +223,8 @@ celix_status_t discovery_removeDiscovere
 
 	status = celixThreadMutex_lock(&discovery->discoveredServicesMutex);
 
+	printf("Remove endpoint: %p\n", endpoint);
+
 	char* endpointId = endpoint->id;
 	void* oldValue = hashMap_remove(discovery->discoveredServices, endpointId);
 

Modified: celix/trunk/remote_services/topology_manager/private/include/topology_manager.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/topology_manager/private/include/topology_manager.h?rev=1651123&r1=1651122&r2=1651123&view=diff
==============================================================================
--- celix/trunk/remote_services/topology_manager/private/include/topology_manager.h (original)
+++ celix/trunk/remote_services/topology_manager/private/include/topology_manager.h Mon Jan
12 15:31:05 2015
@@ -30,11 +30,13 @@
 #include "endpoint_listener.h"
 #include "service_reference.h"
 #include "bundle_context.h"
+#include "log_helper.h"
 
 typedef struct topology_manager *topology_manager_pt;
 
-celix_status_t topologyManager_create(bundle_context_pt context, topology_manager_pt *manager);
+celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper,
topology_manager_pt *manager);
 celix_status_t topologyManager_destroy(topology_manager_pt manager);
+celix_status_t topologyManager_closeImports(topology_manager_pt manager);
 
 celix_status_t topologyManager_rsaAdding(void *handle, service_reference_pt reference, void
**service);
 celix_status_t topologyManager_rsaAdded(void *handle, service_reference_pt reference, void
*service);

Modified: celix/trunk/remote_services/topology_manager/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/topology_manager/private/src/activator.c?rev=1651123&r1=1651122&r2=1651123&view=diff
==============================================================================
--- celix/trunk/remote_services/topology_manager/private/src/activator.c (original)
+++ celix/trunk/remote_services/topology_manager/private/src/activator.c Mon Jan 12 15:31:05
2015
@@ -77,8 +77,9 @@ celix_status_t bundleActivator_create(bu
 	activator->serviceListener = NULL;
 
 	logHelper_create(context, &activator->loghelper);
+	logHelper_start(activator->loghelper);
 
-	status = topologyManager_create(context, &activator->manager);
+	status = topologyManager_create(context, activator->loghelper, &activator->manager);
 	if (status == CELIX_SUCCESS) {
 		status = bundleActivator_createRSATracker(activator, &activator->remoteServiceAdminTracker);
 		if (status == CELIX_SUCCESS) {
@@ -125,8 +126,6 @@ celix_status_t bundleActivator_start(voi
 	celix_status_t status = CELIX_SUCCESS;
 	struct activator *activator = userData;
 
-	logHelper_start(activator->loghelper);
-
 	endpoint_listener_pt endpointListener = malloc(sizeof(*endpointListener));
 	endpointListener->handle = activator->manager;
 	endpointListener->endpointAdded = topologyManager_addImportedService;
@@ -200,7 +199,7 @@ celix_status_t bundleActivator_stop(void
 	serviceRegistration_unregister(activator->endpointListenerService);
 	free(activator->endpointListener);
 
-	logHelper_stop(activator->loghelper);
+	topologyManager_closeImports(activator->manager);
 
 	return status;
 }
@@ -213,6 +212,7 @@ celix_status_t bundleActivator_destroy(v
 		status = CELIX_BUNDLE_EXCEPTION;
 	}
 	else {
+		logHelper_stop(activator->loghelper);
 		logHelper_destroy(&activator->loghelper);
 
 		status = topologyManager_destroy(activator->manager);

Modified: celix/trunk/remote_services/topology_manager/private/src/topology_manager.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/topology_manager/private/src/topology_manager.c?rev=1651123&r1=1651122&r2=1651123&view=diff
==============================================================================
--- celix/trunk/remote_services/topology_manager/private/src/topology_manager.c (original)
+++ celix/trunk/remote_services/topology_manager/private/src/topology_manager.c Mon Jan 12
15:31:05 2015
@@ -68,7 +68,7 @@ struct import_interest {
 celix_status_t topologyManager_notifyListenersEndpointAdded(topology_manager_pt manager,
remote_service_admin_service_pt rsa,  array_list_pt registrations);
 celix_status_t topologyManager_notifyListenersEndpointRemoved(topology_manager_pt manager,
remote_service_admin_service_pt rsa,  export_registration_pt export);
 
-celix_status_t topologyManager_create(bundle_context_pt context, topology_manager_pt *manager)
{
+celix_status_t topologyManager_create(bundle_context_pt context, log_helper_pt logHelper,
topology_manager_pt *manager) {
 	celix_status_t status = CELIX_SUCCESS;
 
 	*manager = malloc(sizeof(**manager));
@@ -89,9 +89,7 @@ celix_status_t topologyManager_create(bu
 	(*manager)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
 	(*manager)->importInterests = hashMap_create(utils_stringHash, NULL, utils_stringEquals,
NULL);
 
-	if (logHelper_create(context, &(*manager)->loghelper) == CELIX_SUCCESS) {
-		logHelper_start((*manager)->loghelper);
-	}
+	(*manager)->loghelper = logHelper;
 
 	return status;
 }
@@ -127,11 +125,47 @@ celix_status_t topologyManager_destroy(t
 	status = celixThreadMutex_unlock(&manager->importInterestsLock);
 	status = celixThreadMutex_destroy(&manager->importInterestsLock);
 
-	if (logHelper_stop(manager->loghelper) == CELIX_SUCCESS) {
-		logHelper_destroy(&manager->loghelper);
+	free(manager);
+
+	return status;
+}
+
+celix_status_t topologyManager_closeImports(topology_manager_pt manager) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = celixThreadMutex_lock(&manager->importedServicesLock);
+
+	hash_map_iterator_pt 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);
+
+		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "TOPOLOGY_MANAGER: Remove imported
service (%s; %s).", ep->service, ep->id);
+		hash_map_iterator_pt importsIter = hashMapIterator_create(imports);
+
+		while (hashMapIterator_hasNext(importsIter)) {
+			hash_map_entry_pt entry = hashMapIterator_nextEntry(importsIter);
+
+			remote_service_admin_service_pt rsa = hashMapEntry_getKey(entry);
+			import_registration_pt import = hashMapEntry_getValue(entry);
+
+			status = rsa->importRegistration_close(rsa->admin, import);
+			if (status == CELIX_SUCCESS) {
+				hashMapIterator_remove(importsIter);
+			}
+		}
+		hashMapIterator_destroy(importsIter);
+
+		hashMapIterator_remove(iter);
+
+		if (imports != NULL) {
+			hashMap_destroy(imports, false, false);
+		}
 	}
+	hashMapIterator_destroy(iter);
 
-	free(manager);
+	status = celixThreadMutex_unlock(&manager->importedServicesLock);
 
 	return status;
 }



Mime
View raw message