use of io.scalecube.services.gateway.GatewayOptions in project scalecube by scalecube.
the class Microservices method start.
private Mono<Microservices> start() {
LOGGER.info("[{}][start] Starting", id);
// Create bootstrap scheduler
Scheduler scheduler = Schedulers.newSingle(toString(), true);
return transportBootstrap.start(this).publishOn(scheduler).flatMap(transportBootstrap -> {
final ServiceCall call = call();
final Address serviceAddress = transportBootstrap.transportAddress;
final ServiceEndpoint.Builder serviceEndpointBuilder = ServiceEndpoint.builder().id(id).address(serviceAddress).contentTypes(DataCodec.getAllContentTypes()).tags(tags);
// invoke service providers and register services
List<Object> serviceInstances = serviceProviders.stream().flatMap(serviceProvider -> serviceProvider.provide(call).stream()).peek(this::registerInMethodRegistry).peek(serviceInfo -> serviceEndpointBuilder.appendServiceRegistrations(ServiceScanner.scanServiceInfo(serviceInfo))).map(ServiceInfo::serviceInstance).collect(Collectors.toList());
if (transportBootstrap == ServiceTransportBootstrap.NULL_INSTANCE && !serviceInstances.isEmpty()) {
LOGGER.warn("[{}] ServiceTransport is not set", this.id());
}
serviceEndpoint = newServiceEndpoint(serviceEndpointBuilder.build());
return createDiscovery(this, new ServiceDiscoveryOptions().serviceEndpoint(serviceEndpoint)).publishOn(scheduler).then(startGateway(new GatewayOptions().call(call))).publishOn(scheduler).then(Mono.fromCallable(() -> Injector.inject(this, serviceInstances))).then(Mono.fromCallable(() -> JmxMonitorMBean.start(this))).then(compositeDiscovery.startListen()).publishOn(scheduler).thenReturn(this);
}).onErrorResume(ex -> Mono.defer(this::shutdown).then(Mono.error(ex)).cast(Microservices.class)).doOnSuccess(m -> LOGGER.info("[{}][start] Started", id)).doOnTerminate(scheduler::dispose);
}
Aggregations