Comments (1)
Hello, @ikhoon nim.
I've come up with an idea for a scalable API, although it might be a bit rough.
By using enums
and Maps
together, I expect that it can be extended in various ServiceConfig
's Children Classes.
How about this way?
public abstract class ServiceConfig {
// Add this abstract method.
public <E, T> T getSpecificValue(E field, Class<T> type);
...
}
- Add abstract method to
ServiceConfig
. all children classes ofServiceConfig
should implement this method. - This method is to produce common interface to get their specific values. (For example,
AnnotatedService
'smethod
) E
means kind ofenum
.T
means type of values.
// Add this enum
public enum AnnotedServiceField {
Method,
ServiceObject,
DefaultStatus,
...
}
- Add
enum
for each concrete class ofServiceConfig
to prevent to forget some fields.
public class AnnotatedService {
...
// Add this method.
public Map<AnnotatedServiceField, Object> fieldsToMap(){
final Map<AnnotatedServiceField, Object> maps = Arrays.stream(AnnotatedServiceField.values())
.collect(Collectors.toMap(v -> v, v -> null));
...
maps.put(AnnotatedServiceField.HttpStatus, this.httpStatus);
maps.put(AnnotatedServiceField.Method, this.method);
...
return maps;
}
...
}
- In case of
AnnotatedService
, i propose that addfieldsToMap()
method to returnMap
their specific fields.
public class AnnotatedServiceConfig extends ServiceConfig {
...
// add this methods.
private final Map<AnnotatedServiceField, Object> specificConfig;
public T getSpecificValue(AnnotatedServiceField field, Class<T> type){
Object field = specifigConfig.get(field);
return (type) field;
}
...
}
AnnotatedServiceConfig
should implement abstract methodT getSpecificValue(AnnotatedServiceField field, Class<T> type)
.
public class ServiceConfigBuilder implements ServiceConfigSetters {
ServiceConfig build(...) {
final Map<AnnotatedServiceField, Object> specificFields = service.fieldsToMap() // Add this code.
ServiceErrorHandler errorHandler =
serviceErrorHandler != null ? serviceErrorHandler.orElse(defaultServiceErrorHandler)
: defaultServiceErrorHandler;
...
}
}
- In case of
AnnotatedServiceConfig
,service.fieldsToMap()
can be added toServiceConfigBuilder#build(...)
forspecificFields
to be includedAnnotatedServiceConfig
.
IMHO, The key aspects are as follows:
- Declare an enum for each Concrete ServiceConfig class to specify certain values.
- Create a Map that uses the enum as a Key and stores values.
- The ServiceConfig interface provides a Generic method to retrieve values from the map.
Through this approach, I expect to ServiceConfig
can produce API that can be extended to multiple concrete class of ServiceConfig
.
What do you think?
When you have some free time, please take a look 🙇♂️
from armeria.
Related Issues (20)
- Avoid `addShutdownHook` to JVM during its shutdown HOT 1
- Compatibility with armeria and grpc 4.26.0 versions is broken. HOT 1
- Provide a way to load a value periodically or when it expires HOT 1
- Derive a new `XdsBootstrap` with `StaticResources`
- who use armeria ? HOT 1
- Support for `@Attribute` in annotated services HOT 4
- Handle an empty query parameters with `@Default` HOT 6
- `RetryingClient` propagates the exception (and whether it is unprocessed) HOT 2
- Make DocService looking up several virtual hosts to represent services in other ports
- Replace `Optional<List<T>>` parameter to `ObjectProvider<T>` HOT 3
- Leak in `ArmeriaHttpPutTest`
- Client-side load balancing for same Endpoint HOT 1
- Add ServerExtension.webSocketClient() for testing
- Do not ignore the result of StreamMessage.tryWrite() in GraphqlWSSubProtocol HOT 6
- Test failure: `com.linecorp.armeria.server.ServerRequestPathEncodingTest` HOT 2
- Make annotated services reject the multipart requests that contain an uninjectable file upload HOT 2
- Make `GrpcStatus` implement `GrpcExceptionHandlerFunction` HOT 2
- Preemptively close the channel when receiving SslCloseCompletionEvent HOT 1
- Make `ClientRequestContext.authority()` and `host()` return non-null HOT 2
- Is it possible to send a ping frame over HTTP/2 using Armeria? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from armeria.