Java Code Examples for io.vertx.core.Context#owner()

The following examples show how to use io.vertx.core.Context#owner() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestClientPoolManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void findByContext_otherVertx(@Mocked VertxImpl otherVertx, @Mocked Context otherContext) {
  HttpClientWithContext pool = new HttpClientWithContext(null, null);
  pools.add(pool);

  new Expectations() {
    {
      Vertx.currentContext();
      result = otherContext;
      otherContext.owner();
      result = otherVertx;
    }
  };

  Assert.assertSame(pool, poolMgr.findByContext());
}
 
Example 2
Source File: TestClientPoolManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void findByContext_worker(@Mocked Context workerContext) {
  HttpClientWithContext pool = new HttpClientWithContext(null, null);
  pools.add(pool);

  new Expectations() {
    {
      Vertx.currentContext();
      result = workerContext;
      workerContext.owner();
      result = vertx;
      workerContext.isEventLoopContext();
      result = false;
    }
  };

  Assert.assertSame(pool, poolMgr.findByContext());
}
 
Example 3
Source File: VertxContextPRNG.java    From vertx-auth with Apache License 2.0 6 votes vote down vote up
/**
 * Get or create a secure non blocking random number generator using the provided vert.x context. This method will not
 * throw an exception.
 *
 * @param context a Vert.x context.
 * @return A secure non blocking random number generator.
 */
@GenIgnore
static VertxContextPRNG current(final Context context) {
  final String contextKey = "__vertx.VertxContextPRNG";
  // attempt to load a PRNG from the current context
  PRNG random = context.get(contextKey);

  if (random == null) {
    synchronized (context) {
      // attempt to reload to avoid double creation when we were
      // waiting for the lock
      random = context.get(contextKey);
      if (random == null) {
        // there was no PRNG in the context, create one
        random = new PRNG(context.owner());
        // need to make the random final
        final PRNG rand = random;
        // save to the context
        context.put(contextKey, rand);
      }
    }
  }

  return random;
}
 
Example 4
Source File: Constants.java    From AlipayWechatPlatform with GNU General Public License v3.0 5 votes vote down vote up
public static void init(Context vertxContext) {
    Constants.vertx = vertxContext.owner();
    Constants.vertxContext = vertxContext;
    JsonObject config = vertxContext.config();
    PROJ_URL = config.getString("projectUrl", "http://itq46u.natappfree.cc/");
    CERT_DIR = config.getString("certDir", "/home/leibniz/");
    JDBC_URL = config.getString("jdbcUrl", "jdbc:mysql://127.0.0.1:3306/fission?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false");
    JDBC_USER = config.getString("jdbcUser", "root");
    JDBC_PSWD = config.getString("jdbcPassword", "turingdi");
    JDBC_DRIVER = config.getString("jdbcDriver", "com.mysql.cj.jdbc.Driver");
}
 
Example 5
Source File: ClientPoolManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
protected CLIENT_POOL findByContext(Context targetContext) {
  Context currentContext = targetContext != null ? targetContext : Vertx.currentContext();
  if (currentContext != null
      && currentContext.owner() == vertx
      && currentContext.isEventLoopContext()) {
    // standard reactive mode
    CLIENT_POOL clientPool = currentContext.get(id);
    if (clientPool != null) {
      return clientPool;
    }

    // this will make "client.thread-count" bigger than which in microservice.yaml
    // maybe it's better to remove "client.thread-count", just use "rest/highway.thread-count"
    return createClientPool(currentContext);
  }

  // not in correct context:
  // 1.normal thread
  // 2.vertx worker thread
  // 3.other vertx thread
  // select a existing context
  int idx = reactiveNextIndex.getAndIncrement() % pools.size();
  if (idx < 0) {
    idx = -idx;
  }
  return pools.get(idx);
}
 
Example 6
Source File: AbstractTcpClientPoolFactory.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public CLIENT_POOL createClientPool(Context context) {
  Vertx vertx = context.owner();

  NetClientWrapper netClientWrapper = new NetClientWrapper(vertx, normalClientConfig, sslClientConfig);
  return doCreateClientPool(context, netClientWrapper);
}
 
Example 7
Source File: VertxUtils.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
/**
 * Return the Vertx of the current context; if there isn't a current context
 * create and return a new Vertx using getVertxWithExceptionHandler().
 * @return the Vertx
 */
public static Vertx getVertxFromContextOrNew() {
  Context context = Vertx.currentContext();

  if (context == null) {
    return getVertxWithExceptionHandler();
  }

  return context.owner();
}
 
Example 8
Source File: ContextScheduler.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
public ContextScheduler(Context context, boolean blocking, boolean ordered) {
  Objects.requireNonNull(context, "context is null");
  this.vertx = context.owner();
  this.context = context;
  this.workerExecutor = null;
  this.blocking = blocking;
  this.ordered = ordered;
}
 
Example 9
Source File: ContextScheduler.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
public ContextScheduler(Context context, boolean blocking, boolean ordered) {
  this.vertx = context.owner();
  this.context = context;
  this.blocking = blocking;
  this.ordered = ordered;
  this.workerExecutor = null;
}
 
Example 10
Source File: ContextScheduler.java    From sfs with Apache License 2.0 4 votes vote down vote up
public ContextScheduler(Context context, boolean blocking, boolean ordered) {
    this.vertx = context.owner();
    this.context = context;
    this.blocking = blocking;
    this.ordered = ordered;
}