- if (!simix_global->context_factory) {
- /* select the context factory to use to create the contexts */
- if (simgrid::simix::factory_initializer)
- simix_global->context_factory = simgrid::simix::factory_initializer();
- else { /* use the factory specified by --cfg=contexts/factory:value */
-#if defined(HAVE_THREAD_CONTEXTS)
- if (!strcmp(smx_context_factory_name, "thread"))
- simix_global->context_factory = simgrid::simix::thread_factory();
-#else
- if (0);
-#endif
-#ifdef HAVE_UCONTEXT_CONTEXTS
- else if (!strcmp(smx_context_factory_name, "ucontext"))
- simix_global->context_factory = simgrid::simix::sysv_factory();
-#endif
-#ifdef HAVE_RAW_CONTEXTS
- else if (!strcmp(smx_context_factory_name, "raw"))
- simix_global->context_factory = simgrid::simix::raw_factory();
-#endif
-#ifdef HAVE_BOOST_CONTEXTS
- else if (!strcmp(smx_context_factory_name, "boost"))
- simix_global->context_factory = simgrid::simix::boost_factory();
-#endif
- else {
- XBT_ERROR("Invalid context factory specified. Valid factories on this machine:");
-#ifdef HAVE_RAW_CONTEXTS
- XBT_ERROR(" raw: high performance context factory implemented specifically for SimGrid");
+
+ /* select the context factory to use to create the contexts */
+ if (simgrid::kernel::context::factory_initializer) { // Give Java a chance to hijack the factory mechanism
+ simix_global->context_factory = simgrid::kernel::context::factory_initializer();
+ return;
+ }
+ /* use the factory specified by --cfg=contexts/factory:value */
+ for (auto const& factory : context_factories)
+ if (context_factory_name == factory.first) {
+ simix_global->context_factory = factory.second();
+ break;
+ }
+
+ if (simix_global->context_factory == nullptr) {
+ XBT_ERROR("Invalid context factory specified. Valid factories on this machine:");
+#if HAVE_RAW_CONTEXTS
+ XBT_ERROR(" raw: high performance context factory implemented specifically for SimGrid");