Search in sources :

Example 1 with ServiceTransport

use of io.scalecube.services.transport.api.ServiceTransport 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);
}
Also used : ServiceDiscoveryOptions(io.scalecube.services.discovery.api.ServiceDiscoveryOptions) Sinks(reactor.core.publisher.Sinks) Arrays(java.util.Arrays) ServiceProviderErrorMapper(io.scalecube.services.exceptions.ServiceProviderErrorMapper) LoggerFactory(org.slf4j.LoggerFactory) UnaryOperator(java.util.function.UnaryOperator) ClientTransport(io.scalecube.services.transport.api.ClientTransport) DefaultErrorMapper(io.scalecube.services.exceptions.DefaultErrorMapper) InetAddress(java.net.InetAddress) Map(java.util.Map) ServiceTransport(io.scalecube.services.transport.api.ServiceTransport) Disposables(reactor.core.Disposables) Address(io.scalecube.net.Address) GatewayOptions(io.scalecube.services.gateway.GatewayOptions) ServiceDiscoveryContext(io.scalecube.services.discovery.api.ServiceDiscoveryContext) ServerTransport(io.scalecube.services.transport.api.ServerTransport) ServiceRegistry(io.scalecube.services.registry.api.ServiceRegistry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) ObjectName(javax.management.ObjectName) Collectors(java.util.stream.Collectors) ServiceDiscovery(io.scalecube.services.discovery.api.ServiceDiscovery) RoundRobinServiceRouter(io.scalecube.services.routing.RoundRobinServiceRouter) Objects(java.util.Objects) Routers(io.scalecube.services.routing.Routers) List(java.util.List) DataCodec(io.scalecube.services.transport.api.DataCodec) ServiceMethodInvoker(io.scalecube.services.methods.ServiceMethodInvoker) ServiceDiscoveryFactory(io.scalecube.services.discovery.api.ServiceDiscoveryFactory) Optional(java.util.Optional) ServiceMessage(io.scalecube.services.api.ServiceMessage) Exceptions(reactor.core.Exceptions) StandardMBean(javax.management.StandardMBean) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Disposable(reactor.core.Disposable) ServiceMethodRegistryImpl(io.scalecube.services.methods.ServiceMethodRegistryImpl) MethodInfo(io.scalecube.services.methods.MethodInfo) HashMap(java.util.HashMap) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Authenticator(io.scalecube.services.auth.Authenticator) ArrayList(java.util.ArrayList) ServiceMessageDataDecoder(io.scalecube.services.transport.api.ServiceMessageDataDecoder) MBeanServer(javax.management.MBeanServer) ServiceDiscoveryEvent(io.scalecube.services.discovery.api.ServiceDiscoveryEvent) ServiceRegistryImpl(io.scalecube.services.registry.ServiceRegistryImpl) Schedulers(reactor.core.scheduler.Schedulers) ManagementFactory(java.lang.management.ManagementFactory) NoSuchElementException(java.util.NoSuchElementException) Logger(org.slf4j.Logger) RETRY_NON_SERIALIZED(io.scalecube.reactor.RetryNonSerializedEmitFailureHandler.RETRY_NON_SERIALIZED) Mono(reactor.core.publisher.Mono) UnknownHostException(java.net.UnknownHostException) PrincipalMapper(io.scalecube.services.auth.PrincipalMapper) Flux(reactor.core.publisher.Flux) Gateway(io.scalecube.services.gateway.Gateway) StringJoiner(java.util.StringJoiner) Type(io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type) Collections(java.util.Collections) ServiceMethodRegistry(io.scalecube.services.methods.ServiceMethodRegistry) InetAddress(java.net.InetAddress) Address(io.scalecube.net.Address) Scheduler(reactor.core.scheduler.Scheduler) ServiceDiscoveryOptions(io.scalecube.services.discovery.api.ServiceDiscoveryOptions) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) GatewayOptions(io.scalecube.services.gateway.GatewayOptions)

Aggregations

Address (io.scalecube.net.Address)1 RETRY_NON_SERIALIZED (io.scalecube.reactor.RetryNonSerializedEmitFailureHandler.RETRY_NON_SERIALIZED)1 ServiceMessage (io.scalecube.services.api.ServiceMessage)1 Authenticator (io.scalecube.services.auth.Authenticator)1 PrincipalMapper (io.scalecube.services.auth.PrincipalMapper)1 ServiceDiscovery (io.scalecube.services.discovery.api.ServiceDiscovery)1 ServiceDiscoveryContext (io.scalecube.services.discovery.api.ServiceDiscoveryContext)1 ServiceDiscoveryEvent (io.scalecube.services.discovery.api.ServiceDiscoveryEvent)1 Type (io.scalecube.services.discovery.api.ServiceDiscoveryEvent.Type)1 ServiceDiscoveryFactory (io.scalecube.services.discovery.api.ServiceDiscoveryFactory)1 ServiceDiscoveryOptions (io.scalecube.services.discovery.api.ServiceDiscoveryOptions)1 DefaultErrorMapper (io.scalecube.services.exceptions.DefaultErrorMapper)1 ServiceProviderErrorMapper (io.scalecube.services.exceptions.ServiceProviderErrorMapper)1 Gateway (io.scalecube.services.gateway.Gateway)1 GatewayOptions (io.scalecube.services.gateway.GatewayOptions)1 MethodInfo (io.scalecube.services.methods.MethodInfo)1 ServiceMethodInvoker (io.scalecube.services.methods.ServiceMethodInvoker)1 ServiceMethodRegistry (io.scalecube.services.methods.ServiceMethodRegistry)1 ServiceMethodRegistryImpl (io.scalecube.services.methods.ServiceMethodRegistryImpl)1 ServiceRegistryImpl (io.scalecube.services.registry.ServiceRegistryImpl)1