use of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter in project rest.li by linkedin.
the class SimpleLoadBalancerStrawMan method main.
public static void main(String[] args) throws URISyntaxException, ServiceUnavailableException {
// define the load balancing strategies that we support (round robin, etc)
Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<>();
loadBalancerStrategyFactories.put("rr", new RandomLoadBalancerStrategyFactory());
loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
// define the clients that we support (http, etc)
Map<String, TransportClientFactory> clientFactories = new HashMap<>();
clientFactories.put("http", new HttpClientFactory.Builder().build());
// listen for service updates (could be a glu discovery client, zk discovery client,
// config discovery client, etc)
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
MockStore<ServiceProperties> serviceRegistry = new MockStore<>();
MockStore<ClusterProperties> clusterRegistry = new MockStore<>();
MockStore<UriProperties> uriRegistry = new MockStore<>();
SimpleLoadBalancerState state = new SimpleLoadBalancerState(executorService, uriRegistry, clusterRegistry, serviceRegistry, clientFactories, loadBalancerStrategyFactories);
// create the load balancer
SimpleLoadBalancer loadBalancer = new SimpleLoadBalancer(state, executorService);
final TransportClient tc = loadBalancer.getClient(new URIRequest("d2://browsemaps/52"), new RequestContext());
final Client c = new TransportClientAdapter(tc, true);
c.restRequest(null);
}
use of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter in project rest.li by linkedin.
the class TestMIMEChainingMultipleSources method setup.
@BeforeClass
public void setup() throws IOException {
_scheduledExecutorService = Executors.newScheduledThreadPool(30);
_clientFactory = new HttpClientFactory.Builder().build();
_client = new TransportClientAdapter(_clientFactory.getClient(Collections.<String, String>emptyMap()));
_server_A_client = new TransportClientAdapter(_clientFactory.getClient(Collections.<String, String>emptyMap()));
final HttpServerFactory httpServerFactory = new HttpServerFactory();
final ServerARequestHandler serverARequestHandler = new ServerARequestHandler();
final TransportDispatcher serverATransportDispatcher = new TransportDispatcherBuilder().addStreamHandler(SERVER_A_URI, serverARequestHandler).build();
final ServerBRequestHandler serverBRequestHandler = new ServerBRequestHandler();
final TransportDispatcher serverBTransportDispatcher = new TransportDispatcherBuilder().addStreamHandler(SERVER_B_URI, serverBRequestHandler).build();
_serverA = httpServerFactory.createServer(PORT_SERVER_A, serverATransportDispatcher, true);
_serverB = httpServerFactory.createServer(PORT_SERVER_B, serverBTransportDispatcher, true);
_serverA.start();
_serverB.start();
}
use of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter in project rest.li by linkedin.
the class TestUnstructuredDataClient method init.
@BeforeClass
public void init() throws Exception {
super.init();
_clientFactory = new HttpClientFactory.Builder().build();
_client = new TransportClientAdapter(_clientFactory.getClient(Collections.emptyMap()), true);
}
use of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter 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>());
}
use of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter in project rest.li by linkedin.
the class RestLiExampleBasicClient method main.
/**
* 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.
*
* 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.Builder().build();
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);
String pathInfo = args.length == 0 ? "" : args[0];
photoClient.sendRequest(pathInfo, new PrintWriter(System.out));
photoClient.shutdown();
http.shutdown(new FutureCallback<>());
}
Aggregations