Ejemplo n.º 1
0
celix_status_t etcdWatcher_create(node_discovery_pt node_discovery, bundle_context_pt context, etcd_watcher_pt *watcher) {
    celix_status_t status = CELIX_SUCCESS;

    char* etcd_server = NULL;
    char* etcd_port_string = NULL;
    int etcd_port = 0;

    if (node_discovery == NULL) {
        return CELIX_BUNDLE_EXCEPTION;
    }

    (*watcher) = calloc(1, sizeof(struct etcd_watcher));

    if (*watcher) {
        (*watcher)->node_discovery = node_discovery;

        if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_IP, &etcd_server) != CELIX_SUCCESS) || !etcd_server) {
            etcd_server = DEFAULT_ETCD_SERVER_IP;
        }

        if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_PORT, &etcd_port_string) != CELIX_SUCCESS) || !etcd_port_string) {
            etcd_port = DEFAULT_ETCD_SERVER_PORT;
        } else {
            char* endptr = etcd_port_string;
            errno = 0;
            etcd_port = strtol(etcd_port_string, &endptr, 10);
            if (*endptr || errno != 0) {
                etcd_port = DEFAULT_ETCD_SERVER_PORT;
            }
        }

        if (etcd_init(etcd_server, etcd_port) == false) {
            status = CELIX_BUNDLE_EXCEPTION;
        } else {
            etcdWatcher_addOwnNode(*watcher);

            if ((status = celixThreadMutex_create(&(*watcher)->watcherLock, NULL)) != CELIX_SUCCESS) {
                return status;
            }

            if ((status = celixThreadMutex_lock(&(*watcher)->watcherLock)) != CELIX_SUCCESS) {
                return status;
            }

            if ((status = celixThread_create(&(*watcher)->watcherThread, NULL, etcdWatcher_run, *watcher)) != CELIX_SUCCESS) {
                return status;
            }

            (*watcher)->running = true;

            if ((status = celixThreadMutex_unlock(&(*watcher)->watcherLock)) != CELIX_SUCCESS) {
                return status;
            }
        }
    } else {
        status = CELIX_ENOMEM;
    }

    return status;
}
Ejemplo n.º 2
0
etcd_writer_pt etcdWriter_create(pubsub_discovery_pt disc) {
	etcd_writer_pt writer = calloc(1, sizeof(*writer));
	if(writer) {
		celixThreadMutex_create(&writer->localPubsLock, NULL);
		arrayList_create(&writer->localPubs);
		writer->pubsub_discovery = disc;
		writer->running = true;
		celixThread_create(&writer->writerThread, NULL, etcdWriter_run, writer);
	}
	return writer;
}
Ejemplo n.º 3
0
celix_status_t pubsub_topicSubscriptionStart(topic_subscription_pt ts){
	celix_status_t status = CELIX_SUCCESS;

	status = serviceTracker_open(ts->tracker);

	ts->running = true;

	if(status==CELIX_SUCCESS){
		status=celixThread_create(&ts->recv_thread,NULL,udp_recv_thread_func,ts);
	}

	return status;
}
Ejemplo n.º 4
0
celix_status_t remoteShell_addConnection(remote_shell_pt instance, int socket) {
	celix_status_t status = CELIX_SUCCESS;
	connection_pt connection = calloc(1, sizeof(struct connection));

	if (connection != NULL) {
		connection->parent = instance;
		connection->threadRunning = false;
		connection->socketStream = fdopen(socket, "w");

		if (connection->socketStream != NULL) {

			celixThreadMutex_lock(&instance->mutex);

			if (arrayList_size(instance->connections) < instance->maximumConnections) {
				celix_thread_t connectionRunThread = celix_thread_default;
				arrayList_add(instance->connections, connection);
				status = celixThread_create(&connectionRunThread, NULL, &remoteShell_connection_run, connection);
			} else {
				status = CELIX_BUNDLE_EXCEPTION;
				remoteShell_connection_print(connection, RS_MAXIMUM_CONNECTIONS_REACHED);
			}
			celixThreadMutex_unlock(&instance->mutex);

		} else {
			status = CELIX_BUNDLE_EXCEPTION;
		}
	} else {
		status = CELIX_ENOMEM;
	}

	if (status != CELIX_SUCCESS && connection != NULL) {
		if (connection->socketStream != NULL) {
			fclose(connection->socketStream);
		}
		free(connection);
	}

	return status;
}
Ejemplo n.º 5
0
int phase1_start(phase1_cmp_t *cmp) {
	printf("start phase1\n");
    cmp->running = true;
    celixThread_create(&cmp->thread, NULL, phase1_thread, cmp);
    return 0;
}
Ejemplo n.º 6
0
/**
 * Allocates memory and initializes a new endpoint_discovery_poller instance.
 */
celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller) {
    celix_status_t status;

    *poller = malloc(sizeof(struct endpoint_discovery_poller));
    if (!*poller) {
        return CELIX_ENOMEM;
    }

    (*poller)->loghelper = &discovery->loghelper;

	status = celixThreadMutex_create(&(*poller)->pollerLock, NULL);
	if (status != CELIX_SUCCESS) {
		return status;
	}

	char* interval = NULL;
	status = bundleContext_getProperty(context, DISCOVERY_POLL_INTERVAL, &interval);
	if (!interval) {
		interval = DEFAULT_POLL_INTERVAL;
	}

	char* endpoints = NULL;
	status = bundleContext_getProperty(context, DISCOVERY_POLL_ENDPOINTS, &endpoints);
	if (!endpoints) {
		endpoints = DEFAULT_POLL_ENDPOINTS;
	}
	// we're going to mutate the string with strtok, so create a copy...
	endpoints = strdup(endpoints);

	(*poller)->poll_interval = atoi(interval);
	(*poller)->discovery = discovery;
	(*poller)->running = false;
	(*poller)->entries = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);

	const char* sep = ",";
	char *save_ptr = NULL;
	char* tok = strtok_r(endpoints, sep, &save_ptr);
	while (tok) {
		endpointDiscoveryPoller_addDiscoveryEndpoint(*poller, utils_stringTrim(tok));
		tok = strtok_r(NULL, sep, &save_ptr);
	}
	// Clean up after ourselves...
	free(endpoints);

    status = celixThreadMutex_lock(&(*poller)->pollerLock);
    if (status != CELIX_SUCCESS) {
        return CELIX_BUNDLE_EXCEPTION;
    }

	(*poller)->running = true;

	status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller);
	if (status != CELIX_SUCCESS) {
		return status;
	}


    status = celixThreadMutex_unlock(&(*poller)->pollerLock);

    return status;
}
Ejemplo n.º 7
0
/*
 * the ectdWatcher needs to have access to the endpoint_discovery_poller and therefore is only
 * allowed to be created after the endpoint_discovery_poller
 */
celix_status_t etcdWatcher_create(discovery_pt discovery, bundle_context_pt context,
                                  etcd_watcher_pt *watcher)
{
    celix_status_t status = CELIX_SUCCESS;

    char* etcd_server = NULL;
    char* etcd_port_string = NULL;
    int etcd_port = 0;

    if (discovery == NULL) {
        return CELIX_BUNDLE_EXCEPTION;
    }

    (*watcher) = calloc(1, sizeof(struct etcd_watcher));
    if (!*watcher) {
        return CELIX_ENOMEM;
    }
    else
    {
        (*watcher)->discovery = discovery;
        (*watcher)->loghelper = &discovery->loghelper;
        (*watcher)->entries = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);
    }

    if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_IP, &etcd_server) != CELIX_SUCCESS) || !etcd_server) {
        etcd_server = DEFAULT_ETCD_SERVER_IP;
    }

    if ((bundleContext_getProperty(context, CFG_ETCD_SERVER_PORT, &etcd_port_string) != CELIX_SUCCESS) || !etcd_port_string) {
        etcd_port = DEFAULT_ETCD_SERVER_PORT;
    }
    else
    {
        char* endptr = etcd_port_string;
        errno = 0;
        etcd_port =  strtol(etcd_port_string, &endptr, 10);
        if (*endptr || errno != 0) {
            etcd_port = DEFAULT_ETCD_SERVER_PORT;
        }
    }

    status = etcd_init(etcd_server, etcd_port);

    printf(" ININT\n");
    if (status == CELIX_SUCCESS) {
        etcdWatcher_addOwnFramework(*watcher);
        status = celixThreadMutex_create(&(*watcher)->watcherLock, NULL);
        printf(" 111\n");
    }

    if (status == CELIX_SUCCESS) {
        if (celixThreadMutex_lock(&(*watcher)->watcherLock) == CELIX_SUCCESS) {
            status = celixThread_create(&(*watcher)->watcherThread, NULL, etcdWatcher_run, *watcher);
            if (status == CELIX_SUCCESS) {
                printf(" STARTEDTSTARTED\n");
                (*watcher)->running = true;
            }
            celixThreadMutex_unlock(&(*watcher)->watcherLock);
        }
    }


    printf(" DONEDONE\n");
    return status;
}