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/04 22:47:08 UTC

celix git commit: CELIX-265: Add discovery_update functionality to perform poll when etcd-update is triggered

Repository: celix
Updated Branches:
  refs/heads/feature/CELIX-265_discovery_improvement [created] 6b9c29593


CELIX-265: Add discovery_update functionality to perform poll when etcd-update is triggered


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

Branch: refs/heads/feature/CELIX-265_discovery_improvement
Commit: 6b9c29593d493322850106a75d9214578cf1e7cd
Parents: d632500
Author: Bjoern Petri <bp...@apache.org>
Authored: Sun Oct 4 22:44:42 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Sun Oct 4 22:44:42 2015 +0200

----------------------------------------------------------------------
 .../discovery/private/src/discovery.c           |  8 +++++
 .../private/src/endpoint_discovery_poller.c     | 33 +++++++++++++-------
 .../private/include/discovery_impl.h            |  2 ++
 .../private/src/discovery_impl.c                | 11 +++++++
 .../private/include/discovery_impl.h            |  3 ++
 .../private/include/etcd_watcher.h              |  2 +-
 .../discovery_etcd/private/src/discovery_impl.c | 21 ++++++-------
 .../discovery_etcd/private/src/etcd_watcher.c   | 10 +++---
 .../private/include/discovery_impl.h            |  2 ++
 .../discovery_shm/private/src/discovery_impl.c  |  6 ++++
 10 files changed, 68 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery/private/src/discovery.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/discovery.c b/remote_services/discovery/private/src/discovery.c
index ee3c293..8e899e5 100644
--- a/remote_services/discovery/private/src/discovery.c
+++ b/remote_services/discovery/private/src/discovery.c
@@ -43,6 +43,10 @@ celix_status_t discovery_endpointAdded(void *handle, endpoint_description_pt end
 
 	status = endpointDiscoveryServer_addEndpoint(discovery->server, endpoint);
 
+	if (status == CELIX_SUCCESS) {
+	    discovery_update(discovery);
+	}
+
 	return status;
 }
 
@@ -54,6 +58,10 @@ celix_status_t discovery_endpointRemoved(void *handle, endpoint_description_pt e
 
 	status = endpointDiscoveryServer_removeEndpoint(discovery->server, endpoint);
 
+	if (status == CELIX_SUCCESS) {
+        discovery_update(discovery);
+    }
+
 	return status;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c b/remote_services/discovery/private/src/endpoint_discovery_poller.c
index ac819c5..0ada46f 100644
--- a/remote_services/discovery/private/src/endpoint_discovery_poller.c
+++ b/remote_services/discovery/private/src/endpoint_discovery_poller.c
@@ -101,10 +101,16 @@ celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_con
         return CELIX_BUNDLE_EXCEPTION;
     }
 
-	status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller);
-	if (status != CELIX_SUCCESS) {
-		return status;
-	}
+    if ((*poller)->poll_interval > 0) {
+
+        status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller);
+        if (status != CELIX_SUCCESS) {
+            return status;
+        }
+    }
+    else {
+        logHelper_log(*(*poller)->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: periodic polling disabled!");
+    }
 
 	(*poller)->running = true;
 
@@ -171,7 +177,7 @@ celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_
 }
 
 /**
- * Adds a new endpoint URL to the list of polled endpoints.
+ * Adds a new endpoint URL to the list of polled endpoints. In case the URL already exists, a poll is performed
  */
 celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url) {
 	celix_status_t status;
@@ -192,6 +198,9 @@ celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_p
 			endpointDiscoveryPoller_poll(poller, url, endpoints);
 		}
 	}
+	else {
+        endpointDiscoveryPoller_poll(poller, url, endpoints);
+	}
 
 	status = celixThreadMutex_unlock(&poller->pollerLock);
 
@@ -248,9 +257,7 @@ celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller,
 	arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &updatedEndpoints);
 	status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);
 
-	if (status != CELIX_SUCCESS) {
-		status = celixThreadMutex_unlock(&poller->pollerLock);
-	} else {
+	if (status == CELIX_SUCCESS) {
 		if (updatedEndpoints) {
 			for (unsigned int i = arrayList_size(currentEndpoints); i > 0; i--) {
 				endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i - 1);
@@ -295,6 +302,7 @@ static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) {
 		if (status != CELIX_SUCCESS) {
 			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to obtain lock; retrying...");
 		} else {
+
 			hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
 
 			while (hashMapIterator_hasNext(iterator)) {
@@ -307,11 +315,12 @@ static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) {
 			}
 
 			hashMapIterator_destroy(iterator);
-		}
 
-		status = celixThreadMutex_unlock(&poller->pollerLock);
-		if (status != CELIX_SUCCESS) {
-			logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to release lock; retrying...");
+			status = celixThreadMutex_unlock(&poller->pollerLock);
+
+			if (status != CELIX_SUCCESS) {
+				logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to release lock; retrying...");
+			}
 		}
 	}
 

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery_configured/private/include/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/private/include/discovery_impl.h b/remote_services/discovery_configured/private/include/discovery_impl.h
index 0414eac..6b34b9a 100644
--- a/remote_services/discovery_configured/private/include/discovery_impl.h
+++ b/remote_services/discovery_configured/private/include/discovery_impl.h
@@ -59,4 +59,6 @@ struct discovery {
 	log_helper_pt loghelper;
 };
 
+celix_status_t discovery_update(discovery_pt discovery);
+
 #endif /* DISCOVERY_IMPL_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery_configured/private/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_configured/private/src/discovery_impl.c b/remote_services/discovery_configured/private/src/discovery_impl.c
index 35a0c71..fcb1738 100644
--- a/remote_services/discovery_configured/private/src/discovery_impl.c
+++ b/remote_services/discovery_configured/private/src/discovery_impl.c
@@ -121,3 +121,14 @@ celix_status_t discovery_destroy(discovery_pt discovery) {
 
 	return status;
 }
+
+/**
+ * discovery_update usually triggers a clientside rep-oll of the
+ * endpoint informations. This unfortunately is not possible for
+ * discovery_configured.
+ */
+celix_status_t discovery_update(discovery_pt discovery) {
+    return CELIX_SUCCESS;
+}
+
+

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery_etcd/private/include/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/private/include/discovery_impl.h b/remote_services/discovery_etcd/private/include/discovery_impl.h
index e7e1071..cfc0e89 100644
--- a/remote_services/discovery_etcd/private/include/discovery_impl.h
+++ b/remote_services/discovery_etcd/private/include/discovery_impl.h
@@ -65,4 +65,7 @@ struct discovery {
 	log_helper_pt loghelper;
 };
 
+
+celix_status_t discovery_update(discovery_pt discovery);
+
 #endif /* DISCOVERY_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery_etcd/private/include/etcd_watcher.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/private/include/etcd_watcher.h b/remote_services/discovery_etcd/private/include/etcd_watcher.h
index b4dbf40..bf7dd27 100644
--- a/remote_services/discovery_etcd/private/include/etcd_watcher.h
+++ b/remote_services/discovery_etcd/private/include/etcd_watcher.h
@@ -35,6 +35,6 @@ typedef struct etcd_watcher *etcd_watcher_pt;
 
 celix_status_t etcdWatcher_create(discovery_pt discovery,  bundle_context_pt context, etcd_watcher_pt *watcher);
 celix_status_t etcdWatcher_destroy(etcd_watcher_pt watcher);
-
+celix_status_t etcdWatcher_registerDiscovery(etcd_watcher_pt watcher);
 
 #endif /* ETCD_WATCHER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery_etcd/private/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/private/src/discovery_impl.c b/remote_services/discovery_etcd/private/src/discovery_impl.c
index b8d7d5c..ff6127a 100644
--- a/remote_services/discovery_etcd/private/src/discovery_impl.c
+++ b/remote_services/discovery_etcd/private/src/discovery_impl.c
@@ -109,21 +109,9 @@ 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;
 
 	logHelper_start(discovery->loghelper);
 
-	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;
@@ -182,4 +170,13 @@ celix_status_t discovery_stop(discovery_pt discovery) {
 }
 
 
+celix_status_t discovery_update(discovery_pt discovery) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    status = etcdWatcher_registerDiscovery(discovery->watcher);
+
+    return status;
+}
+
+
 

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery_etcd/private/src/etcd_watcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/private/src/etcd_watcher.c b/remote_services/discovery_etcd/private/src/etcd_watcher.c
index c54fcdc..195e2a0 100644
--- a/remote_services/discovery_etcd/private/src/etcd_watcher.c
+++ b/remote_services/discovery_etcd/private/src/etcd_watcher.c
@@ -150,7 +150,7 @@ static celix_status_t etcdWatcher_addAlreadyExistingWatchpoints(discovery_pt dis
 }
 
 
-static celix_status_t etcdWatcher_addOwnFramework(etcd_watcher_pt watcher)
+celix_status_t etcdWatcher_registerDiscovery(etcd_watcher_pt watcher)
 {
     celix_status_t status = CELIX_BUNDLE_EXCEPTION;
     char localNodePath[MAX_LOCALNODE_LENGTH];
@@ -209,9 +209,9 @@ static celix_status_t etcdWatcher_addEntry(etcd_watcher_pt watcher, char* key, c
 	celix_status_t status = CELIX_BUNDLE_EXCEPTION;
 	endpoint_discovery_poller_pt poller = watcher->discovery->poller;
 
-	if (!hashMap_containsKey(watcher->entries, key)) {
-		status = endpointDiscoveryPoller_addDiscoveryEndpoint(poller, value);
+    status = endpointDiscoveryPoller_addDiscoveryEndpoint(poller, value);
 
+	if (!hashMap_containsKey(watcher->entries, key)) {
 		if (status == CELIX_SUCCESS) {
 			hashMap_put(watcher->entries, strdup(key), strdup(value));
 		}
@@ -288,7 +288,7 @@ static void* etcdWatcher_run(void* data) {
 
 		// update own framework uuid
 		if (time(NULL) - timeBeforeWatch > (DEFAULT_ETCD_TTL/2)) {
-			etcdWatcher_addOwnFramework(watcher);
+		    etcdWatcher_registerDiscovery(watcher);
 			timeBeforeWatch = time(NULL);
 		}
 	}
@@ -347,7 +347,7 @@ celix_status_t etcdWatcher_create(discovery_pt discovery, bundle_context_pt cont
 		return status;
 	}
 
-	etcdWatcher_addOwnFramework(*watcher);
+	etcdWatcher_registerDiscovery(*watcher);
 
 	if ((status = celixThreadMutex_create(&(*watcher)->watcherLock, NULL)) != CELIX_SUCCESS) {
 		return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/remote_services/discovery_shm/private/include/discovery_impl.h
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/include/discovery_impl.h b/remote_services/discovery_shm/private/include/discovery_impl.h
index fa6d7bf..5d4e818 100644
--- a/remote_services/discovery_shm/private/include/discovery_impl.h
+++ b/remote_services/discovery_shm/private/include/discovery_impl.h
@@ -63,4 +63,6 @@ struct discovery {
 	log_helper_pt loghelper;
 };
 
+celix_status_t discovery_update(discovery_pt discovery);
+
 #endif /* DISCOVERY_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/6b9c2959/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 1451c41..1fb5330 100644
--- a/remote_services/discovery_shm/private/src/discovery_impl.c
+++ b/remote_services/discovery_shm/private/src/discovery_impl.c
@@ -181,4 +181,10 @@ celix_status_t discovery_stop(discovery_pt discovery) {
 }
 
 
+celix_status_t discovery_update(discovery_pt discovery) {
+    celix_status_t status = CELIX_SUCCESS;
+
+
+    return status;
+}