int mod_main (flux_t *h, int argc, char **argv) { flux_msg_handler_t **handlers = NULL; sqlite_ctx_t *ctx = getctx (h); if (!ctx) goto done; if (flux_event_subscribe (h, "shutdown") < 0) { flux_log_error (h, "flux_event_subscribe"); goto done; } if (flux_msg_handler_addvec (h, htab, ctx, &handlers) < 0) { flux_log_error (h, "flux_msg_handler_addvec"); goto done; } if (register_backing_store (h, true, "content-sqlite") < 0) { flux_log_error (h, "registering backing store"); goto done; } if (register_content_backing_service (h) < 0) { flux_log_error (h, "service.add: content-backing"); goto done; } if (flux_reactor_run (flux_get_reactor (h), 0) < 0) { flux_log_error (h, "flux_reactor_run"); goto done; } done: flux_msg_handler_delvec (handlers); return 0; }
int mod_main (flux_t *h, int argc, char **argv) { int rc = -1; ctx_t *ctx = getctx (h); if (!ctx) goto done; if (flux_event_subscribe (h, "barrier.") < 0) { flux_log_error (h, "flux_event_subscribe"); goto done; } if (flux_msg_handler_addvec (h, htab, ctx) < 0) { flux_log_error (h, "flux_msghandler_add"); goto done; } if (flux_reactor_run (flux_get_reactor (h), 0) < 0) { flux_log_error (h, "flux_reactor_run"); goto done_unreg; } rc = 0; done_unreg: flux_msg_handler_delvec (htab); done: return rc; }
int mod_main (flux_t *h, int argc, char **argv) { ctx_t *ctx = getctx (h); uint32_t rank; flux_msg_handler_t **handlers = NULL; int rc = -1; if (flux_get_rank (h, &rank) < 0) return -1; if (rank != 0) { flux_log (h, LOG_ERR, "this module must only run on rank 0"); return -1; } flux_log (h, LOG_INFO, "module starting"); if (flux_event_subscribe (h, "sim.start") < 0) { flux_log (h, LOG_ERR, "subscribing to event: %s", strerror (errno)); return -1; } if (flux_msg_handler_addvec (h, htab, ctx, &handlers) < 0) { flux_log (h, LOG_ERR, "flux_msg_handler_add: %s", strerror (errno)); return -1; } send_alive_request (h, module_name); if (flux_reactor_run (flux_get_reactor (h), 0) < 0) { flux_log (h, LOG_ERR, "flux_reactor_run: %s", strerror (errno)); goto done_delvec; } rc = 0; done_delvec: flux_msg_handler_delvec (handlers); return rc; }
static void *cron_event_create (flux_t *h, cron_entry_t *e, json_t *arg) { struct cron_event *ev; int nth = 0; int after = 0; double min_interval = 0.; const char *event; struct flux_match match = FLUX_MATCH_EVENT; if (json_unpack (arg, "{ s:s, s?i, s?i, s?F }", "topic", &event, "nth", &nth, "after", &after, "min_interval", &min_interval) < 0) { flux_log_error (h, "cron event: json_unpack"); errno = EPROTO; return NULL; } if ((ev = calloc (1, sizeof (*ev))) == NULL) { flux_log_error (h, "cron event: calloc"); return NULL; } /* Call subscribe per cron entry. Multiple event subscriptions are * allowed and each cron_event entry will have a corresponding * unsubscribe */ if (flux_event_subscribe (h, event) < 0) { flux_log_error (h, "cron_event: subscribe"); goto fail; } /* Save a copy of this handle for event unsubscribe at destroy */ ev->h = h; ev->nth = nth; ev->after = after; ev->min_interval = min_interval; ev->counter = 0; if ((ev->event = strdup (event)) == NULL) { flux_log_error (h, "cron event: strdup"); goto fail; } match.topic_glob = ev->event; ev->mh = flux_msg_handler_create (h, match, event_handler, (void *)e); if (!ev->mh) { flux_log_error (h, "cron_event: flux_msg_handler_create"); goto fail; } return (ev); fail: cron_event_destroy (ev); return (NULL); }
static subscription_t *subscription_create (flux_t h, int type, const char *topic) { subscription_t *sub = xzmalloc (sizeof (*sub)); sub->type = type; sub->topic = xstrdup (topic); if (type == FLUX_MSGTYPE_EVENT) { (void)flux_event_subscribe (h, topic); flux_log (h, LOG_DEBUG, "event subscribe %s", topic); } return sub; }
int mod_main (flux_t *h, int argc, char **argv) { zhash_t *args = zhash_fromargv (argc, argv); ctx_t *ctx; char *eoc_str; bool exit_on_complete; uint32_t rank; if (flux_get_rank (h, &rank) < 0) return -1; if (rank != 0) { flux_log (h, LOG_ERR, "sim module must only run on rank 0"); return -1; } flux_log (h, LOG_INFO, "sim comms module starting"); if (!(eoc_str = zhash_lookup (args, "exit-on-complete"))) { flux_log (h, LOG_ERR, "exit-on-complete argument is not set, defaulting to false"); exit_on_complete = false; } else { exit_on_complete = (!strcmp (eoc_str, "true") || !strcmp (eoc_str, "True")); } ctx = getctx (h, exit_on_complete); if (flux_event_subscribe (h, "rdl.update") < 0) { flux_log (h, LOG_ERR, "subscribing to event: %s", strerror (errno)); return -1; } if (flux_msg_handler_addvec (h, htab, ctx) < 0) { flux_log (h, LOG_ERR, "flux_msg_handler_add: %s", strerror (errno)); return -1; } if (send_start_event (h) < 0) { flux_log (h, LOG_ERR, "sim failed to send start event"); return -1; } flux_log (h, LOG_DEBUG, "sim sent start event"); if (flux_reactor_run (flux_get_reactor (h), 0) < 0) { flux_log (h, LOG_ERR, "flux_reactor_run: %s", strerror (errno)); return -1; } return 0; }
static int notify_status_obj (flux_t *h, jsc_handler_obj_f func, void *d) { int rc = -1; cb_pair_t *c = NULL; jscctx_t *ctx = NULL; flux_msg_handler_t **handlers; if (!func) goto done; if (flux_event_subscribe (h, "wreck.state.") < 0) { flux_log_error (h, "subscribing to job event"); rc = -1; goto done; } if (flux_event_subscribe (h, "jsc.state.") < 0) { flux_log_error (h, "subscribing to job event"); rc = -1; goto done; } if (flux_msg_handler_addvec (h, htab, NULL, &handlers) < 0) { flux_log_error (h, "registering resource event handler"); rc = -1; goto done; } ctx = getctx (h); ctx->handlers = handlers; c = (cb_pair_t *) xzmalloc (sizeof(*c)); c->cb = func; c->arg = d; if (zlist_append (ctx->callbacks, c) < 0) goto done; zlist_freefn (ctx->callbacks, c, free, true); rc = 0; done: return rc; }
void shutdown_set_handle (shutdown_t *s, flux_t h) { struct flux_match match = FLUX_MATCH_EVENT; s->h = h; match.topic_glob = "shutdown"; if (!(s->shutdown = flux_msg_handler_create (s->h, match, shutdown_handler, s))) log_err_exit ("flux_msg_handler_create"); flux_msg_handler_start (s->shutdown); if (flux_event_subscribe (s->h, "shutdown") < 0) log_err_exit ("flux_event_subscribe"); if (flux_get_rank (s->h, &s->myrank) < 0) log_err_exit ("flux_get_rank"); }
static void register_event (ctx_t *ctx, const char *name, flux_msg_handler_f cb) { struct flux_match match = FLUX_MATCH_EVENT; flux_msg_handler_t *w; match.topic_glob = xasprintf ("%s.%s", module_get_name (ctx->p), name); if (!(w = flux_msg_handler_create (ctx->h, match, cb, ctx->p))) log_err_exit ("flux_msg_handler_create"); flux_msg_handler_start (w); if (zlist_append (ctx->handlers, w) < 0) oom (); if (flux_event_subscribe (ctx->h, match.topic_glob) < 0) log_err_exit ("%s: flux_event_subscribe %s", __FUNCTION__, match.topic_glob); free (match.topic_glob); }
int mod_main (flux_t h, zhash_t *args) { ctx_t *ctx = getctx (h); if (flux_event_subscribe (h, "xbarrier.") < 0) { err ("%s: flux_event_subscribe", __FUNCTION__); return -1; } if (flux_msghandler_addvec (h, htab, htablen, ctx) < 0) { flux_log (h, LOG_ERR, "flux_msghandler_addvec: %s", strerror (errno)); return -1; } if (flux_reactor_start (h) < 0) { flux_log (h, LOG_ERR, "flux_reactor_start: %s", strerror (errno)); return -1; } return 0; }
int main (int argc, char **argv) { flux_t *h; flux_msg_t *msg; const char *topic; if (!(h = flux_open (NULL, 0))) log_err_exit ("flux_open"); if (flux_event_subscribe (h, "hb") < 0) log_err_exit ("flux_event_subscribe"); if (!(msg = flux_recv (h, FLUX_MATCH_EVENT, 0))) log_err_exit ("flux_recv"); if (flux_msg_get_topic (msg, &topic) < 0) log_err_exit ("flux_msg_get_topic"); printf ("Event: %s\n", topic); if (flux_event_unsubscribe (h, "hb") < 0) log_err_exit ("flux_event_unsubscribe"); flux_msg_destroy (msg); flux_close (h); return (0); }
int personality (kap_config_t *kc, kap_personality_t *p) { char bn[KAP_MAX_STR]; if ( !p || !kc ) return -1; p->rank = kap_commfab_rank (); p->size = kap_commfab_size (); p->iter_count = 0; p->role = k_none; p->handle = _hndl; kap_conf_postinit (kc, p->size); /* * Assume the rank distribution is cyclic * e.g., distributes rank processes to * all of the nodes first before starting to * use the core on the first node again. */ if ( p->rank < kc->nproducers ) { p->role = k_producer; } if ( ((p->size-1) - p->rank) < kc->nconsumers ) { p->role = (p->role != k_producer) ? k_consumer : k_both; } if (kc->sync_type == s_causal) { if ( IS_CONSUMER(p->role) ) { if (flux_event_subscribe (p->handle, KAP_CAUSAL_CONS_EV) < 0) { fprintf (stderr, "Failed: event sub.\n"); goto error; } } } if (kc->iter_consumer > kc->iter_producer) { kc->iter_consumer = kc->iter_producer; fprintf (stderr, "Warning: iter-consumer > than iter-producer.\n"); fprintf (stderr, "Warning: iter-consumer set to iter-producer.\n"); } snprintf (bn, KAP_MAX_STR, "init-hb-%d", (int) kc->instance_num); /* to establish a clean happens-before relationship */ if (flux_barrier (p->handle, bn, kc->total_num_proc ) < 0) { fprintf (stderr, "Initial barrier failed.\n"); goto error; } return 0; error: return -1; }