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;
}
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>());
}
Aggregations