celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1643222 - in /celix/trunk/remote_services: remote_service_admin/public/include/ remote_service_admin_http/ remote_service_admin_http/private/include/ remote_service_admin_http/private/src/
Date Fri, 05 Dec 2014 10:08:22 GMT
Author: bpetri
Date: Fri Dec  5 10:08:22 2014
New Revision: 1643222

URL: http://svn.apache.org/viewvc?rev=1643222&view=rev
Log:
CELIX-192: add locking, fixed minor issues in export- and import-registration 

Modified:
    celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
    celix/trunk/remote_services/remote_service_admin_http/CMakeLists.txt
    celix/trunk/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
    celix/trunk/remote_services/remote_service_admin_http/private/src/export_registration_impl.c
    celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c
    celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c

Modified: celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h?rev=1643222&r1=1643221&r2=1643222&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
(original)
+++ celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint_impl.h
Fri Dec  5 10:08:22 2014
@@ -28,10 +28,11 @@
 #define REMOTE_ENDPOINT_IMPL_H_
 
 #include "remote_endpoint.h"
+#include "celix_threads.h"
 
 struct remote_endpoint {
+	celix_thread_mutex_t serviceLock;
 	void *service;
-//	apr_pool_t* pool;
 };
 
 #endif /* REMOTE_ENDPOINT_IMPL_H_ */

Modified: celix/trunk/remote_services/remote_service_admin_http/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/CMakeLists.txt?rev=1643222&r1=1643221&r2=1643222&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_http/CMakeLists.txt (original)
+++ celix/trunk/remote_services/remote_service_admin_http/CMakeLists.txt Fri Dec  5 10:08:22
2014
@@ -18,6 +18,7 @@
 find_package(APR REQUIRED)
 find_package(CURL REQUIRED)
 
+
 include_directories(${CURL_INCLUDE_DIRS})
 include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
 include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
@@ -43,4 +44,4 @@ bundle(remote_service_admin_http SOURCES
 
 install_bundle(remote_service_admin_http)
     
-target_link_libraries(remote_service_admin_http celix_framework ${APRUTIL_LIBRARY} ${CURL_LIBRARIES})
+target_link_libraries(remote_service_admin_http celix_framework  ${APRUTIL_LIBRARY} ${CURL_LIBRARIES})

Modified: celix/trunk/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h?rev=1643222&r1=1643221&r2=1643222&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
(original)
+++ celix/trunk/remote_services/remote_service_admin_http/private/include/remote_service_admin_http_impl.h
Fri Dec  5 10:08:22 2014
@@ -36,7 +36,10 @@ struct remote_service_admin {
 	bundle_context_pt context;
 	log_helper_pt loghelper;
 
+	celix_thread_mutex_t exportedServicesLock;
 	hash_map_pt exportedServices;
+
+	celix_thread_mutex_t importedServicesLock;
 	hash_map_pt importedServices;
 
 	char *port;

Modified: celix/trunk/remote_services/remote_service_admin_http/private/src/export_registration_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/private/src/export_registration_impl.c?rev=1643222&r1=1643221&r2=1643222&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_http/private/src/export_registration_impl.c
(original)
+++ celix/trunk/remote_services/remote_service_admin_http/private/src/export_registration_impl.c
Fri Dec  5 10:08:22 2014
@@ -158,6 +158,7 @@ celix_status_t exportRegistration_endpoi
 
 	remote_endpoint_service_pt endpoint = service;
 	if (registration->endpoint != NULL) {
+		remoteServiceAdmin_removeExportedService(registration);
 		registration->endpoint = NULL;
 		endpoint->setService(endpoint->endpoint, NULL);
 	}

Modified: celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c?rev=1643222&r1=1643221&r2=1643222&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c
(original)
+++ celix/trunk/remote_services/remote_service_admin_http/private/src/import_registration_impl.c
Fri Dec  5 10:08:22 2014
@@ -229,8 +229,8 @@ celix_status_t importRegistrationFactory
 		// check whether factory is available
 		if (((*registration_factory)->trackedFactory == NULL) && ((status = importRegistrationFactory_open(*registration_factory))
!= CELIX_SUCCESS)) {
 			logHelper_log((*registration_factory)->loghelper, OSGI_LOGSERVICE_ERROR, "remoteServiceAdmin_importService:
cannot open registration_factory for %s.", serviceName);
-			importRegistrationFactory_destroy(registration_factory);
 			serviceTracker_close((*registration_factory)->proxyFactoryTracker);
+			importRegistrationFactory_destroy(registration_factory);
 		}
 	}
 

Modified: celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c?rev=1643222&r1=1643221&r2=1643222&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
(original)
+++ celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
Fri Dec  5 10:08:22 2014
@@ -53,7 +53,7 @@
 #include "service_registration.h"
 #include "log_helper.h"
 #include "log_service.h"
-
+#include "celix_threads.h"
 
 // defines how often the webserver is restarted (with an increased port number)
 #define MAX_NUMBER_OF_RESTARTS 	5
@@ -112,6 +112,9 @@ celix_status_t remoteServiceAdmin_create
 		(*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
 		(*admin)->importedServices = hashMap_create(NULL, NULL, NULL, NULL);
 
+		celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
+		celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
+
 		if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
 			logHelper_start((*admin)->loghelper);
 		}
@@ -201,6 +204,9 @@ celix_status_t remoteServiceAdmin_stop(r
 		}
 	}
     hashMapIterator_destroy(iter);
+
+    celixThreadMutex_lock(&admin->importedServicesLock);
+
     iter = hashMapIterator_create(admin->importedServices);
     while (hashMapIterator_hasNext(iter))
     {
@@ -220,6 +226,7 @@ celix_status_t remoteServiceAdmin_stop(r
         importRegistrationFactory_close(importFactory);
     }
     hashMapIterator_destroy(iter);
+    celixThreadMutex_unlock(&admin->importedServicesLock);
 
 	if (admin->ctx != NULL) {
 		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Stopping webserver...");
@@ -245,10 +252,13 @@ static int remoteServiceAdmin_callback(s
 	if (request_info->uri != NULL) {
 		remote_service_admin_pt rsa = request_info->user_data;
 
+
 		if (strncmp(request_info->uri, "/service/", 9) == 0 && strcmp("POST", request_info->request_method)
== 0) {
+
 			// uri = /services/myservice/call
 			const char *uri = request_info->uri;
 			// rest = myservice/call
+
 			const char *rest = uri+9;
 			char *interfaceStart = strchr(rest, '/');
 			int pos = interfaceStart - rest;
@@ -256,6 +266,8 @@ static int remoteServiceAdmin_callback(s
 			strncpy(service, rest, pos);
 			service[pos] = '\0';
 
+			celixThreadMutex_lock(&rsa->exportedServicesLock);
+
 			hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
 			while (hashMapIterator_hasNext(iter)) {
 				hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
@@ -287,6 +299,8 @@ static int remoteServiceAdmin_callback(s
 					}
 				}
 			}
+			celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
             hashMapIterator_destroy(iter);
 		}
 	}
@@ -295,6 +309,8 @@ static int remoteServiceAdmin_callback(s
 }
 
 celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_pt rsa, char *service,
char *data, char **reply) {
+	celixThreadMutex_lock(&rsa->exportedServicesLock);
+
 	hash_map_iterator_pt iter = hashMapIterator_create(rsa->exportedServices);
 	while (hashMapIterator_hasNext(iter)) {
 		hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
@@ -308,6 +324,9 @@ celix_status_t remoteServiceAdmin_handle
 		}
 	}
     hashMapIterator_destroy(iter);
+
+	celixThreadMutex_unlock(&rsa->exportedServicesLock);
+
 	return CELIX_SUCCESS;
 }
 
@@ -387,7 +406,10 @@ celix_status_t remoteServiceAdmin_export
 				exportRegistration_open(registration);
 				exportRegistration_startTracking(registration);
 			}
+			celixThreadMutex_lock(&admin->exportedServicesLock);
 			hashMap_put(admin->exportedServices, reference, *registrations);
+			celixThreadMutex_unlock(&admin->exportedServicesLock);
+
 		}
 		arrayList_destroy(interfaces);
 	}
@@ -399,7 +421,10 @@ celix_status_t remoteServiceAdmin_remove
     celix_status_t status = CELIX_SUCCESS;
     remote_service_admin_pt admin = registration->rsa;
 
+    celixThreadMutex_lock(&admin->exportedServicesLock);
+
     hashMap_remove(admin->exportedServices, registration->reference);
+    celixThreadMutex_unlock(&admin->exportedServicesLock);
 
     return status;
 }
@@ -408,6 +433,7 @@ celix_status_t remoteServiceAdmin_instal
 	celix_status_t status = CELIX_SUCCESS;
 	properties_pt endpointProperties = properties_create();
 
+
 	unsigned int size = 0;
     char **keys;
 
@@ -520,6 +546,8 @@ celix_status_t remoteServiceAdmin_import
 
 	logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Import service %s", endpointDescription->service);
 
+	celixThreadMutex_lock(&admin->importedServicesLock);
+
    import_registration_factory_pt registration_factory = (import_registration_factory_pt)
hashMap_get(admin->importedServices, endpointDescription->service);
 
 	// check whether we already have a registration_factory registered in the hashmap
@@ -545,6 +573,9 @@ celix_status_t remoteServiceAdmin_import
 		arrayList_add(registration_factory->registrations, *registration);
 	}
 
+    celixThreadMutex_unlock(&admin->importedServicesLock);
+
+
 	return status;
 }
 
@@ -552,7 +583,11 @@ celix_status_t remoteServiceAdmin_import
 celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt
registration) {
 	celix_status_t status = CELIX_SUCCESS;
 	endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
-	import_registration_factory_pt registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices,
endpointDescription->service);
+	import_registration_factory_pt registration_factory = NULL;
+
+    celixThreadMutex_lock(&admin->importedServicesLock);
+
+    registration_factory = (import_registration_factory_pt) hashMap_get(admin->importedServices,
endpointDescription->service);
 
     // factory available
     if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL))
@@ -577,6 +612,8 @@ celix_status_t remoteServiceAdmin_remove
 		}
     }
 
+    celixThreadMutex_unlock(&admin->importedServicesLock);
+
 	return status;
 }
 
@@ -602,6 +639,8 @@ celix_status_t remoteServiceAdmin_send(r
     if(!curl) {
         status = CELIX_ILLEGAL_STATE;
     } else {
+
+
         curl_easy_setopt(curl, CURLOPT_URL, url);
         curl_easy_setopt(curl, CURLOPT_POST, 1L);
         curl_easy_setopt(curl, CURLOPT_READFUNCTION, remoteServiceAdmin_readCallback);



Mime
View raw message