You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by Brian Cho <ch...@gmail.com> on 2015/07/08 11:45:29 UTC
Using ExternalConstructor as a named/required parameter
Hi,
I’d like to be able to set an ExternalConstructor as a parameter using Tang. For example, I’m working on some code where I’d like to wire-up HTrace configurations via ExternalConstructor:
public final class HTraceConfiguration extends ConfigurationModuleBuilder {
public static final RequiredParameter<Sampler> SAMPLER_CONSTRUCTOR = new RequiredParameter<>();
public static final ConfigurationModule CONF = new HTraceConfiguration()
.bindImplementation(Tracer.class, HTracer.class)
.bindNamedParameter(HTraceParameters.HTraceSampler.class, SAMPLER_CONSTRUCTOR)
.build();
public static final Configuration getDefaultConfiguration() {
return CONF
.set(SAMPLER_CONSTRUCTOR, AlwaysSamplerConstructor.class)
.build();
}
}
However, there’s no .set() method that will take the class AlwaysSamplerConstructor implements ExternalConstructor<Sampler>. Does it make sense to add this .set() method to Tang? If so, would it be difficult to implement?
Thanks,
Brian
Re: Using ExternalConstructor as a named/required parameter
Posted by 이계원 <st...@gmail.com>.
Hi, Brian, Markus.
I also think that there is no reason for not having .set() method for ExternalConstructors.
I’ve checked the code, and it seems that we can solve the problem by creating another data structure for storing ExternalConstructors. Of course there could be unknown obstacles, though. I’ll create an issue for this in JIRA.
Thanks,
Gyewon
> 2015. 7. 10., 오후 10:58, Markus Weimer <ma...@weimo.de> 작성:
>
> On 2015-07-08 02:45, Brian Cho wrote:
>> I’d like to be able to set an ExternalConstructor as a parameter
>> using Tang. For example, I’m working on some code where I’d like to
>> wire-up HTrace configurations via ExternalConstructor:
>>
>> [...]
>>
>> However, there’s no .set() method that will take the class
>> AlwaysSamplerConstructor implements ExternalConstructor<Sampler>.
>> Does it make sense to add this .set() method to Tang? If so, would it
>> be difficult to implement?
>
> This sounds like a sane extension of Tang to me. I have no idea how hard
> it would be to implement, though.
>
> As a work-around: You can define yourself a wrapping interface with a
> method `getSampler()` or such which you can then use in named parameters
> as usual.
>
> Markus
Re: Using ExternalConstructor as a named/required parameter
Posted by Markus Weimer <ma...@weimo.de>.
On 2015-07-08 02:45, Brian Cho wrote:
> I’d like to be able to set an ExternalConstructor as a parameter
> using Tang. For example, I’m working on some code where I’d like to
> wire-up HTrace configurations via ExternalConstructor:
>
> [...]
>
> However, there’s no .set() method that will take the class
> AlwaysSamplerConstructor implements ExternalConstructor<Sampler>.
> Does it make sense to add this .set() method to Tang? If so, would it
> be difficult to implement?
This sounds like a sane extension of Tang to me. I have no idea how hard
it would be to implement, though.
As a work-around: You can define yourself a wrapping interface with a
method `getSampler()` or such which you can then use in named parameters
as usual.
Markus