本文整理匯總了Java中io.vertx.core.Vertx類的典型用法代碼示例。如果您正苦於以下問題:Java Vertx類的具體用法?Java Vertx怎麽用?Java Vertx使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Vertx類屬於io.vertx.core包,在下文中一共展示了Vertx類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hello3
import io.vertx.core.Vertx; //導入依賴的package包/類
@Path("3")
@GET
public void hello3(@Suspended final AsyncResponse asyncResponse,
// Inject the Vertx instance
@Context Vertx vertx){
System.err.println("Creating client");
HttpClientOptions options = new HttpClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
HttpClient client = vertx.createHttpClient(options);
client.getNow(443,
"www.google.com",
"/robots.txt",
resp -> {
System.err.println("Got response");
resp.bodyHandler(body -> {
System.err.println("Got body");
asyncResponse.resume(Response.ok(body.toString()).build());
});
});
System.err.println("Created client");
}
示例2: initInternal
import io.vertx.core.Vertx; //導入依賴的package包/類
private static void initInternal(final Vertx vertx,
final String name) {
vertxRef = vertx;
Fn.pool(CONFIGS, name,
() -> Infix.init(Plugins.Infix.JOOQ,
(config) -> {
// Initialized client
final Configuration configuration = new DefaultConfiguration();
configuration.set(SQLDialect.MYSQL_8_0);
final ConnectionProvider provider =
new DefaultConnectionProvider(HikariCpPool.getConnection(
config.getJsonObject("provider")
));
// Initialized default configuration
configuration.set(provider);
return configuration;
}, JooqInfix.class));
}
示例3: findByContext
import io.vertx.core.Vertx; //導入依賴的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();
}
示例4: VertxAsyncSecurityHandler
import io.vertx.core.Vertx; //導入依賴的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;
}
示例5: testCreationWithVertx
import io.vertx.core.Vertx; //導入依賴的package包/類
@Test
public void testCreationWithVertx() {
Vertx vertx = Vertx.vertx();
Fluid fluid = new Fluid(vertx);
List<String> list = new ArrayList<>();
FluidRegistry.register("input", Source.from("a", "b", "c"));
FluidRegistry.register("output", Sink.<String>forEachPayload(list::add));
fluid.deploy(f -> {
Sink<String> output = f.sink("output");
f.<String>from("input")
.transformPayload(String::toUpperCase)
.to(output);
});
await().until(() -> list.size() == 3);
assertThat(list).containsExactly("A", "B", "C");
}
示例6: deploy
import io.vertx.core.Vertx; //導入依賴的package包/類
static void deploy(final Vertx vertx,
final Class<?> clazz,
final DeploymentOptions option,
final Annal logger) {
// Verticle deployment
final String name = clazz.getName();
final String flag = option.isWorker() ? "Worker" : "Agent";
vertx.deployVerticle(name, option, (result) -> {
// Success or Failed.
if (result.succeeded()) {
logger.info(Info.VTC_END,
name, option.getInstances(), result.result(),
flag);
INSTANCES.put(clazz, result.result());
} else {
logger.warn(Info.VTC_FAIL,
name, option.getInstances(), result.result(),
null == result.cause() ? null : result.cause().getMessage(), flag);
}
});
}
示例7: setUp
import io.vertx.core.Vertx; //導入依賴的package包/類
@Before
public void setUp(TestContext context) throws IOException {
vertx = Vertx.vertx();
// Pick an available and random
ServerSocket socket = new ServerSocket(0);
port = socket.getLocalPort();
socket.close();
DeploymentOptions options = new DeploymentOptions()
.setConfig(new JsonObject()
.put("HTTP_PORT", port)
.put("url", "jdbc:hsqldb:mem:test?shutdown=true")
.put("driver_class", "org.hsqldb.jdbcDriver")
);
vertx.deployVerticle(MyFirstVerticle.class.getName(), options, context.asyncAssertSuccess());
}
示例8: hello8
import io.vertx.core.Vertx; //導入依賴的package包/類
@Path("8")
@GET
public Single<String> hello8(@Context io.vertx.rxjava.core.Vertx rxVertx){
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Created client");
return responseHandler.map(body -> {
System.err.println("Got body");
return body.body().toString();
});
}
示例9: main
import io.vertx.core.Vertx; //導入依賴的package包/類
public static void main(String [] args) throws IOException {
Properties properties = loadProperties("config.properties");
String messagingHost = properties.getProperty("service.hostname", "messaging.enmasse.svc");
int messagingPort = Integer.parseInt(properties.getProperty("service.port", "5672"));
String username = properties.getProperty("service.username", "test");
String password = properties.getProperty("service.password", "test");
String maxAddress = properties.getProperty("address.max", "max");
String controlPrefix = properties.getProperty("address.control.prefix", "control");
int minTemp = Integer.parseInt(properties.getProperty("control.temperature.min", "15"));
int maxTemp = Integer.parseInt(properties.getProperty("control.temperature.max", "25"));
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new Thermostat(messagingHost, messagingPort, username, password, maxAddress, controlPrefix, minTemp, maxTemp));
}
示例10: main
import io.vertx.core.Vertx; //導入依賴的package包/類
public static void main(String... args) {
//Note to self
// run this demo in HA mode, deploy this verticle on a separate node and combine it with demo6
final JsonObject config = Config.fromFile("config/demo7.json");
VertxOptions opts = new VertxOptions().setClustered(true);
Vertx.clusteredVertx(opts, result -> {
if (result.succeeded()) {
LOG.info("Cluster running");
Vertx vertx = result.result();
vertx.deployVerticle(BitcoinAdjustedData.class.getName(),
new DeploymentOptions().setConfig(config).setWorker(false));
} else {
LOG.error("Clusterin failed");
throw new RuntimeException(result.cause());
}
});
}
示例11: main
import io.vertx.core.Vertx; //導入依賴的package包/類
public static void main(String... args) {
final JsonObject config = Config.fromFile("config/demo6.json");
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new JSPercentilesDatasource(), new DeploymentOptions().setConfig(config));
/*
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new JSAggregateDatasource(), new DeploymentOptions().setConfig(config));
*/
VertxOptions opts = new VertxOptions().setClustered(true);
Vertx.clusteredVertx(opts, result -> {
if(result.succeeded()){
LOG.info("Cluster running");
Vertx cvertx = result.result();
cvertx.deployVerticle(new JSPercentilesDatasource(), new DeploymentOptions().setConfig(config));
} else {
LOG.error("Clustering failed");
throw new RuntimeException(result.cause());
}
});
}
示例12: start
import io.vertx.core.Vertx; //導入依賴的package包/類
@Override
public void start() throws Exception {
JsonObject config = Vertx.currentContext().config();
DeploymentOptions opts = new DeploymentOptions().setConfig(config);
DeploymentOptions chunkOpts = new DeploymentOptions().setConfig(config.copy().put(ADDRESS, "/queryChunk"))
//.setInstances(config.getInteger(PARALLELISM))
//.setWorker(true)
;
vertx.deployVerticle("js:io/devcon5/metrics/demo6/AggregatePercentilesVerticle.js",chunkOpts, result -> {
if (result.succeeded()) {
LOG.info("JS Verticle successfully deployed {}", result.result());
} else {
LOG.error("Failed to deploy JS Verticle", result.cause());
}
});
vertx.deployVerticle(SplitMergeTimeSeriesVerticle.class.getName(), opts);
vertx.deployVerticle(AnnotationVerticle.class.getName(), opts);
vertx.deployVerticle(LabelVerticle.class.getName(), opts);
vertx.deployVerticle(HttpServerVerticle.class.getName(), opts);
}
示例13: VertxAsyncLogoutHandler
import io.vertx.core.Vertx; //導入依賴的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);
}
示例14: testRoundStrategy
import io.vertx.core.Vertx; //導入依賴的package包/類
@Test
public void testRoundStrategy() {
Vertx vertx = Vertx.vertx();
WebClient http = WebClient.create(vertx);
App a = new App(vertx,http,"test");
RoundNodeStrategy w = new RoundNodeStrategy();
Node n1 = a.createDevNode("10.10.10.1",80,1);
Node n2 = a.createDevNode("10.10.10.1",80,1);
Node n3 = a.createDevNode("10.10.10.1",80,1);
Node n4 = a.createDevNode("10.10.10.1",80,1);
Node n5 = a.createDevNode("10.10.10.1",80,1);
w.addNode(n1);
w.addNode(n2);
w.addNode(n3);
w.addNode(n4);
w.addNode(n5);
for(int i=0; i<100 ;i++){
System.out.println(w.getNode(null).toString());
}
}
示例15: getChannel
import io.vertx.core.Vertx; //導入依賴的package包/類
/**
* @param vertx Vert.x instance
* @param config configuration
* @return ManagedChannel
*/
public static ManagedChannel getChannel(final Vertx vertx,
final JsonObject config) {
final String rpcHost = config.getString(Key.HOST);
final Integer rpcPort = config.getInteger(Key.PORT);
LOGGER.info(Info.CLIENT_RPC, rpcHost, String.valueOf(rpcPort));
final VertxChannelBuilder builder =
VertxChannelBuilder
.forAddress(vertx, rpcHost, rpcPort);
Fn.safeSemi(null != config.getValue(Key.SSL), LOGGER,
() -> {
final JsonObject sslConfig = config.getJsonObject(Key.SSL);
if (null != sslConfig && !sslConfig.isEmpty()) {
final Object type = sslConfig.getValue("type");
final CertType certType = null == type ?
CertType.PEM : Types.fromStr(CertType.class, type.toString());
final TrustPipe<JsonObject> pipe = TrustPipe.get(certType);
// Enable SSL
builder.useSsl(pipe.parse(sslConfig));
} else {
builder.usePlaintext(true);
}
});
return builder.build();
}