All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.core.impl.SyncContext Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.vertx.core.impl;

import java.io.Serial;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import io.netty.channel.EventLoop;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.ThreadingModel;
import io.vertx.core.json.JsonObject;
import io.vertx.core.spi.tracing.VertxTracer;

/**
 * This class is created to make vertx unit test easier
 */
@SuppressWarnings({"rawtypes"})
public class SyncContext extends ContextBase implements ContextInternal {
  @Serial
  private static final long serialVersionUID = -6209656149925076980L;

  protected VertxInternal owner;

  protected Executor executor = Executors.newSingleThreadExecutor();

  public SyncContext() {
    this(0);
  }

  public SyncContext(int localsLength) {
    super(localsLength);
  }

  @Override
  public VertxInternal owner() {
    return owner;
  }

  @Override
  public Context exceptionHandler(@Nullable Handler handler) {
    return null;
  }

  @Override
  public @Nullable Handler exceptionHandler() {
    return null;
  }

  @Override
  public boolean inThread() {
    return false;
  }

  @Override
  public  void emit(T t, Handler handler) {

  }

  @Override
  public void execute(Runnable runnable) {

  }

  @Override
  public  void execute(T t, Handler handler) {

  }

  @Override
  public void reportException(Throwable throwable) {

  }

  @Override
  public ConcurrentMap contextData() {
    return null;
  }

  @Override
  public ClassLoader classLoader() {
    return null;
  }

  @Override
  public WorkerPool workerPool() {
    return null;
  }

  @Override
  public VertxTracer tracer() {
    return null;
  }

  @Override
  public ContextInternal duplicate() {
    return null;
  }

  @Override
  public CloseFuture closeFuture() {
    return null;
  }

  public void setOwner(VertxInternal owner) {
    this.owner = owner;
  }


  public static  void syncExecuteBlocking(Handler> blockingCodeHandler,
      Handler> asyncResultHandler) {
    Promise res = Promise.promise();

    try {
      blockingCodeHandler.handle(res);
    } catch (Throwable e) {
      res.fail(e);
      return;
    }

    res.future().onComplete(asyncResultHandler);
  }

  private static  Future syncExecuteBlocking(Handler> blockingCodeHandler) {
    Promise res = Promise.promise();

    try {
      blockingCodeHandler.handle(res);
    } catch (Throwable e) {
      res.fail(e);
      return res.future();
    }

    return res.future();
  }

  @Override
  public  Future executeBlockingInternal(Handler> action) {
    return syncExecuteBlocking(action);
  }

  @Override
  public  Future executeBlockingInternal(Callable callable) {
    return null;
  }

  @Override
  public  Future executeBlockingInternal(Handler> handler, boolean b) {
    return null;
  }

  @Override
  public  Future executeBlockingInternal(Callable callable, boolean b) {
    return null;
  }

  @Override
  public Deployment getDeployment() {
    return null;
  }

  @Override
  public Executor executor() {
    return executor;
  }

  @Override
  public EventLoop nettyEventLoop() {
    return null;
  }

  @Override
  @Deprecated
  public  Future executeBlocking(Handler> handler, TaskQueue taskQueue) {
    return null;
  }

  @Override
  public  Future executeBlocking(Callable callable, TaskQueue taskQueue) {
    return null;
  }

  @Override
  @Deprecated
  public  void executeBlocking(Handler> blockingCodeHandler, boolean ordered,
      Handler> asyncResultHandler) {
    syncExecuteBlocking(blockingCodeHandler, asyncResultHandler);
  }

  @Override
  public  Future<@Nullable T> executeBlocking(Callable callable, boolean b) {
    return null;
  }

  @Override
  @Deprecated
  public  Future<@Nullable T> executeBlocking(Handler> handler, boolean b) {
    return null;
  }

  @Override
  public @Nullable JsonObject config() {
    return null;
  }

  @Override
  public boolean isEventLoopContext() {
    return false;
  }

  @Override
  public boolean isWorkerContext() {
    return false;
  }

  @Override
  public ThreadingModel threadingModel() {
    return null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy