當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。