com.netflix.ribbon.RibbonTransportFactory Java Examples

The following examples show how to use com.netflix.ribbon.RibbonTransportFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxMovieProxyExampleTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBindCustomClientConfigFactory() {
    ConfigurationManager.getConfigInstance().setProperty(MovieService.class.getSimpleName() + ".MyConfig.listOfServers", "localhost:" + port);

    Injector injector = Guice.createInjector(
            new AbstractModule() {
                @Override
                protected void configure() {
                    bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON);
                    bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
                    bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON);
                    bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON);
                }
            },
            new AbstractModule() {
                @Override
                protected void configure() {
                    bind(MovieService.class).toProvider(new RibbonResourceProvider<MovieService>(MovieService.class)).asEagerSingleton();
                }
            }
    );

    RxMovieProxyExample example = injector.getInstance(RxMovieProxyExample.class);
    assertTrue(example.runExample());
}
 
Example #2
Source File: RxMovieProxyExampleTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransportFactoryWithInjection() {
    Injector injector = Guice.createInjector(
            new AbstractModule() {
                @Override
                protected void configure() {
                    bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON);
                    bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
                }
            }
    );

    RibbonTransportFactory transportFactory = injector.getInstance(RibbonTransportFactory.class);
    HttpClient<ByteBuf, ByteBuf> client = transportFactory.newHttpClient("myClient");
    IClientConfig config = ((LoadBalancingHttpClient) client).getClientConfig();
    assertEquals("MyConfig", config.getNameSpace());
}
 
Example #3
Source File: RibbonModule.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    bind(ClientConfigFactory.class).toInstance(ClientConfigFactory.DEFAULT);
    bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
    bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON);
    bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON);
}
 
Example #4
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public RibbonDynamicProxy(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory, ClientConfigFactory configFactory,
                          RibbonTransportFactory transportFactory, AnnotationProcessorsProvider processors) {
    registerAnnotationProcessors(processors);
    ClassTemplate<T> classTemplate = ClassTemplate.from(clientInterface);
    HttpResourceGroup httpResourceGroup = new ProxyHttpResourceGroupFactory<T>(classTemplate, resourceGroupFactory, processors).createResourceGroup();
    templateExecutorMap = MethodTemplateExecutor.from(httpResourceGroup, clientInterface, processors);
    lifeCycle = new ProxyLifecycleImpl(httpResourceGroup);
}
 
Example #5
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory,
                                ClientConfigFactory configFactory, RibbonTransportFactory transportFactory, AnnotationProcessorsProvider processors) {
    if (!clientInterface.isInterface()) {
        throw new IllegalArgumentException(clientInterface.getName() + " is a class not interface");
    }
    return (T) Proxy.newProxyInstance(
            Thread.currentThread().getContextClassLoader(),
            new Class[]{clientInterface, ProxyLifeCycle.class},
            new RibbonDynamicProxy<T>(clientInterface, resourceGroupFactory, configFactory, transportFactory, processors)
    );
}
 
Example #6
Source File: SecuredRibbonResourceFactory.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public SecuredRibbonResourceFactory(final ClientConfigFactory configFactory, final RibbonTransportFactory transportFactory, final AnnotationProcessorsProvider processors) {
    super(configFactory, transportFactory, processors);
}
 
Example #7
Source File: SecuredRibbonResourceFactory.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public SecuredRibbonResourceFactory(final ClientConfigFactory configFactory, final RibbonTransportFactory transportFactory, final AnnotationProcessorsProvider processors) {
    super(configFactory, transportFactory, processors);
}
 
Example #8
Source File: ProxyHttpResourceGroupFactory.java    From ribbon with Apache License 2.0 4 votes vote down vote up
ProxyHttpResourceGroupFactory(ClassTemplate<T> classTemplate) {
    this(classTemplate, new DefaultResourceFactory(ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT),
            AnnotationProcessorsProvider.DEFAULT);
}
 
Example #9
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public static <T> T newInstance(Class<T> clientInterface) {
    return newInstance(clientInterface, new DefaultResourceFactory(ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT),
            ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT);
}
 
Example #10
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public static <T> T newInstance(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory,
                                ClientConfigFactory configFactory, RibbonTransportFactory transportFactory) {
    return newInstance(clientInterface, resourceGroupFactory, configFactory, transportFactory, AnnotationProcessorsProvider.DEFAULT);
}
 
Example #11
Source File: HttpResourceGroup.java    From ribbon with Apache License 2.0 4 votes vote down vote up
private Builder(String name, ClientConfigFactory configFactory, RibbonTransportFactory transportFactory) {
    this.name = name;
    this.clientConfigFactory = configFactory;
    this.transportFactory = transportFactory;
}
 
Example #12
Source File: HttpResourceGroup.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public static Builder newBuilder(String groupName, ClientConfigFactory configFactory, RibbonTransportFactory transportFactory) {
    return new Builder(groupName, configFactory, transportFactory);
}
 
Example #13
Source File: HttpResourceGroup.java    From ribbon with Apache License 2.0 4 votes vote down vote up
protected HttpResourceGroup(String groupName) {
    super(groupName, ClientOptions.create(), ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT);
    client = transportFactory.newHttpClient(getClientConfig());
    headers = HttpHeaders.EMPTY_HEADERS;
}
 
Example #14
Source File: HttpResourceGroup.java    From ribbon with Apache License 2.0 4 votes vote down vote up
protected HttpResourceGroup(String groupName, ClientOptions options, ClientConfigFactory configFactory, RibbonTransportFactory transportFactory, HttpHeaders headers) {
    super(groupName, options, configFactory, transportFactory);
    client = transportFactory.newHttpClient(getClientConfig());
    this.headers = headers;
}
 
Example #15
Source File: HttpResourceGroupFactoryTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Test
public void testResourceGroupAnnotationMissing() throws Exception {
    ClassTemplate<SampleMovieService> classTemplate = new ClassTemplate<SampleMovieService>(SampleMovieService.class);
    new ProxyHttpResourceGroupFactory<SampleMovieService>(classTemplate, new DefaultResourceFactory(ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT),
            AnnotationProcessorsProvider.DEFAULT).createResourceGroup();
}