Example usage for io.vertx.core Vertx getOrCreateContext

List of usage examples for io.vertx.core Vertx getOrCreateContext

Introduction

In this page you can find the example usage for io.vertx.core Vertx getOrCreateContext.

Prototype

Context getOrCreateContext();

Source Link

Document

Gets the current context, or creates one if there isn't one

Usage

From source file:com.julienviet.childprocess.Process.java

License:Apache License

/**
 * Create a child process (not running) from this process, call {@link #start()} to start the process.
 *
 * @param vertx the vertx instance//from  w w w .  ja va  2  s .c  om
 * @param command the command to run
 * @param args list of string arguments
 * @param options the options to run the command
 * @return the created child process
 */
static Process create(Vertx vertx, String command, List<String> args, ProcessOptions options) {
    Map<String, String> env = new HashMap<>();
    if (options.getEnv() != null) {
        options.getEnv().entrySet().forEach(entry -> {
            if (entry.getValue() != null) {
                env.put(entry.getKey(), entry.getValue());
            }
        });
    }
    ArrayList<String> commands = new ArrayList<>();
    commands.add(command);
    commands.addAll(args);
    NuProcessBuilder builder = new NuProcessBuilder(commands, env);
    if (options.getCwd() != null) {
        builder.setCwd(new File(options.getCwd()).toPath());
    }
    return new ProcessImpl(vertx.getOrCreateContext(), builder);
}

From source file:examples.CoreExamples.java

License:Open Source License

public void retrieveContext(Vertx vertx) {
    Context context = vertx.getOrCreateContext();
}

From source file:examples.CoreExamples.java

License:Open Source License

public void retrieveContextType(Vertx vertx) {
    Context context = vertx.getOrCreateContext();
    if (context.isEventLoopContext()) {
        System.out.println("Context attached to Event Loop");
    } else if (context.isWorkerContext()) {
        System.out.println("Context attached to Worker Thread");
    } else if (context.isMultiThreadedWorkerContext()) {
        System.out.println("Context attached to Worker Thread - multi threaded worker");
    } else if (!Context.isOnVertxThread()) {
        System.out.println("Context not attached to a thread managed by vert.x");
    }//from ww  w  .  ja va2s. com
}

From source file:examples.CoreExamples.java

License:Open Source License

public void runInContext(Vertx vertx) {
    vertx.getOrCreateContext().runOnContext((v) -> {
        System.out.println("This will be executed asynchronously in the same context");
    });/* w  ww  . ja v a  2  s  .  co m*/
}

From source file:examples.CoreExamples.java

License:Open Source License

public void runInContextWithData(Vertx vertx) {
    final Context context = vertx.getOrCreateContext();
    context.put("data", "hello");
    context.runOnContext((v) -> {//  w  w w.j a v  a  2 s .  co  m
        String hello = context.get("data");
    });
}

From source file:examples.hystrix.HystrixExamples.java

License:Open Source License

public void exampleHystrix3(Vertx vertx) {
    vertx.runOnContext(v -> {/*from w ww . ja v a2 s.  c om*/
        Context context = vertx.getOrCreateContext();
        HystrixCommand<String> command = getSomeCommandInstance();
        command.observe().subscribe(result -> {
            context.runOnContext(v2 -> {
                // Back on context (event loop or worker)
                String r = result;
            });
        });
    });
}

From source file:examples.VertxProtonExamples.java

License:Apache License

public void example5(Vertx vertx, ProtonClient client) {
    Context myContext = vertx.getOrCreateContext();

    myContext.runOnContext(x -> {/*from  w ww  .j  a  va  2s  .  c om*/
        client.connect("hostname", 5672, connectResult -> {
            // In this case the context will be 'myContext' from earlier
        });
    });
}

From source file:imbrobits.loosh.handler.TodoistApiService.java

License:Open Source License

@Inject
public TodoistApiService(Vertx vertx) {
    appConfig = vertx.getOrCreateContext().config();
    auth = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE,
            new OAuth2ClientOptions().setClientID(appConfig.getString(Config.TODOIST_CLIENT_ID))
                    .setClientSecret(appConfig.getString(Config.TODOIST_CLIENT_SECRET))
                    .setSite("https://todoist.com").setTokenPath("/oauth/access_token")
                    .setAuthorizationPath("/oauth/authorize"));
}

From source file:io.github.qrman.guice.WimbledonModule.java

License:Open Source License

public WimbledonModule(Vertx vertx) {
    this.vertx = vertx;
    this.context = vertx.getOrCreateContext();
}

From source file:io.gravitee.fetcher.http.vertx.VertxCompletableFuture.java

License:Apache License

/**
 * Creates a new {@link VertxCompletableFuture} from the given {@link Vertx} instance and given
 * {@link CompletableFuture}. The returned future uses the current Vert.x context, or creates a new one.
 * <p>/*from  w  w w. j av a2  s . c  om*/
 * The created {@link VertxCompletableFuture} is completed successfully or not when the given completable future
 * completes successfully or not.
 *
 * @param vertx  the Vert.x instance
 * @param future the future
 * @param <T>    the type of the result
 * @return the new {@link VertxCompletableFuture}
 */
public static <T> VertxCompletableFuture<T> from(Vertx vertx, CompletableFuture<T> future) {
    return from(vertx.getOrCreateContext(), future);
}