celix_status_t wiringTopologyManager_waRemoved(void * handle, service_reference_pt reference, void * service) {
    celix_status_t status = CELIX_SUCCESS;
    wiring_topology_manager_pt manager = handle;
    wiring_admin_service_pt wiringAdminService = (wiring_admin_service_pt) service;

    /* check whether one of the exported Wires can be exported here via the newly available wiringAdmin*/
    celixThreadMutex_lock(&manager->exportedWiringEndpointsLock);
    hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedWiringEndpoints);
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        hash_map_pt wiringAdminMap = hashMapEntry_getValue(entry);

        if (hashMap_containsKey(wiringAdminMap, wiringAdminService)) {
            wiring_endpoint_description_pt wEndpoint = (wiring_endpoint_description_pt) hashMap_remove(wiringAdminMap, wiringAdminService);

            status = wiringTopologyManager_notifyListenersWiringEndpointRemoved(manager, wEndpoint);

            if (status == CELIX_SUCCESS) {
                status = wiringAdminService->removeExportedWiringEndpoint(wiringAdminService->admin, wEndpoint);
            } else {
                printf("WTM: failed while removing WiringAdmin.\n");
            }
        }
    }

    hashMapIterator_destroy(iter);

    celixThreadMutex_unlock(&manager->exportedWiringEndpointsLock);

    /* Check if the added WA can match one of the imported WiringEndpoints */
    celixThreadMutex_lock(&manager->importedWiringEndpointsLock);
    iter = hashMapIterator_create(manager->importedWiringEndpoints);
    while (hashMapIterator_hasNext(iter)) {
        hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
        wiring_endpoint_description_pt importedWiringEndpointDesc = hashMapEntry_getKey(entry);
        array_list_pt wiringAdminList = hashMapEntry_getValue(entry);

        if (arrayList_contains(wiringAdminList, wiringAdminService)) {
            status = wiringAdminService->removeImportedWiringEndpoint(wiringAdminService->admin, importedWiringEndpointDesc);
            arrayList_removeElement(wiringAdminList, wiringAdminService);
        }

        if (status == CELIX_SUCCESS) {
            arrayList_add(wiringAdminList, wiringAdminService);
        }

    }
    hashMapIterator_destroy(iter);
    celixThreadMutex_unlock(&manager->importedWiringEndpointsLock);

    celixThreadMutex_lock(&manager->waListLock);
    arrayList_removeElement(manager->waList, wiringAdminService);
    celixThreadMutex_unlock(&manager->waListLock);

    printf("WTM: Removed WA\n");

    return status;
}
celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints) {
	celix_status_t status;
	array_list_pt updatedEndpoints = NULL;

	// create an arraylist with a custom equality test to ensure we can find endpoints properly...
	arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &updatedEndpoints);
	status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);

	if (status != CELIX_SUCCESS) {
		status = celixThreadMutex_unlock(&poller->pollerLock);
	} else {
		if (updatedEndpoints) {
			for (unsigned int i = arrayList_size(currentEndpoints); i > 0; i--) {
				endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i - 1);

				if (!arrayList_contains(updatedEndpoints, endpoint)) {
					status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
					arrayList_remove(currentEndpoints, i - 1);
					endpointDescription_destroy(endpoint);
				}
			}

			for (int i = arrayList_size(updatedEndpoints); i > 0; i--) {
				endpoint_description_pt endpoint = arrayList_remove(updatedEndpoints, 0);

				if (!arrayList_contains(currentEndpoints, endpoint)) {
					arrayList_add(currentEndpoints, endpoint);
					status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
				} else {
					endpointDescription_destroy(endpoint);

				}
			}
		}

		if (updatedEndpoints) {
			arrayList_destroy(updatedEndpoints);
		}
	}

	return status;
}
Exemple #3
0
void test_arrayList_contains(void) {
	char * entry = "entry";
	char * entry2 = "entry2";
	char * entry3 = NULL;
	bool contains;

	arrayList_clear(list);

	arrayList_add(list, entry);

	arrayList_add(list, entry2);

	CU_ASSERT_TRUE(arrayList_contains(list, entry));
	CU_ASSERT_TRUE(arrayList_contains(list, entry2));
	contains = arrayList_contains(list, NULL);
	CU_ASSERT_FALSE(contains);

	arrayList_add(list, entry3);

	CU_ASSERT_TRUE(arrayList_contains(list, entry3));
}