Here are the analogous components in Config vs Health in order to discuss the
#43 issue.
Config Response
spi.ConfigBuilder ResponseBuilder
spi.ConfigProviderResolver spi.SPIFactory
There seem to be two main concerns:
1. SPIFactory should be called ResponseBuilderResolver to be consistent with the config conventions.
2. There are 3 methods on ResponseBuilder(#up(), #down(), #state(boolean)) that return a Response instance rather than a single build() method.
Some other structural differences are:
3a. One accesses a ConfigProviderResolver via an ConfigProviderResolver#instance() static method while an SPIFactory is implicitly used from within the Response#named(String) static method to create a ResponseBuilder.
3b. The ConfigBuilder is part of the spi package while ResponseBuilder is in the root of the api package.
Concern 2. could be addressed by either:
public abstract class ResponseBuilder {
public abstract ResponseBuilder name(String name);
public abstract ResponseBuilder withAttribute(String key, String value);
public abstract ResponseBuilder withAttribute(String key, long value);
public abstract ResponseBuilder withAttribute(String key, boolean value);
public abstract ResponseBuilder up();
public abstract ResponseBuilder down();
public abstract Response build();
}
or more simply:
public abstract class ResponseBuilder {
public abstract ResponseBuilder name(String name);
public abstract ResponseBuilder withAttribute(String key, String value);
public abstract ResponseBuilder withAttribute(String key, long value);
public abstract ResponseBuilder withAttribute(String key, boolean value);
public abstract Response build(boolean up);
}
To address concerns 1. and 3. the following would have to change:
1. SPIFactory would be renamed ResponseBuilderProvider, and be made an abstract class with an instance() static method that either used the explicitly provided ResponseBuilder as previously set via a setInstance(ResponseBuilder) static method that exists to accommodate OSGi environments, or it would use the java.util.ServiceLoader pattern to locate a ResponseBuilderProvider.
2. ResponseBuilder would be moved into the spi package.
3. The Response#named(String) method and associated service loader code would be removed as it has been replaced by the ResponseBuilderProvider.
so creation of a response as it is currently:
Response response = Response.named("somename")
.withAttribute("uptime", 60)
.up();
would become:
Response response = ResponseBuilderProvider.instance()
.name("somename")
.withAttribute("uptime", 60)
.build(true);
Discussion?