/** * This is a stand-alone app to demo the use of client-side Pegasus API. To run in, * com.linkedin.restli.example.RestLiExamplesServer has to be running. * * <p>The only argument is the path to the resource on the photo server, e.g. /photos/1 */ public static void main(String[] args) throws Exception { // create HTTP Netty client with default properties final HttpClientFactory http = new HttpClientFactory(); final TransportClient transportClient = http.getClient(Collections.<String, String>emptyMap()); // create an abstraction layer over the actual client, which supports both REST and RPC final Client r2Client = new TransportClientAdapter(transportClient); // REST client wrapper that simplifies the interface final StringBuilder serverUrlBuilder = new StringBuilder("http://") .append(SERVER_HOSTNAME) .append(":") .append(SERVER_PORT) .append("/"); final RestClient restClient = new RestClient(r2Client, serverUrlBuilder.toString()); final RestLiExampleBasicClient photoClient = new RestLiExampleBasicClient(restClient); photoClient.sendRequest(args[0], new PrintWriter(System.out)); photoClient.shutdown(); http.shutdown(new FutureCallback<None>()); }
@Override @Before public void setUp() { logger.info(" Initial SEED used for random number generator: " + TestUtils.SEED); final int numServers = 1; this.nodeId = 0; servers = new VoldemortServer[numServers]; try { // 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); cluster = ServerTestUtils.startVoldemortCluster( servers, null, clusterXmlFile, storesXmlfile, props, customCluster); } catch (IOException e) { fail("Failure to setup the cluster"); } // 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.POOL_SIZE_KEY, Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize())); TransportClient transportClient = clientFactory.getClient(properties); R2Store r2Store = new R2Store( STORE_NAME, restClientConfig.getHttpBootstrapURL(), "0", transportClient, restClientConfig, 0); store = r2Store; }
public RESTClientFactory(RESTClientFactoryConfig config) { this.restClientFactoryConfig = config; this.config = new RESTClientConfig(restClientFactoryConfig.getClientConfig()); this.stats = new StoreStats(); this.rawStoreList = new ArrayList<R2Store>(); // Create the R2 (Netty) Factory object // TODO: Add monitoring for R2 factory this._clientFactory = new HttpClientFactory(); Map<String, String> properties = new HashMap<String, String>(); properties.put( HttpClientFactory.POOL_SIZE_KEY, Integer.toString(this.config.getMaxR2ConnectionPoolSize())); transportClient = _clientFactory.getClient(properties); this.RESTClientFactoryStats = new StoreClientFactoryStats(); keySerializerMap = new HashMap<String, SerializerDefinition>(); valueSerializerMap = new HashMap<String, SerializerDefinition>(); }