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> type)
        Unwraps this Service into the object of the specified type. Use this method instead of an explicit 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);
         
        Specified by:
        as in interface Unwrappable
        Parameters:
        type - the type of the object to return
        Returns:
        the object of the specified type if found. Optional.empty() if not found.
        See Also:
        Unwrappable
      • 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.