当前位置: 首页>>代码示例>>Java>>正文


Java ClientFactory类代码示例

本文整理汇总了Java中com.netflix.client.ClientFactory的典型用法代码示例。如果您正苦于以下问题:Java ClientFactory类的具体用法?Java ClientFactory怎么用?Java ClientFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClientFactory类属于com.netflix.client包,在下文中一共展示了ClientFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPrimeConnectionsLargePool

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Test
public void testPrimeConnectionsLargePool() throws Exception {
	Configuration config = ConfigurationManager.getConfigInstance();
	config.setProperty("PrimeConnectionsTest2.ribbon.NFLoadBalancerClassName", 
			com.netflix.loadbalancer.DynamicServerListLoadBalancer.class.getName());
	config.setProperty("PrimeConnectionsTest2.ribbon.NIWSServerListClassName", LargeFixedServerList.class.getName());
	config.setProperty("PrimeConnectionsTest2.ribbon.EnablePrimeConnections", "true");
	DynamicServerListLoadBalancer<Server> lb = (DynamicServerListLoadBalancer<Server>) ClientFactory.getNamedLoadBalancer("PrimeConnectionsTest2");
	PrimeConnectionEndStats stats = lb.getPrimeConnections().getEndStats();
	assertEquals(stats.success, LARGE_FIXED_SERVER_LIST_SIZE);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:12,代码来源:PrimeConnectionsTest.java

示例2: beforeTest

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Before
public void beforeTest() {
    ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon.NFLoadBalancerClassName", BaseLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon.client.NFLoadBalancerPingClassName", DummyPing.class.getName());

    ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon.ReadTimeout", "1000");
    ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon." + CommonClientConfigKey.ConnectTimeout, "500");
    ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon." + CommonClientConfigKey.OkToRetryOnAllOperations, "true");

    client = (RestClient) ClientFactory.getNamedClient("RetryTest");

    lb = (BaseLoadBalancer) client.getLoadBalancer();
    lb.setServersList(Lists.newArrayList(localServer));
    
    httpClient = NFHttpClientFactory.getNamedNFHttpClient("RetryTest");
    connectionPoolManager = (MonitoredConnectionManager) httpClient.getConnectionManager(); 
    
    client.setMaxAutoRetries(0);
    client.setMaxAutoRetriesNextServer(0);
    client.setOkToRetryOnAllOperations(false);
    lb.setServersList(Lists.newArrayList(localServer));
    // reset the server index
    lb.setRule(new AvailabilityFilteringRule());
    lb.getLoadBalancerStats().getSingleServerStat(localServer).clearSuccessiveConnectionFailureCount();
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:26,代码来源:RetryTest.java

示例3: testSunnyDayNoClientAuth

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Test
public void testSunnyDayNoClientAuth() throws Exception{

	AbstractConfiguration cm = ConfigurationManager.getConfigInstance();

	String name = "GetPostSecureTest" + ".testSunnyDayNoClientAuth";

	String configPrefix = name + "." + "ribbon";

	cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
	cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT2));
	cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
	cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS2.getAbsolutePath());
	cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);

	RestClient rc = (RestClient) ClientFactory.getNamedClient(name);

	testServer2.accept();

	URI getUri = new URI(SERVICE_URI2 + "test/");
       HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
	HttpResponse response = rc.execute(request);
	assertEquals(200, response.getStatus());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:25,代码来源:SecureGetTest.java

示例4: testSecureClient2

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Test
public void testSecureClient2()  throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.IsSecure, "true");
    ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStore, secureServer.getTrustStore().getAbsolutePath());
    ConfigurationManager.getConfigInstance().setProperty("test3.ribbon." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD);
    
    RestClient client = (RestClient) ClientFactory.getNamedClient("test3");
    BaseLoadBalancer lb = new BaseLoadBalancer();
    Server[] servers = new Server[]{new Server("localhost", secureServer.getServerPort())}; 
    lb.addServers(Arrays.asList(servers));
    client.setLoadBalancer(lb);
    HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
    HttpResponse response = client.executeWithLoadBalancer(request);
    assertStatusIsOk(response.getStatus());
    assertEquals(secureServer.getServerPath("/"), response.getRequestedURI().toString());
    
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:18,代码来源:RestClientTest.java

示例5: testConnectionPoolCleaner

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Test
public void testConnectionPoolCleaner() throws Exception {
    // LogManager.getRootLogger().setLevel((Level)Level.DEBUG);
    ConfigurationManager.getConfigInstance().setProperty("ConnectionPoolCleanerTest.ribbon." + CommonClientConfigKey.ConnIdleEvictTimeMilliSeconds, "100");
    ConfigurationManager.getConfigInstance().setProperty("ConnectionPoolCleanerTest.ribbon." + CommonClientConfigKey.ConnectionCleanerRepeatInterval, "500");
    RestClient client = (RestClient) ClientFactory.getNamedClient("ConnectionPoolCleanerTest");
    NFHttpClient httpclient = NFHttpClientFactory.getNamedNFHttpClient("ConnectionPoolCleanerTest");
    assertNotNull(httpclient);
    com.netflix.client.http.HttpResponse response = null;
    try {
        response = client.execute(HttpRequest.newBuilder().uri(server.getServerPath("/")).build());
    } finally {
        if (response != null) {
            response.close();
        }
    }
    MonitoredConnectionManager connectionPoolManager = (MonitoredConnectionManager) httpclient.getConnectionManager();
    Thread.sleep(2000);
    assertEquals(0, connectionPoolManager.getConnectionsInPool());
    client.shutdown();
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:22,代码来源:NamedConnectionPoolTest.java

示例6: getFilterImpl

import com.netflix.client.ClientFactory; //导入依赖的package包/类
/**
 * Get a ServerListFilter instance. It uses {@link ClientFactory#instantiateInstanceWithClientConfig(String, IClientConfig)}
 * which in turn uses reflection to initialize the filter instance. 
 * The filter class name is determined by the value of {@link CommonClientConfigKey#NIWSServerListFilterClassName}
 * in the {@link IClientConfig}. The default implementation is {@link ZoneAffinityServerListFilter}.
 */
public AbstractServerListFilter<T> getFilterImpl(IClientConfig niwsClientConfig) throws ClientException{
    try {
        String niwsServerListFilterClassName = niwsClientConfig
                .getProperty(
                        CommonClientConfigKey.NIWSServerListFilterClassName,
                        ZoneAffinityServerListFilter.class.getName())
                .toString();

        AbstractServerListFilter<T> abstractNIWSServerListFilter = 
                (AbstractServerListFilter<T>) ClientFactory.instantiateInstanceWithClientConfig(niwsServerListFilterClassName, niwsClientConfig);
        return abstractNIWSServerListFilter;
    } catch (Throwable e) {
        throw new ClientException(
                ClientException.ErrorType.CONFIGURATION,
                "Unable to get an instance of CommonClientConfigKey.NIWSServerListFilterClassName. Configured class:"
                        + niwsClientConfig
                                .getProperty(CommonClientConfigKey.NIWSServerListFilterClassName), e);
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:26,代码来源:AbstractServerList.java

示例7: initWithNiwsConfig

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Override
public void initWithNiwsConfig(IClientConfig clientConfig) {
    String ruleClassName = (String) clientConfig
            .getProperty(CommonClientConfigKey.NFLoadBalancerRuleClassName);
    String pingClassName = (String) clientConfig
            .getProperty(CommonClientConfigKey.NFLoadBalancerPingClassName);

    IRule rule;
    IPing ping;
    try {
        rule = (IRule) ClientFactory.instantiateInstanceWithClientConfig(
                ruleClassName, clientConfig);
        ping = (IPing) ClientFactory.instantiateInstanceWithClientConfig(
                pingClassName, clientConfig);
    } catch (Exception e) {
        throw new RuntimeException("Error initializing load balancer", e);
    }
    initWithConfig(clientConfig, rule, ping);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:20,代码来源:BaseLoadBalancer.java

示例8: run

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Override
protected String run() {
	try {
		/*
		 * The named client param must match the prefix for the ribbon
		 * configuration specified in the edge.properties file
		 */
		RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);

		HttpClientRequest request = HttpClientRequest
				.newBuilder()
				.setVerb(Verb.POST)
				.setUri(new URI("/"
						+ RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
						+ RSSConstants.RSS_ENTRY_POINT
                           + "?url=" + url))
				.build();
		HttpClientResponse response = client.executeWithLoadBalancer(request);

		return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
	} catch (Exception exc) {
		throw new RuntimeException("Exception occurred when adding a RSS feed", exc);
	}
}
 
开发者ID:Netflix,项目名称:recipes-rss,代码行数:25,代码来源:AddRSSCommand.java

示例9: run

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Override
protected String run() {
	try {
		// The named client param must match the prefix for the ribbon
		// configuration specified in the edge.properties file
		RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);

		HttpClientRequest request = HttpClientRequest
				.newBuilder()
				.setVerb(Verb.GET)
				.setUri(new URI("/"
						+ RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
						+ RSSConstants.RSS_ENTRY_POINT)
                   )
				.build();
		HttpClientResponse response = client.executeWithLoadBalancer(request);

		return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
	} catch (Exception exc) {
		throw new RuntimeException("Exception", exc);
	}
}
 
开发者ID:Netflix,项目名称:recipes-rss,代码行数:23,代码来源:GetRSSCommand.java

示例10: run

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Override
protected String run() {
	try {
		// The named client param must match the prefix for the ribbon
		// configuration specified in the edge.properties file
		RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);

		HttpClientRequest request = HttpClientRequest
				.newBuilder()
				.setVerb(Verb.DELETE)
				.setUri(new URI("/"
                           + RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
                           + RSSConstants.RSS_ENTRY_POINT
                           + "?url=" + url)
                   )
				.build();
		HttpClientResponse response = client.executeWithLoadBalancer(request);

		return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
	} catch (Exception exc) {
		throw new RuntimeException("Exception", exc);
	}
}
 
开发者ID:Netflix,项目名称:recipes-rss,代码行数:24,代码来源:DeleteRSSCommand.java

示例11: testCreateLBClient

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Test
public void testCreateLBClient() {
  LBClientFactory.Default lbClientFactory = new LBClientFactory.Default();
  LBClient client = lbClientFactory.create("clientName");
  assertEquals("clientName", client.getClientName());
  assertEquals(ClientFactory.getNamedLoadBalancer("clientName"), client.getLoadBalancer());
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:8,代码来源:LBClientFactoryTest.java

示例12: create

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@Override
public LBClient create(String clientName) {
    LBClient client = new LBClientFactory.Default().create(clientName);
    IClientConfig config = ClientFactory.getNamedConfig(clientName);
    client.setRetryHandler(new DefaultLoadBalancerRetryHandler(config));
    return client;
}
 
开发者ID:aatarasoff,项目名称:spring-cloud-marathon,代码行数:8,代码来源:RibbonMarathonClient.java

示例13: create

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T create(Class<T> clientClass) {

    Preconditions.checkNotNull(this.namedClient, "NamedClient required");
    Preconditions.checkNotNull(
            this.restAdapterConfig.getMessageSerializer(),
            "MessageSerializer required");

    LOGGER.info("Using NamedClient {}", this.namedClient);
    LOGGER.info("Using MessageSerializer {}",
            this.restAdapterConfig.getMessageSerializer());

    final RestClient restClient = (RestClient) ClientFactory
            .getNamedClient(namedClient);
    restClient.getJerseyClient().addFilter(new LoggerFilter());

    if (this.restAdapterConfig.getEncoding() == Encoding.gzip) {
        restClient.getJerseyClient().addFilter(
                new GZIPContentEncodingFilter());
    }

    InvocationHandler invocationHandler = new JerseyInvocationHandler(
            restClient, this.restAdapterConfig);
    Object proxyInstance = Proxy.newProxyInstance(
            ClassLoader.getSystemClassLoader(),
            new Class<?>[] { clientClass }, invocationHandler);
    return (T) proxyInstance;
}
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:29,代码来源:RestAdapter.java

示例14: doGet

import com.netflix.client.ClientFactory; //导入依赖的package包/类
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doGet(HttpServletRequest servletRequest,
		HttpServletResponse servletResponse) throws ServletException,
		IOException {
	try {
					
		System.out.println(ConfigurationManager.getConfigInstance()
				.getProperty("sample-client.ribbon.listOfServers"));
		RestClient client = (RestClient) ClientFactory
				.getNamedClient("sample-client");
		HttpRequest request = HttpRequest.newBuilder().uri(new URI("/"))
				.build();
		for (int i = 0; i < 1; i++) {
			HttpResponse response = client.executeWithLoadBalancer(request);
			System.out.println("Status code for "
					+ response.getRequestedURI() + "  :"
					+ response.getStatus());
		}
		@SuppressWarnings("rawtypes")
		ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) client
				.getLoadBalancer();
		servletResponse.getOutputStream().println(lb.getLoadBalancerStats().toString());
		
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:WASdev,项目名称:sample.netflixoss.wlp,代码行数:31,代码来源:Ribbon.java

示例15: testZoneExclusivity

import com.netflix.client.ClientFactory; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })    
@Test
public void testZoneExclusivity() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.EnableZoneExclusivity", "true");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest2");
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();        
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    servers.add(createServer(3, "c"));
    servers.add(createServer(4, "c"));
    servers.add(createServer(5, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c"));
    assertEquals(expected, filtered);
    lb.setServersList(filtered);        
    for (int i = 1; i <= 4; i++) {            
        loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(expected, filtered);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:39,代码来源:DefaultNIWSServerListFilterTest.java


注:本文中的com.netflix.client.ClientFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。