本文整理汇总了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();
}
示例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());
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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) {
}
}
示例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();
}
示例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));
}
}
示例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);
}
示例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;
}