@Override public VirtualHost virtualHost() { return cfg.virtualHost(); }
/** * Returns the {@link Server} the {@link #service()} belongs to. */ public Server server() { return virtualHost().server(); }
/** * Finds the {@link List} of {@link VirtualHost}s that contains the specified {@link Service}. If there's * no match, an empty {@link List} is returned. Note that this is potentially an expensive operation and * thus should not be used in a performance-sensitive path. */ public List<VirtualHost> findVirtualHosts(Service<?, ?> service) { requireNonNull(service, "service"); @SuppressWarnings("rawtypes") final Class<? extends Service> serviceType = service.getClass(); final List<VirtualHost> res = new ArrayList<>(); for (VirtualHost h : virtualHosts) { for (ServiceConfig c : h.serviceConfigs()) { // Consider the case where the specified service is decorated before being added. final Service<?, ?> s = c.service(); @SuppressWarnings("rawtypes") final Optional<? extends Service> sOpt = s.as(serviceType); if (!sOpt.isPresent()) { continue; } if (sOpt.get() == service) { res.add(c.virtualHost()); break; } } } return res; }
@Override public void serverStarting(Server server) throws Exception { final ServerConfig config = server.config(); final List<VirtualHost> virtualHosts = config.findVirtualHosts(DocService.this); final List<ServiceConfig> services = config.serviceConfigs().stream() .filter(se -> virtualHosts.contains(se.virtualHost())) .collect(toImmutableList()); ServiceSpecification spec = generate(services); spec = addDocStrings(spec, services); spec = addExamples(spec); vfs(SPECIFICATION_INDEX).setContent(jsonMapper.writerWithDefaultPrettyPrinter() .writeValueAsBytes(spec)); } });
@Override public ServiceSpecification generateSpecification(Set<ServiceConfig> serviceConfigs) { requireNonNull(serviceConfigs, "serviceConfigs"); final Map<Class<?>, Set<MethodInfo>> methodInfos = new HashMap<>(); final Map<Class<?>, String> serviceDescription = new HashMap<>(); serviceConfigs.forEach(sc -> { final Optional<AnnotatedHttpService> service = sc.service().as(AnnotatedHttpService.class); service.ifPresent( httpService -> { addMethodInfo(methodInfos, sc.virtualHost().hostnamePattern(), httpService); addServiceDescription(serviceDescription, httpService); }); }); return generate(serviceDescription, methodInfos); }
@Override public ServiceSpecification generateSpecification(Set<ServiceConfig> serviceConfigs) { final Map<Class<?>, EntryBuilder> map = new LinkedHashMap<>(); for (ServiceConfig c : serviceConfigs) { final THttpService service = c.service().as(THttpService.class).get(); service.entries().forEach((serviceName, entry) -> { for (Class<?> iface : entry.interfaces()) { final Class<?> serviceClass = iface.getEnclosingClass(); final EntryBuilder builder = map.computeIfAbsent(serviceClass, cls -> new EntryBuilder(serviceClass)); // Add all available endpoints. Accept only the services with exact and prefix path // mappings, whose endpoint path can be determined. final PathMapping pathMapping = c.pathMapping(); final String path = pathMapping.exactPath().orElse(pathMapping.prefix().orElse(null)); if (path != null) { builder.endpoint(new EndpointInfoBuilder(c.virtualHost().hostnamePattern(), path) .fragment(serviceName) .defaultFormat(service.defaultSerializationFormat()) .availableFormats(service.allowedSerializationFormats()) .build()); } } }); } final List<Entry> entries = map.values().stream() .map(EntryBuilder::build) .collect(Collectors.toList()); return generate(entries); }
final String serviceName = service.getServiceDescriptor().getName(); map.get(serviceName).endpoint( new EndpointInfoBuilder(serviceConfig.virtualHost().hostnamePattern(),
@Override public void serviceAdded(ServiceConfig cfg) throws Exception { checkState(server == null, "cannot be added to more than one server"); server = cfg.server(); router = Routers.ofCompositeService(services); final MeterRegistry registry = server.meterRegistry(); final MeterIdPrefix meterIdPrefix = new MeterIdPrefix("armeria.server.router.compositeServiceCache", "hostnamePattern", cfg.virtualHost().hostnamePattern(), "pathMapping", cfg.pathMapping().meterTag()); router.registerMetrics(registry, meterIdPrefix); for (CompositeServiceEntry<I, O> e : services()) { ServiceCallbackInvoker.invokeServiceAdded(cfg, e.service()); } }
@Override public void serviceAdded(ServiceConfig cfg) throws Exception { final MeterRegistry registry = cfg.server().meterRegistry(); if (cache != null) { CaffeineMetricSupport.setup( registry, new MeterIdPrefix("armeria.server.file.vfsCache", "hostnamePattern", cfg.virtualHost().hostnamePattern(), "pathMapping", cfg.pathMapping().meterTag(), "vfs", config.vfs().meterTag()), cache); } }
@Override public ServiceSpecification generateSpecification(Set<ServiceConfig> serviceConfigs) { final Map<Class<?>, EntryBuilder> map = new LinkedHashMap<>(); for (ServiceConfig c : serviceConfigs) { final THttpService service = c.service().as(THttpService.class).get(); service.entries().forEach((serviceName, entry) -> { for (Class<?> iface : entry.interfaces()) { final Class<?> serviceClass = iface.getEnclosingClass(); final EntryBuilder builder = map.computeIfAbsent(serviceClass, cls -> new EntryBuilder(serviceClass)); // Add all available endpoints. Accept only the services with exact and prefix path // mappings, whose endpoint path can be determined. final PathMapping pathMapping = c.pathMapping(); final String path = pathMapping.exactPath().orElse(pathMapping.prefix().orElse(null)); if (path != null) { builder.endpoint(new EndpointInfo( c.virtualHost().hostnamePattern(), path, serviceName, service.defaultSerializationFormat(), service.allowedSerializationFormats())); } } }); } final List<Entry> entries = map.values().stream() .map(EntryBuilder::build) .collect(Collectors.toList()); return generate(entries); }
@Override public ServiceSpecification generateSpecification(Set<ServiceConfig> serviceConfigs) { final Map<Class<?>, EntryBuilder> map = new LinkedHashMap<>(); for (ServiceConfig c : serviceConfigs) { final THttpService service = c.service().as(THttpService.class).get(); service.entries().forEach((serviceName, entry) -> { for (Class<?> iface : entry.interfaces()) { final Class<?> serviceClass = iface.getEnclosingClass(); final EntryBuilder builder = map.computeIfAbsent(serviceClass, cls -> new EntryBuilder(serviceClass)); // Add all available endpoints. Accept only the services with exact and prefix path // mappings, whose endpoint path can be determined. final PathMapping pathMapping = c.pathMapping(); final String path = pathMapping.exactPath().orElse(pathMapping.prefix().orElse(null)); if (path != null) { builder.endpoint(new EndpointInfoBuilder(c.virtualHost().hostnamePattern(), path) .fragment(serviceName) .defaultFormat(service.defaultSerializationFormat()) .availableFormats(service.allowedSerializationFormats()) .build()); } } }); } final List<Entry> entries = map.values().stream() .map(EntryBuilder::build) .collect(Collectors.toList()); return generate(entries); }
@Override public ServiceSpecification generateSpecification(Set<ServiceConfig> serviceConfigs) { final Map<Class<?>, EntryBuilder> map = new LinkedHashMap<>(); for (ServiceConfig c : serviceConfigs) { final THttpService service = c.service().as(THttpService.class).get(); service.entries().forEach((serviceName, entry) -> { for (Class<?> iface : entry.interfaces()) { final Class<?> serviceClass = iface.getEnclosingClass(); final EntryBuilder builder = map.computeIfAbsent(serviceClass, cls -> new EntryBuilder(serviceClass)); // Add all available endpoints. Accept only the services with exact and prefix path // mappings, whose endpoint path can be determined. final PathMapping pathMapping = c.pathMapping(); final String path = pathMapping.exactPath().orElse(pathMapping.prefix().orElse(null)); if (path != null) { builder.endpoint(new EndpointInfoBuilder(c.virtualHost().hostnamePattern(), path) .fragment(serviceName) .defaultFormat(service.defaultSerializationFormat()) .availableFormats(service.allowedSerializationFormats()) .build()); } } }); } final List<Entry> entries = map.values().stream() .map(EntryBuilder::build) .collect(Collectors.toList()); return generate(entries); }
final String serviceName = service.getServiceDescriptor().getName(); map.get(serviceName).endpoint( new EndpointInfoBuilder(serviceConfig.virtualHost().hostnamePattern(),