Search in sources :

Example 31 with HttpClientFactory

use of com.linkedin.r2.transport.http.client.HttpClientFactory in project voldemort by voldemort.

the class RestServiceR2StoreTest method setUp.

@Override
@Before
public void setUp() throws IOException {
    logger.info(" Initial SEED used for random number generator: " + TestUtils.SEED);
    final int numServers = 1;
    this.nodeId = 0;
    servers = new VoldemortServer[numServers];
    // Setup the cluster
    Properties props = new Properties();
    props.setProperty("rest.enable", "true");
    props.setProperty("http.enable", "true");
    Cluster customCluster = clusterMapper.readCluster(new FileReader(clusterXmlFile), false);
    logger.info(" Node " + customCluster.getNodes().iterator().next().getStateString());
    cluster = ServerTestUtils.startVoldemortCluster(servers, null, clusterXmlFile, storesXmlfile, props, customCluster);
    // Creating R2Store
    RESTClientConfig restClientConfig = new RESTClientConfig();
    restClientConfig.setHttpBootstrapURL("http://localhost:" + cluster.getNodeById(0).getRestPort()).setTimeoutMs(10000, TimeUnit.MILLISECONDS).setMaxR2ConnectionPoolSize(100);
    clientFactory = new HttpClientFactory();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize()));
    TransportClient transportClient = clientFactory.getClient(properties);
    R2Store r2Store = new R2Store(STORE_NAME, restClientConfig.getHttpBootstrapURL(), "0", transportClient, restClientConfig, 0);
    store = r2Store;
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) RESTClientConfig(voldemort.restclient.RESTClientConfig) HashMap(java.util.HashMap) R2Store(voldemort.restclient.R2Store) Cluster(voldemort.cluster.Cluster) FileReader(java.io.FileReader) Properties(java.util.Properties) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) Before(org.junit.Before)

Example 32 with HttpClientFactory

use of com.linkedin.r2.transport.http.client.HttpClientFactory in project rest.li by linkedin.

the class RestLiFortunesClient method main.

/**
   * This stand-alone app demos the client-side Pegasus API.
   * To see the demo, run RestLiFortuneServer, then start the client
   */
public static void main(String[] args) throws Exception {
    // Create an HttpClient and wrap it in an abstraction layer
    final HttpClientFactory http = new HttpClientFactory();
    final Client r2Client = new TransportClientAdapter(http.getClient(Collections.<String, String>emptyMap()));
    // Create a RestClient to talk to localhost:8080
    RestClient restClient = new RestClient(r2Client, "http://localhost:8080/");
    // Generate a random ID for a fortune cookie, in the range 0-5
    long fortuneId = (long) (Math.random() * 5);
    // Construct a request for the specified fortune
    FortunesGetBuilder getBuilder = _fortuneBuilder.get();
    Request<Fortune> getReq = getBuilder.id(fortuneId).build();
    // Send the request and wait for a response
    final ResponseFuture<Fortune> getFuture = restClient.sendRequest(getReq);
    final Response<Fortune> resp = getFuture.getResponse();
    // Print the response
    System.out.println(resp.getEntity().getFortune());
    // shutdown
    restClient.shutdown(new FutureCallback<None>());
    http.shutdown(new FutureCallback<None>());
}
Also used : RestClient(com.linkedin.restli.client.RestClient) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) RestClient(com.linkedin.restli.client.RestClient) Client(com.linkedin.r2.transport.common.Client) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) None(com.linkedin.common.util.None)

Aggregations

HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)23 HashMap (java.util.HashMap)23 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)18 None (com.linkedin.common.util.None)15 Test (org.testng.annotations.Test)14 FutureCallback (com.linkedin.common.callback.FutureCallback)13 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)10 URI (java.net.URI)9 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)8 LoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory)8 DegraderLoadBalancerStrategyFactoryV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3)8 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 Client (com.linkedin.r2.transport.common.Client)8 RequestContext (com.linkedin.r2.message.RequestContext)7 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)7 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)7 ArrayList (java.util.ArrayList)7 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)6