本文整理匯總了Java中io.vertx.core.AbstractVerticle類的典型用法代碼示例。如果您正苦於以下問題:Java AbstractVerticle類的具體用法?Java AbstractVerticle怎麽用?Java AbstractVerticle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AbstractVerticle類屬於io.vertx.core包,在下文中一共展示了AbstractVerticle類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: blockDeploy
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
public static <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx,
Class<VERTICLE> cls,
DeploymentOptions options) throws InterruptedException {
Holder<Boolean> result = new Holder<>();
CountDownLatch latch = new CountDownLatch(1);
vertx.deployVerticle(cls.getName(), options, ar -> {
result.value = ar.succeeded();
if (ar.failed()) {
LOGGER.error("deploy vertx failed, cause ", ar.cause());
}
latch.countDown();
});
latch.await();
return result.value;
}
示例2: testInit
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
@Test
public void testInit() {
boolean status = false;
try {
new MockUp<VertxUtils>() {
@Mock
public Vertx init(VertxOptions vertxOptions) {
return null;
}
@Mock
public <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls,
DeploymentOptions options) throws InterruptedException {
return true;
}
};
instance.init();
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
示例3: testUndeployUnassignedConsumer
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
@Test
// Regression test for ISS-73: undeployment of a verticle with unassigned consumer fails
public void testUndeployUnassignedConsumer(TestContext ctx) throws Exception {
Properties config = kafkaCluster.useTo().getConsumerProperties("testUndeployUnassignedConsumer_consumer",
"testUndeployUnassignedConsumer_consumer", OffsetResetStrategy.EARLIEST);
config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
Async async = ctx.async(1);
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
KafkaConsumer<String, String> consumer = KafkaConsumer.create(vertx, config);
vertx.setTimer(20, record -> {
// Very rarely, this throws a AlreadyUndedeployed error
vertx.undeploy(context.deploymentID(), ctx.asyncAssertSuccess(ar -> {
async.complete();
}));
});
}
}, ctx.asyncAssertSuccess());
}
示例4: deployAndWait
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
/**
* Deploy the given verticle.
*
* @param vertx
* Vertex instance which should be deployed into
* @param config
* Verticle configuration
* @param verticle
* Verticle which should be deployed
* @param worker
* Flag which indicates whether the verticle should be deployed as worker verticle
* @return Deployment Id
* @throws Exception
*/
public static String deployAndWait(Vertx vertx, JsonObject config, AbstractVerticle verticle, boolean worker)
throws Exception {
CompletableFuture<String> fut = new CompletableFuture<>();
DeploymentOptions options = new DeploymentOptions();
if (config != null) {
options = new DeploymentOptions(new JsonObject().put("config", config));
}
options.setWorker(worker);
vertx.deployVerticle(verticle, options, handler -> {
if (handler.succeeded()) {
String deploymentId = handler.result();
if (log.isInfoEnabled()) {
log.info("Deployed verticle {" + verticle.getClass().getName() + "} => " + deploymentId);
}
fut.complete(deploymentId);
} else {
Throwable error = handler.cause();
log.error("Error:", error);
fut.completeExceptionally(error);
}
});
return fut.get(DEFAULT_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
}
示例5: executePostConstruct
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
/**
* Executes the postConstruct using Reflection. This solves the issue that you can extend from a
* VxmsEndpoint or use the static invocation of an AbstractVerticle.
*
* @param router the http router handler
* @param startFuture the vert.x start future
* @param registrationObject the object to execute postConstruct
*/
private static void executePostConstruct(AbstractVerticle registrationObject, Router router,
final Future<Void> startFuture) {
final Stream<ReflectionExecutionWrapper> reflectionExecutionWrapperStream = Stream
.of(new ReflectionExecutionWrapper("postConstruct",
registrationObject, new Object[]{router, startFuture}, startFuture),
new ReflectionExecutionWrapper("postConstruct",
registrationObject, new Object[]{startFuture, router}, startFuture),
new ReflectionExecutionWrapper("postConstruct",
registrationObject, new Object[]{startFuture}, startFuture));
final Optional<ReflectionExecutionWrapper> methodWrapperToInvoke = reflectionExecutionWrapperStream
.filter(ReflectionExecutionWrapper::isPresent).findFirst();
methodWrapperToInvoke.ifPresent(ReflectionExecutionWrapper::invoke);
if(!methodWrapperToInvoke.isPresent() && !startFuture.isComplete()) {
startFuture.complete();
}
}
示例6: resolveBeanAnnotations
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
/**
* Resolves discovery annotation in AbstractVerticles
*
* @param service the service where to resolve the annotations
* @param kubeConfig the kubernetes config
*/
public static void resolveBeanAnnotations(AbstractVerticle service, Config kubeConfig) {
final JsonObject env = service.config();
final List<Field> serviceNameFields = findServiceFields(service);
if (!env.getBoolean("kube.offline", false)) { // online
final DefaultKubernetesClient client =
new DefaultKubernetesClient(kubeConfig); // TODO be aware of OpenShiftClient
if (!serviceNameFields.isEmpty()) {
findServiceEntryAndSetValue(service, serviceNameFields, env, client);
} else {
// TODO check and handle Endpoints & Pods
}
} else {
// resolve properties offline
if (!serviceNameFields.isEmpty()) {
resolveServicesOffline(service, serviceNameFields, env);
} else {
// TODO check and handle Endpoints & Pods
}
}
}
示例7: asyncAssertSuccess_02
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
@Source(translate = false)
public static void asyncAssertSuccess_02(Vertx vertx, TestContext context) {
AtomicBoolean started = new AtomicBoolean();
Async async = context.async();
vertx.deployVerticle(new AbstractVerticle() {
public void start() throws Exception {
started.set(true);
}
}, ar -> {
if (ar.succeeded()) {
context.assertTrue(started.get());
async.complete();
} else {
context.fail(ar.cause());
}
});
// Can be replaced by
vertx.deployVerticle("my.verticle", context.asyncAssertSuccess(id -> {
context.assertTrue(started.get());
}));
}
示例8: asJavaVerticle
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
/**
* @return the Java {@link Verticle} adapter for this Groovy Verticle
*/
public Verticle asJavaVerticle() {
return new AbstractVerticle() {
@Override
public void start(Future<Void> startFuture) throws Exception {
GroovyVerticle.this.vertx = super.vertx;
GroovyVerticle.this.context = super.context;
GroovyVerticle.this.start(startFuture);
}
@Override
public void stop(Future<Void> stopFuture) throws Exception {
GroovyVerticle.this.stop(stopFuture);
}
};
}
示例9: main
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
NetworkUtils.init();
System.out.println("===================Test start===================");
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
NetworkUtils.asyncPostString("http://breo.turing.asia/gzwx/smartBox/poll", System.out::println);
}
});
}
示例10: builderWithConfig
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
@Test
public void builderWithConfig(){
RestKiqrServerVerticle.Builder builder = RestKiqrServerVerticle.Builder.serverBuilder(new KStreamBuilder(), new Properties());
AbstractVerticle serverVerticle = builder.withOptions(new HttpServerOptions().setPort(4711)).build();
assertThat(serverVerticle, is(instanceOf(RestKiqrServerVerticle.class)));
RestKiqrServerVerticle server = (RestKiqrServerVerticle) serverVerticle;
assertThat(server.serverOptions.getPort(), is(equalTo(4711)));
}
示例11: builderWithPort
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
@Test
public void builderWithPort(){
RestKiqrServerVerticle.Builder builder = RestKiqrServerVerticle.Builder.serverBuilder(new KStreamBuilder(), new Properties());
AbstractVerticle serverVerticle = builder.withPort(4711).build();
assertThat(serverVerticle, is(instanceOf(RestKiqrServerVerticle.class)));
RestKiqrServerVerticle server = (RestKiqrServerVerticle) serverVerticle;
assertThat(server.serverOptions.getPort(), is(equalTo(4711)));
}
示例12: testCleanupInProducer
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
@Test
public void testCleanupInProducer(TestContext ctx) throws Exception {
Properties config = kafkaCluster.useTo().getProducerProperties("the_producer");
config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
AtomicReference<KafkaProducer<String, String>> producerRef = new AtomicReference<>();
AtomicReference<String> deploymentRef = new AtomicReference<>();
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
KafkaProducer<String, String> producer = KafkaProducer.create(vertx, config);
producerRef.set(producer);
producer.write(KafkaProducerRecord.create("the_topic", "the_value"), ctx.asyncAssertSuccess());
}
}, ctx.asyncAssertSuccess(deploymentRef::set));
Async async = ctx.async();
kafkaCluster.useTo().consumeStrings("the_topic", 1, 10, TimeUnit.SECONDS, () -> {
vertx.undeploy(deploymentRef.get(), ctx.asyncAssertSuccess(v -> {
Thread.getAllStackTraces().forEach((t, s) -> {
if (t.getName().contains("kafka-producer-network-thread")) {
ctx.fail("Was expecting the producer to be closed");
}
});
async.complete();
}));
});
}
示例13: testCleanupInConsumer
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
@Test
public void testCleanupInConsumer(TestContext ctx) throws Exception {
String topicName = "testCleanupInConsumer";
Properties config = kafkaCluster.useTo().getConsumerProperties("testCleanupInConsumer_consumer",
"testCleanupInConsumer_consumer", OffsetResetStrategy.EARLIEST);
config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
Async async = ctx.async(2);
Async produceLatch = ctx.async();
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start(Future<Void> fut) throws Exception {
KafkaConsumer<String, String> consumer = KafkaConsumer.create(vertx, config);
consumer.handler(record -> {
// Very rarely, this throws a AlreadyUndedeployed error
vertx.undeploy(context.deploymentID(), ctx.asyncAssertSuccess(ar -> {
try {
// Race condition? Without a sleep, test fails sometimes
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
Thread.getAllStackTraces().forEach((t, s) -> {
if (t.getName().contains("vert.x-kafka-consumer-thread")) {
ctx.fail("Was expecting the consumer to be closed");
}
});
async.countDown();
}));
});
consumer.assign(new TopicPartition(topicName, 0), fut);
}
}, ctx.asyncAssertSuccess(v -> produceLatch.complete()
));
produceLatch.awaitSuccess(10000);
kafkaCluster.useTo().produce("testCleanupInConsumer_producer", 100,
new StringSerializer(), new StringSerializer(), async::countDown,
() -> new ProducerRecord<>(topicName, "the_value"));
}
示例14: ClusterDiscovery
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
public ClusterDiscovery(String name, List<ApiDefinition> definitions, AtomicInteger seq) {
vertx
.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
apiDiscovery = ApiDiscovery.create(vertx, new ApiDiscoveryOptions().setName(name));
for (ApiDefinition definition : definitions) {
apiDiscovery.publish(definition,
ar -> seq.incrementAndGet());
}
}
});
}
示例15: fakeEurekaVerticle
import io.vertx.core.AbstractVerticle; //導入依賴的package包/類
private static AbstractVerticle fakeEurekaVerticle() {
return new AbstractVerticle() {
@Override
public void start(Future<Void> startFuture) throws Exception {
final Router router = Router.router(vertx);
router.get("/eureka/v2/apps").handler(context -> {
final HttpServerResponse response = context.response();
vertx.fileSystem()
.readFile("eureka-data.xml", res -> {
if (res.succeeded()) {
response.putHeader(HttpHeaders.CONTENT_TYPE, "application/xml")
.end(res.result());
} else {
response.setStatusCode(500)
.end("Error while reading eureka data from classpath");
}
});
});
vertx.createHttpServer(new HttpServerOptions())
.requestHandler(router::accept)
.listen(FAKE_EUREKA_SERVER_PORT, res -> {
if (res.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(res.cause());
}
});
}
};
}
開發者ID:kennedyoliveira,項目名稱:standalone-hystrix-dashboard,代碼行數:35,代碼來源:HystrixDashboardProxyEurekaTest.java