当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中io.vertx.core.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于io.vertx.core包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findByContext

import io.vertx.core.Context; //导入依赖的package包/类
protected CLIENT_POOL findByContext() {
  Context currentContext = 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();
  }

  // not in correct context:
  // 1.normal thread
  // 2.vertx worker thread
  // 3.other vertx thread
  // select a existing context
  return nextPool();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:24,代码来源:ClientPoolManager.java

示例2: start

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void start(@Mocked Context context) throws Exception {
  AtomicInteger count = new AtomicInteger();
  ClientPoolManager<HttpClientWithContext> clientMgr = new MockUp<ClientPoolManager<HttpClientWithContext>>() {
    @Mock
    HttpClientWithContext createClientPool() {
      count.incrementAndGet();
      return null;
    }
  }.getMockInstance();
  clientVerticle.init(null, context);

  JsonObject config = new SimpleJsonObject();
  config.put(ClientVerticle.CLIENT_MGR, clientMgr);
  new Expectations() {
    {
      context.config();
      result = config;
    }
  };

  clientVerticle.start();

  Assert.assertEquals(1, count.get());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:26,代码来源:TestClientVerticle.java

示例3: send_inDisconnectedStatus

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void send_inDisconnectedStatus(@Mocked AbstractTcpClientPackage tcpClientPackage,
    @Mocked TcpOutputStream tcpOutputStream) {
  long msgId = 1;
  new Expectations(tcpClientConnection) {
    {
      tcpClientPackage.getMsgId();
      result = msgId;
    }
  };
  new MockUp<Context>(context) {
    @Mock
    void runOnContext(Handler<Void> action) {
      action.handle(null);
    }
  };
  tcpClientConnection.send(tcpClientPackage, ar -> {
  });

  Assert.assertSame(tcpClientPackage, packageQueue.poll());
  Assert.assertNull(packageQueue.poll());
  Assert.assertEquals(Status.CONNECTING, Deencapsulation.getField(tcpClientConnection, "status"));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:24,代码来源:TestTcpClientConnection.java

示例4: send_disconnectedToTryLogin

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void send_disconnectedToTryLogin(@Mocked AbstractTcpClientPackage tcpClientPackage,
    @Mocked TcpOutputStream tcpOutputStream) {
  long msgId = 1;
  new Expectations(tcpClientConnection) {
    {
      tcpClientPackage.getMsgId();
      result = msgId;
    }
  };
  new MockUp<Context>(context) {
    @Mock
    void runOnContext(Handler<Void> action) {
      Deencapsulation.setField(tcpClientConnection, "status", Status.TRY_LOGIN);
      action.handle(null);
    }
  };
  tcpClientConnection.send(tcpClientPackage, ar -> {
  });

  Assert.assertSame(tcpClientPackage, packageQueue.poll());
  Assert.assertNull(packageQueue.poll());
  Assert.assertEquals(Status.TRY_LOGIN, Deencapsulation.getField(tcpClientConnection, "status"));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:TestTcpClientConnection.java

示例5: send_disconnectedToWorking

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void send_disconnectedToWorking(@Mocked AbstractTcpClientPackage tcpClientPackage,
    @Mocked TcpOutputStream tcpOutputStream) {
  long msgId = 1;
  new Expectations(tcpClientConnection) {
    {
      tcpClientPackage.getMsgId();
      result = msgId;
    }
  };
  new MockUp<Context>(context) {
    @Mock
    void runOnContext(Handler<Void> action) {
      Deencapsulation.setField(tcpClientConnection, "status", Status.WORKING);
      action.handle(null);
    }
  };
  tcpClientConnection.send(tcpClientPackage, ar -> {
  });

  Assert.assertNull(writeQueue.poll());
  Assert.assertNull(packageQueue.poll());
  Assert.assertEquals(Status.WORKING, Deencapsulation.getField(tcpClientConnection, "status"));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:TestTcpClientConnection.java

示例6: createClientPool

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void createClientPool(@Mocked Vertx vertx, @Mocked Context context, @Mocked HttpClient httpClient) {
  new Expectations(VertxImpl.class) {
    {
      VertxImpl.context();
      result = context;
      context.owner();
      result = vertx;
      vertx.createHttpClient(httpClientOptions);
      result = httpClient;
    }
  };
  HttpClientWithContext pool = factory.createClientPool();

  Assert.assertSame(context, pool.context());
  Assert.assertSame(httpClient, pool.getHttpClient());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:TestHttpClientPoolFactory.java

示例7: findByContext_otherVertx

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void findByContext_otherVertx(@Mocked Vertx otherVertx, @Mocked Context otherContext) {
  HttpClientWithContext pool = new HttpClientWithContext(null, null);
  pools.add(pool);

  new Expectations(VertxImpl.class) {
    {
      VertxImpl.context();
      result = otherContext;
      otherContext.owner();
      result = otherVertx;
    }
  };

  Assert.assertSame(pool, poolMgr.findByContext());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:TestClientPoolManager.java

示例8: findByContext_woker

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void findByContext_woker(@Mocked Context workerContext) {
  HttpClientWithContext pool = new HttpClientWithContext(null, null);
  pools.add(pool);

  new Expectations(VertxImpl.class) {
    {
      VertxImpl.context();
      result = workerContext;
      workerContext.owner();
      result = vertx;
      workerContext.isEventLoopContext();
      result = false;
    }
  };

  Assert.assertSame(pool, poolMgr.findByContext());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TestClientPoolManager.java

示例9: testRestServerVerticleWithRouter

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void testRestServerVerticleWithRouter(@Mocked Transport transport, @Mocked Vertx vertx,
    @Mocked Context context,
    @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
  URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080");
  new Expectations() {
    {
      transport.parseAddress("http://127.0.0.1:8080");
      result = endpointObject;
    }
  };
  Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080");

  new Expectations() {
    {
      context.config();
      result = jsonObject;
      jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
      result = endpiont;
    }
  };
  RestServerVerticle server = new RestServerVerticle();
  // process stuff done by Expectations
  server.init(vertx, context);
  server.start(startFuture);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:27,代码来源:TestRestServerVerticle.java

示例10: testRestServerVerticleWithRouterSSL

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void testRestServerVerticleWithRouterSSL(@Mocked Transport transport, @Mocked Vertx vertx,
    @Mocked Context context,
    @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
  URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080?sslEnabled=true");
  new Expectations() {
    {
      transport.parseAddress("http://127.0.0.1:8080?sslEnabled=true");
      result = endpointObject;
    }
  };
  Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080?sslEnabled=true");

  new Expectations() {
    {
      context.config();
      result = jsonObject;
      jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
      result = endpiont;
    }
  };
  RestServerVerticle server = new RestServerVerticle();
  // process stuff done by Expectations
  server.init(vertx, context);
  server.start(startFuture);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:27,代码来源:TestRestServerVerticle.java

示例11: testDoMethodNullPointerException

import io.vertx.core.Context; //导入依赖的package包/类
@Test
public void testDoMethodNullPointerException(@Mocked HttpClient httpClient) throws Exception {
  Context context = new MockUp<Context>() {
    @Mock
    public void runOnContext(Handler<Void> action) {
      action.handle(null);
    }
  }.getMockInstance();
  HttpClientWithContext httpClientWithContext = new HttpClientWithContext(httpClient, context);

  Invocation invocation = mock(Invocation.class);
  AsyncResponse asyncResp = mock(AsyncResponse.class);

  try {
    this.doMethod(httpClientWithContext, invocation, asyncResp);
    fail("Expect to throw NullPointerException, but got none");
  } catch (NullPointerException e) {
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:TestVertxHttpMethod.java

示例12: init

import io.vertx.core.Context; //导入依赖的package包/类
@Override
public void init(Vertx vertx, Context context) {
	super.init(vertx, context);

	String host = System.getenv(CommonConstants.JDG_SERVICE_HOST_ENV) != null
			? System.getenv(CommonConstants.JDG_SERVICE_HOST_ENV) : CommonConstants.JDG_SERVICE_HOST_DEFAULT;
	String port = System.getenv(CommonConstants.JDG_SERVICE_PORT_ENV) != null
			? System.getenv(CommonConstants.JDG_SERVICE_PORT_ENV) : CommonConstants.JDG_SERVICE_PORT_DEFAULT;

	ConfigurationBuilder builder = new ConfigurationBuilder();
	builder.addServers(String.format(JDG_CONNECTION_STRING_FORMAT, host, port));
	builder.nearCache().mode(NearCacheMode.INVALIDATED).maxEntries(25);
	builder.marshaller(new ProtoStreamMarshaller());

	cacheManager = new RemoteCacheManager(builder.build());

	this.registerProtoBufSchema();
}
 
开发者ID:benemon,项目名称:he-rss-poll,代码行数:19,代码来源:AbstractJDGVerticle.java

示例13: schedule

import io.vertx.core.Context; //导入依赖的package包/类
@Override
protected void schedule(CommandBase<?> cmd) {
  Context current = Vertx.currentContext();
  if (current == context) {
    pool.acquire(new CommandWaiter() {
      @Override
      protected void onSuccess(Connection conn) {
        // Work around stack over flow
        context.runOnContext(v -> {
          conn.schedule(cmd);
          conn.close(this);
        });
      }
      @Override
      protected void onFailure(Throwable cause) {
        cmd.fail(cause);
      }
    });
  } else {
    context.runOnContext(v -> schedule(cmd));
  }
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:23,代码来源:PgPoolImpl.java

示例14: VertxAsyncLogoutHandler

import io.vertx.core.Context; //导入依赖的package包/类
public VertxAsyncLogoutHandler(final Vertx vertx,
                               final Context context,
                               final AsyncConfig<Void, CommonProfile, VertxAsyncWebContext> config,
                               final LogoutHandlerOptions options) {
    DefaultAsyncLogoutLogic<Void, CommonProfile, VertxAsyncWebContext> defaultApplicationLogoutLogic = new DefaultAsyncLogoutLogic<>(config,
            httpActionAdapter,
            options.getDefaultUrl(),
            options.getLogoutUrlPattern(),
            options.isLocalLogout(),
            options.isDestroySession(),
            options.isCentralLogout());
    defaultApplicationLogoutLogic.setProfileManagerFactory(c -> new VertxAsyncProfileManager(c));
    this.logoutLogic = defaultApplicationLogoutLogic;
    this.config = config;
    this.asynchronousComputationAdapter = new VertxAsynchronousComputationAdapter(vertx, context);
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:17,代码来源:VertxAsyncLogoutHandler.java

示例15: VertxAsyncSecurityHandler

import io.vertx.core.Context; //导入依赖的package包/类
public VertxAsyncSecurityHandler(final Vertx vertx,
                                 final Context context,
                                 final AsyncConfig config, final Pac4jAuthProvider authProvider,
                                 final SecurityHandlerOptions options) {
    super(authProvider);
    CommonHelper.assertNotNull("vertx", vertx);
    CommonHelper.assertNotNull("context", context);
    CommonHelper.assertNotNull("config", config);
    CommonHelper.assertNotNull("config.getClients()", config.getClients());
    CommonHelper.assertNotNull("authProvider", authProvider);
    CommonHelper.assertNotNull("options", options);

    clientNames = options.getClients();
    authorizerName = options.getAuthorizers();
    matcherName = options.getMatchers();
    multiProfile = options.isMultiProfile();
    this.vertx = vertx;
    this.asynchronousComputationAdapter = new VertxAsynchronousComputationAdapter(vertx, context);
    this.context = context;
    this.config = config;

    final DefaultAsyncSecurityLogic<Void, U , VertxAsyncWebContext> securityLogic = new DefaultAsyncSecurityLogic<Void, U, VertxAsyncWebContext>(options.isSaveProfileInSession(),
            options.isMultiProfile(), config, httpActionAdapter);
    securityLogic.setProfileManagerFactory(c -> new VertxAsyncProfileManager(c));
    this.securityLogic = securityLogic;
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:27,代码来源:VertxAsyncSecurityHandler.java


注:本文中的io.vertx.core.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。