You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by bp...@apache.org on 2015/10/05 08:08:07 UTC

celix git commit: CELIX-265: refactored discovery_shm to set non-default configuration

Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-265_discovery_improvement 6b9c29593 -> 523b37168


CELIX-265: refactored discovery_shm to set non-default configuration


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/523b3716
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/523b3716
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/523b3716

Branch: refs/heads/feature/CELIX-265_discovery_improvement
Commit: 523b371682eae56ca96128a491a6c983b177c76d
Parents: 6b9c295
Author: Bjoern Petri <bp...@apache.org>
Authored: Mon Oct 5 08:06:58 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Mon Oct 5 08:06:58 2015 +0200

----------------------------------------------------------------------
 .../private/include/endpoint_discovery_poller.h |  2 +-
 .../discovery_shm/private/include/shm_watcher.h |  3 ++-
 .../discovery_shm/private/src/discovery_impl.c  | 19 +++-----------
 .../discovery_shm/private/src/shm_watcher.c     | 27 ++++++++++++--------
 4 files changed, 22 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/523b3716/remote_services/discovery/private/include/endpoint_discovery_poller.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/include/endpoint_discovery_poller.h b/remote_services/discovery/private/include/endpoint_discovery_poller.h
index 1bb6679..c362973 100644
--- a/remote_services/discovery/private/include/endpoint_discovery_poller.h
+++ b/remote_services/discovery/private/include/endpoint_discovery_poller.h
@@ -50,6 +50,6 @@ celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poll
 
 celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
 celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url);
-
+celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls);
 
 #endif /* ENDPOINT_DISCOVERY_POLLER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/523b3716/remote_services/discovery_shm/private/include/shm_watcher.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/include/shm_watcher.h b/remote_services/discovery_shm/private/include/shm_watcher.h
index f99007f..59c32e5 100644
--- a/remote_services/discovery_shm/private/include/shm_watcher.h
+++ b/remote_services/discovery_shm/private/include/shm_watcher.h
@@ -33,7 +33,8 @@
 
 typedef struct shm_watcher *shm_watcher_pt;
 
-celix_status_t shmWatcher_create(endpoint_discovery_poller_pt poller, bundle_context_pt context, shm_watcher_pt *watcher);
+
+celix_status_t shmWatcher_create(discovery_pt discovery, bundle_context_pt context, shm_watcher_pt *watcher);
 celix_status_t shmWatcher_destroy(shm_watcher_pt watcher);
 
 

http://git-wip-us.apache.org/repos/asf/celix/blob/523b3716/remote_services/discovery_shm/private/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/src/discovery_impl.c b/remote_services/discovery_shm/private/src/discovery_impl.c
index 1fb5330..5159edc 100644
--- a/remote_services/discovery_shm/private/src/discovery_impl.c
+++ b/remote_services/discovery_shm/private/src/discovery_impl.c
@@ -109,33 +109,20 @@ celix_status_t discovery_destroy(discovery_pt discovery) {
 
 celix_status_t discovery_start(discovery_pt discovery) {
     celix_status_t status = CELIX_SUCCESS;
-	char *port = NULL;
-	char *path = NULL;
-
-
-	bundleContext_getProperty(discovery->context, DISCOVERY_SERVER_PORT, &port);
-	if (port == NULL) {
-		port = DEFAULT_SERVER_PORT;
-	}
-
-	bundleContext_getProperty(discovery->context, DISCOVERY_SERVER_PATH, &path);
-	if (path == NULL) {
-		path = DEFAULT_SERVER_PATH;
-	}
 
     status = endpointDiscoveryPoller_create(discovery, discovery->context, &discovery->poller);
     if (status != CELIX_SUCCESS) {
     	return CELIX_BUNDLE_EXCEPTION;
     }
 
-    status = shmWatcher_create(discovery->poller, discovery->context, &discovery->watcher);
+    status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
     if (status != CELIX_SUCCESS) {
     	return CELIX_BUNDLE_EXCEPTION;
     }
 
-    status = endpointDiscoveryServer_create(discovery, discovery->context, &discovery->server);
+    status = shmWatcher_create(discovery, discovery->context, &discovery->watcher);
     if (status != CELIX_SUCCESS) {
-    	return CELIX_BUNDLE_EXCEPTION;
+        return CELIX_BUNDLE_EXCEPTION;
     }
 
     return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/523b3716/remote_services/discovery_shm/private/src/shm_watcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/src/shm_watcher.c b/remote_services/discovery_shm/private/src/shm_watcher.c
index 2152345..cd21344 100644
--- a/remote_services/discovery_shm/private/src/shm_watcher.c
+++ b/remote_services/discovery_shm/private/src/shm_watcher.c
@@ -39,7 +39,7 @@
 #include "endpoint_discovery_poller.h"
 
 struct shm_watcher {
-    endpoint_discovery_poller_pt poller;
+    discovery_pt discovery;
     bundle_context_pt context;
 
     shmData_pt shmData;
@@ -79,6 +79,7 @@ static celix_status_t shmWatcher_getLocalNodePath(bundle_context_pt context, cha
 /* retrieves all endpoints from shm and syncs them with the ones already available */
 static celix_status_t shmWatcher_syncEndpoints(shm_watcher_pt watcher) {
     celix_status_t status = CELIX_SUCCESS;
+    endpoint_discovery_poller_pt poller = watcher->discovery->poller;
     char** shmKeyArr = calloc(SHM_DATA_MAX_ENTRIES, sizeof(*shmKeyArr));
     array_list_pt registeredKeyArr = NULL; //calloc(SHM_DATA_MAX_ENTRIES, sizeof(*registeredKeyArr));
 
@@ -94,7 +95,7 @@ static celix_status_t shmWatcher_syncEndpoints(shm_watcher_pt watcher) {
     discovery_shmGetKeys(watcher->shmData, shmKeyArr, &shmSize);
 
     // get all locally registered endpoints
-    endpointDiscoveryPoller_getDiscoveryEndpoints(watcher->poller, registeredKeyArr);
+    endpointDiscoveryPoller_getDiscoveryEndpoints(poller, registeredKeyArr);
 
     // add discovery points which are in shm, but not local yet
     for (i = 0; i < shmSize; i++) {
@@ -111,7 +112,7 @@ static celix_status_t shmWatcher_syncEndpoints(shm_watcher_pt watcher) {
             }
 
             if (elementFound == false) {
-                endpointDiscoveryPoller_addDiscoveryEndpoint(watcher->poller, url);
+                endpointDiscoveryPoller_addDiscoveryEndpoint(poller, url);
             }
         }
     }
@@ -121,7 +122,7 @@ static celix_status_t shmWatcher_syncEndpoints(shm_watcher_pt watcher) {
         char* regUrl = arrayList_get(registeredKeyArr, i);
 
         if (regUrl != NULL) {
-            endpointDiscoveryPoller_removeDiscoveryEndpoint(watcher->poller, regUrl);
+            endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, regUrl);
         }
     }
 
@@ -142,20 +143,23 @@ static celix_status_t shmWatcher_syncEndpoints(shm_watcher_pt watcher) {
 
 static void* shmWatcher_run(void* data) {
     shm_watcher_pt watcher = (shm_watcher_pt) data;
+    endpoint_discovery_server_pt server = watcher->discovery->server;
+
     char localNodePath[MAX_LOCALNODE_LENGTH];
-    char* endpoints = NULL;
+    char url[SHM_ENTRY_MAX_VALUE_LENGTH];
 
     if (shmWatcher_getLocalNodePath(watcher->context, &localNodePath[0]) != CELIX_SUCCESS) {
         fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "Cannot register local discovery");
     }
 
-    if ((bundleContext_getProperty(watcher->context, DISCOVERY_POLL_ENDPOINTS, &endpoints) != CELIX_SUCCESS) || !endpoints) {
-        endpoints = DEFAULT_POLL_ENDPOINTS;
+
+    if (endpointDiscoveryServer_getUrl(server, &url[0]) != CELIX_SUCCESS) {
+        snprintf(url, SHM_ENTRY_MAX_VALUE_LENGTH, "http://%s:%s/%s", DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT, DEFAULT_SERVER_PATH);
     }
 
     while (watcher->running) {
         // register own framework
-        if (discovery_shmSet(watcher->shmData, localNodePath, endpoints) != CELIX_SUCCESS) {
+        if (discovery_shmSet(watcher->shmData, localNodePath, url) != CELIX_SUCCESS) {
             fw_log(logger, OSGI_FRAMEWORK_LOG_WARNING, "Cannot register local discovery");
         }
 
@@ -166,10 +170,11 @@ static void* shmWatcher_run(void* data) {
     return NULL;
 }
 
-celix_status_t shmWatcher_create(endpoint_discovery_poller_pt poller, bundle_context_pt context, shm_watcher_pt *watcher) {
+celix_status_t shmWatcher_create(discovery_pt discovery, bundle_context_pt context, shm_watcher_pt *watcher) {
     celix_status_t status = CELIX_SUCCESS;
 
-    if (poller == NULL) {
+
+    if (discovery == NULL) {
         return CELIX_BUNDLE_EXCEPTION;
     }
 
@@ -177,7 +182,7 @@ celix_status_t shmWatcher_create(endpoint_discovery_poller_pt poller, bundle_con
     if (!*watcher) {
         return CELIX_ENOMEM;
     } else {
-        (*watcher)->poller = poller;
+        (*watcher)->discovery = discovery;
         (*watcher)->context = context;
         if (discovery_shmAttach(&((*watcher)->shmData)) != CELIX_SUCCESS)
             discovery_shmCreate(&((*watcher)->shmData));