本文整理汇总了Java中io.vertx.servicediscovery.spi.ServiceImporter类的典型用法代码示例。如果您正苦于以下问题:Java ServiceImporter类的具体用法?Java ServiceImporter怎么用?Java ServiceImporter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceImporter类属于io.vertx.servicediscovery.spi包,在下文中一共展示了ServiceImporter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
public void initialize(Handler<ServiceDiscovery> completionHandler) {
Collection<ServiceImporter> spi = getServiceImporterFromSPI();
Map<Future, ServiceImporter> map = new HashMap<>();
List<Future> futures = spi.stream().map(imp -> {
Future<Void> fut = Future.future();
imp.start(vertx, this, new JsonObject(), fut);
map.put(fut, imp);
return fut;
}).collect(Collectors.toList());
CompositeFuture.join(futures)
.setHandler(ar -> {
for (Future f : futures) {
ServiceImporter serviceImporter = map.get(f);
if (f.succeeded()) {
LOGGER.info("Auto-registration of importer " + serviceImporter);
importers.add(serviceImporter);
} else {
LOGGER.warn("Failed to register importer " + serviceImporter);
}
}
completionHandler.handle(this);
});
}
示例2: registerConsul
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
private void registerConsul(ServiceDiscovery discovery, JsonObject config) {
try {
ServiceImporter serviceImporter = new ConsulServiceImporter();
discovery
.registerServiceImporter(serviceImporter, config,
Future.<Void>future().completer());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: registerZookeeper
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
private void registerZookeeper(ServiceDiscovery discovery, JsonObject config) {
try {
ServiceImporter serviceImporter = new ZookeeperServiceImporter();
discovery
.registerServiceImporter(serviceImporter, config,
Future.<Void>future().completer());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: getServiceImporterFromSPI
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
private Collection<ServiceImporter> getServiceImporterFromSPI() {
ServiceLoader<ServiceImporter> importers = ServiceLoader.load(ServiceImporter.class);
Iterator<ServiceImporter> iterator = importers.iterator();
List<ServiceImporter> list = new ArrayList<>();
// We have a name
while (iterator.hasNext()) {
ServiceImporter importer = iterator.next();
list.add(importer);
}
return list;
}
示例5: registerServiceImporter
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
@Override
public ServiceDiscovery registerServiceImporter(ServiceImporter importer, JsonObject configuration,
Handler<AsyncResult<Void>> completionHandler) {
JsonObject conf;
if (configuration == null) {
conf = new JsonObject();
} else {
conf = configuration;
}
Future<Void> completed = Future.future();
completed.setHandler(
ar -> {
if (ar.failed()) {
LOGGER.error("Cannot start the service importer " + importer, ar.cause());
if (completionHandler != null) {
completionHandler.handle(Future.failedFuture(ar.cause()));
}
} else {
importers.add(importer);
LOGGER.info("Service importer " + importer + " started");
if (completionHandler != null) {
completionHandler.handle(Future.succeededFuture(null));
}
}
}
);
importer.start(vertx, this, conf, completed);
return this;
}
示例6: testBridges
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
@Test
public void testBridges() {
AtomicBoolean closed = new AtomicBoolean();
AtomicBoolean registered = new AtomicBoolean();
ServiceImporter bridge = new ServiceImporter() {
@Override
public void start(Vertx vertx, ServicePublisher publisher, JsonObject configuration, Future<Void> future) {
Record rec1 = HttpEndpoint.createRecord("static-record-1", "acme.org");
Record rec2 = HttpEndpoint.createRecord("static-record-2", "example.com");
publisher.publish(rec1,
ar -> publisher.publish(rec2, ar2 -> {
registered.set(true);
future.complete();
}));
}
@Override
public void close(Handler<Void> closeHandler) {
closed.set(true);
closeHandler.handle(null);
}
};
discovery.registerServiceImporter(bridge, null);
await().untilAtomic(registered, is(true));
AtomicReference<Record> record1 = new AtomicReference<>();
AtomicReference<Record> record2 = new AtomicReference<>();
discovery.getRecord(new JsonObject().put("name", "static-record-1"), found -> {
record1.set(found.result());
});
discovery.getRecord(new JsonObject().put("name", "static-record-2"), found -> {
record2.set(found.result());
});
assertThat(record1).isNotNull();
assertThat(record2).isNotNull();
discovery.close();
await().untilAtomic(closed, is(true));
}
示例7: registerServiceImporter
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ServiceDiscovery registerServiceImporter(ServiceImporter importer, JsonObject configuration) {
return unmanagedDiscoveryInstance.registerServiceImporter(importer, configuration);
}
示例8: registerServiceImporter
import io.vertx.servicediscovery.spi.ServiceImporter; //导入依赖的package包/类
/**
* Registers a discovery service importer. Importers let you integrate other discovery technologies in this service
* discovery.
*
* @param importer the service importer
* @param configuration the optional configuration
* @return the current {@link ServiceDiscovery}
*/
ServiceDiscovery registerServiceImporter(ServiceImporter importer, JsonObject configuration);