public static void main(String[] args) throws Exception { Config conf = new Config(); StormSubmitter.submitTopology("reach", conf, buildTopology()); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { Thread.sleep(2000); System.out.println("REACH: " + drpc.execute("reach", "aaa")); System.out.println("REACH: " + drpc.execute("reach", "foo.com/blog/1")); System.out.println("REACH: " + drpc.execute("reach", "engineering.twitter.com/blog/5")); } }
public DRPCSpout(String function) { _function = function; if (DRPCClient.isLocalOverride()) { _local_drpc_id = DRPCClient.getOverrideServiceId(); } else { _local_drpc_id = null; } }
@Test public void testFailedThrift() throws Exception { Map<String, Object> conf = getConf(0, 0, null); try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) { server.start(); try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort()); DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) { Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test")); DRPCRequest request = getNextAvailableRequest(invoke, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); invoke.failRequest(request.get_request_id()); try { found.get(1000, TimeUnit.MILLISECONDS); fail("exec did not throw an exception"); } catch (ExecutionException e) { Throwable t = e.getCause(); assertEquals(t.getClass(), DRPCExecutionException.class); //Don't know a better way to validate that it failed. assertEquals("Request failed", ((DRPCExecutionException)t).get_msg()); } } } }
private static void runAndPrint(DRPCClient drpc, String func, String arg) throws Exception { String result = drpc.execute(func, arg); System.out.println(String.format("%s \"%s\" => \"%s\"", func, arg, result)); }
public static DRPCClient getConfiguredClient(Map<String, Object> conf) throws TTransportException { DistributedRPC.Iface override = _localOverrideClient; if (override != null) { return new DRPCClient(override); for (String host : servers) { try { return new DRPCClient(fullConf, host, port); } catch (RuntimeException e) { if (Utils.exceptionCauseIsInstanceOf(ConnectException.class, e)) {
final String function = (String) cl.get("f"); Config conf = new Config(); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { if (function == null) { if (funcAndArgs.size() % 2 != 0) {
@Test public void testGoodThrift() throws Exception { Map<String, Object> conf = getConf(0, 0, null); try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) { server.start(); try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort()); DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) { final Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test")); DRPCRequest request = getNextAvailableRequest(invoke, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); invoke.result(request.get_request_id(), "tested"); String result = found.get(1000, TimeUnit.MILLISECONDS); assertEquals("tested", result); } } }
public static void main(String[] args) throws Exception { Config conf = new Config(); conf.setMaxSpoutPending(20); String topoName = "wordCounter"; if (args.length > 0) { topoName = args[0]; } conf.setNumWorkers(3); StormSubmitter.submitTopologyWithProgressBar(topoName, conf, buildTopology()); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { for (int i = 0; i < 10; i++) { System.out.println("DRPC RESULT: " + drpc.execute("words", "cat the dog jumped")); Thread.sleep(1000); } } }
public static void main(String[] args) throws Exception { Config conf = new Config(); conf.setMaxSpoutPending(20); String topoName = "wordCounter"; if (args.length > 0) { topoName = args[0]; } conf.setNumWorkers(3); StormSubmitter.submitTopologyWithProgressBar(topoName, conf, buildTopology()); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { for (int i = 0; i < 10; i++) { System.out.println("DRPC RESULT: " + drpc.execute("words", "CAT THE DOG JUMPED")); Thread.sleep(1000); } } } }
public static void main(String[] args) throws Exception { LinearDRPCTopologyBuilder builder = construct(); Config conf = new Config(); conf.setNumWorkers(6); String topoName = "reach-drpc"; if (args.length > 0) { topoName = args[0]; } StormSubmitter.submitTopologyWithProgressBar(topoName, conf, builder.createRemoteTopology()); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { String[] urlsToTry = new String[]{ "foo.com/blog/1", "engineering.twitter.com/blog/5", "notaurl.com" }; for (String url : urlsToTry) { System.out.println("Reach of " + url + ": " + drpc.execute("reach", url)); } } }
public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); DRPCSpout spout = new DRPCSpout("exclamation"); builder.setSpout("drpc", spout); builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc"); builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim"); Config conf = new Config(); StormSubmitter.submitTopology("exclaim", conf, builder.createTopology()); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { System.out.println(drpc.execute("exclamation", "aaa")); System.out.println(drpc.execute("exclamation", "bbb")); } }
public static void main(String[] args) throws Exception { LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("exclamation"); builder.addBolt(new ExclaimBolt(), 3); Config conf = new Config(); String topoName = "DRPCExample"; if (args != null && args.length > 0) { topoName = args[0]; } conf.setNumWorkers(3); StormSubmitter.submitTopologyWithProgressBar(topoName, conf, builder.createRemoteTopology()); if (args.length > 1) { try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { for (int i = 1; i < args.length; i++) { String word = args[i]; System.out.println("Result for \"" + word + "\": " + drpc.execute("exclamation", word)); } } } }