Interface Service<I extends Request,​O extends Response>

    • Method Detail

      • serviceAdded

        default void serviceAdded​(ServiceConfig cfg)
                           throws Exception
        Invoked when this Service has been added to a Server with the specified configuration. Please note that this method can be invoked more than once if this Service has been added more than once.
        Throws:
        Exception
      • as

        default <T> Optional<T> as​(Class<T> serviceType)
        Undecorates this Service to find the Service which is an instance of the specified serviceType. Use this method instead of an explicit downcast since most Services are decorated via decorate(Function) and thus cannot be downcast. For example:
        
         Service s = new MyService().decorate(LoggingService.newDecorator())
                                    .decorate(AuthService.newDecorator());
         MyService s1 = s.as(MyService.class);
         LoggingService s2 = s.as(LoggingService.class);
         AuthService s3 = s.as(AuthService.class);
         
        Parameters:
        serviceType - the type of the desired Service
        Returns:
        the Service which is an instance of serviceType if this Service decorated such a Service. Optional.empty() otherwise.
      • decorate

        default <R extends Service<?,​?>> R decorate​(Class<R> serviceType)
        Creates a new Service that decorates this Service with a new Service instance of the specified serviceType. The specified Class must have a single-parameter constructor which accepts this Service.
      • shouldCachePath

        default boolean shouldCachePath​(String path,
                                        @Nullable
                                        String query,
                                        Route route)
        Returns whether the given path and query should be cached if the service's result is successful. By default, exact path mappings with no input query are cached.