Bind instance provided by ThrowingProvider to MapBinder

18 views
Skip to first unread message

Michael

unread,
Aug 22, 2014, 6:01:02 AM8/22/14
to google...@googlegroups.com

I am trying to bind instance provided by a ThrowingProvider into MapBinder. But I don't know how to do this.

I have a SslHandlerProvider provides a SSL channel handler.

public interface SslHandlerProvider extends CheckedProvider<ChannelHandler>{
    ChannelHandler get() throws SslException;
}

Here's the implementation :

public class SslHandlerProviderImpl implements SslHandlerProvider{

    @Inject SslContextProvider context;

    @Inject SslContextConfig config;

    @Override
    public ChannelHandler get() throws SslException {
        SSLEngine engine = context.get().createSSLEngine();
        engine.setUseClientMode(config.isClientMode());
        return new SslHandler(engine);
    }

}

In module config, I want to bind a SSLHandler into the MapBinder, but this cause a compile errorThe method toProvider(Provider<? extends ChannelHandler>) in the type LinkedBindingBuilder<ChannelHandler> is not applicable for the arguments (Class<SslHandlerProvider>) when I use .toProvider method.

MapBinder<String, ChannelHandler> handlerBinder = MapBinder.newMapBinder(binder(), String.class, ChannelHandler.class);
//This will cause compile error:
//handlerBinder.addHandler("ssl").toProvider(SslHandlerProvider.class).in(Scopes.NO_SCOPE);

handlerBinder.addHandler("encoder").to(JsonEncoder.class).in(Scopes.NO_SCOPE);
handlerBinder.addHandler("decoder").to(JsonDecoder.class).in(Scopes.NO_SCOPE);

So How could I do this ? Any answer or suggestion is appreciated. Thanks!

Reply all
Reply to author
Forward
0 new messages