Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ServiceOptions to Service #5071

Closed
ikhoon opened this issue Jul 25, 2023 · 1 comment · Fixed by #5574
Closed

Add ServiceOptions to Service #5071

ikhoon opened this issue Jul 25, 2023 · 1 comment · Fixed by #5574

Comments

@ikhoon
Copy link
Contributor

ikhoon commented Jul 25, 2023

Currently, there is no way to set the default options for a specific service.
Users should override the default options for a service when it is bound to a server.

public final class ServiceBindingBuilder extends AbstractServiceBindingBuilder {

If we provide a way to provide the default options from a service, users can define a sensible default option for certain services when implementing the service.

interface HttpService {

  default ServiceOptions defaultOptions() {
    return ServiceOptions.of();
  }
}

class WebSocketService extends HttpService {
    @Override
    default ServiceOptions defaultOptions() {
       return WEB_SOCKET_DEFAULT_OPTIONS;
    }
}

// ServiceConfigBuilder

if (service.option() != ServiceOptions.of()) {
   // override the default values with service.options().
}

We can also define an annotation like @ServiceOption to inject the values to ServiceOptions for annotated services.

public class MyService {

  @ServiceOption(
     maxRequestLength = 1_000_000, // 100 MB
     responseTimeoutMillis = 120_000, // 2 minutes
     ...
  )
  @Post("/upload")
  public CompletableFuture<Result> upload(MultipartFile file) { ... }

  @ServiceOption(
     responseTimeoutMillis = 0, // disable the timeout
     verboseResponse = true,
     ...
  )
  @Get("/upload")
  public HttpResponse videoStreaming(String filename) { ... }
  
}
@seonWKim
Copy link
Contributor

seonWKim commented Apr 7, 2024

Hi, @ikhoon. I've made a PR on this issue 😀

trustin pushed a commit that referenced this issue Jun 10, 2024
Motivation:

Allow users to set default options for a specific service 

Modifications:

- Add `ServiceOptions` and `@ServiceOption` annotation to allow users
specify default options

Result:

Users are able to set service specific options like below 
```java
final HttpService httpService = new HttpService() {
    ...

    @OverRide
    public ServiceOptions options() {
        return defaultServiceOptions;
    }
};
```

or use annotation 

```java
  final class MyService {

      @ServiceOption(requestTimeoutMillis = 11111, maxRequestLength = 1111,
              requestAutoAbortDelayMillis = 111)
      @get("/test1")
      public HttpResponse test() {
          return HttpResponse.of("OK");
      }
   ...
}
```

- Closes <#5071>. (If this
resolves the issue.)

<!--
Visit this URL to learn more about how to write a pull request
description:

https://armeria.dev/community/developer-guide#how-to-write-pull-request-description
-->

---------

Co-authored-by: minux <songmw725@gmail.com>
Co-authored-by: jrhee17 <guins_j@guins.org>
Co-authored-by: Ikhun Um <ih.pert@gmail.com>
Co-authored-by: Ikhun Um <ikhun.um@linecorp.com>
Co-authored-by: minux <minu.song@linecorp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants