private RocksService getRocksClient() throws Exception { if (rocksClient.get() == null) { try { rocksClient.set(clientManager.createClient( new FramedClientConnector(fromParts(host, port)), RocksService.class).get()); logger.info("Opened Rocksdb connection to " + host + ":" + port); } catch (Exception e) { logger.error("Error in open rocksdb to " + host + ":" + port + " " + e); throw e; } } return rocksClient.get(); }
@Override protected <T> T doRefer(Class<T> type, URL url) throws RpcException { FramedClientConnector connector = new FramedClientConnector(HostAndPort.fromParts(url.getHost(), url.getPort())); try { ThriftClientManager clientManager = new ThriftClientManager(); T ref = clientManager.createClient(connector, type).get(); return ref; } catch (Exception e) { throw new RpcException( "Fail to create remoting client for service(" + url + "): " + e.getMessage(), e ); } } }
private <T> ListenableFuture<T> createUnframedClient( ThriftClientManager clientManager, Class<T> clientType, int servicePort) throws Exception { return clientManager.createClient( new UnframedClientConnector(HostAndPort.fromParts("localhost", servicePort)), clientType); }
public DelayedMapAsyncProxyHandler(ThriftClientManager clientManager, ThriftServer targetServer) throws ExecutionException, InterruptedException { FramedClientConnector connector = new FramedClientConnector(HostAndPort.fromParts("localhost", targetServer.getPort())); asyncClient = clientManager.createClient(connector, DelayedMap.AsyncClient.class).get(); }
/** * Try to establish new connection to JobProgressTracker */ private void resetConnection() throws ExecutionException, InterruptedException { clientManager = new ThriftClientManager( new ThriftCodecManager(new ThriftCodec[0]), new NiftyClient( new NettyClientConfigBuilder().setWorkerThreadCount(2).build()), ImmutableSet.<ThriftClientEventHandler>of()); FramedClientConnector connector = new FramedClientConnector(new InetSocketAddress( ClientThriftServer.CLIENT_THRIFT_SERVER_HOST.get(conf), ClientThriftServer.CLIENT_THRIFT_SERVER_PORT.get(conf))); jobProgressTracker = clientManager.createClient(connector, JobProgressTracker.class).get(); }
private com.facebook.swift.service.ResultCode logSwift(int port, List<com.facebook.swift.service.LogEntry> entries) throws Exception { try ( ThriftClientManager clientManager = new ThriftClientManager(); Scribe scribe = clientManager.createClient( new FramedClientConnector(fromParts("localhost", port)), Scribe.class).get() ) { return scribe.log(entries); } }
private ListenableFuture<? extends ClientInterface> createClient(ThriftClientManager clientManager) throws TTransportException, InterruptedException, ExecutionException { HostAndPort address = HostAndPort.fromParts(serverConfig.getBindAddress(), server.getPort()); return clientManager.createClient(new FramedClientConnector(address), clientClass); }
private com.facebook.swift.service.ResultCode logSwift(int port, List<com.facebook.swift.service.LogEntry> entries) throws Exception { NettyClientConfig nettyClientConfig = NettyClientConfig.newBuilder() .setSSLClientConfiguration( new SslClientConfiguration.Builder() .caFile(new File(getClass().getResource("/rsa.crt").getFile())) .build()).build(); NiftyClient niftyClient = new NiftyClient(nettyClientConfig); try ( ThriftClientManager clientManager = new ThriftClientManager(new ThriftCodecManager(), niftyClient, ImmutableSet.of()); Scribe scribe = clientManager.createClient( new FramedClientConnector(fromParts("localhost", port)), Scribe.class).get() ) { return scribe.log(entries); } }
@Test public void testPumaSwiftException() throws Exception { PumaReadServer puma = new PumaReadServer(); ReadSemanticException exception = new ReadSemanticException("my exception"); puma.setException(exception); NiftyProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), puma); try ( ThriftServer server = new ThriftServer(processor).start(); ThriftClientManager clientManager = new ThriftClientManager(); PumaReadService pumaClient = clientManager.createClient( new FramedClientConnector(HostAndPort.fromParts("localhost", server.getPort())), PumaReadService.class).get() ) { pumaClient.getResultTimeString(PUMA_REQUEST); fail("Expected ReadSemanticException"); } catch (ReadSemanticException e) { assertEquals(e, exception); } }
@Test public void testPumaSwift() throws Exception { // create server and start PumaReadServer puma = new PumaReadServer(); ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), ImmutableList.<ThriftEventHandler>of(), puma); // create server and client try ( ThriftServer server = new ThriftServer(processor).start(); ThriftClientManager clientManager = new ThriftClientManager(); PumaReadService pumaClient = clientManager.createClient( new FramedClientConnector(fromParts("localhost", server.getPort())), PumaReadService.class).get() ) { // invoke puma List<ReadResultQueryInfoTimeString> results = pumaClient.getResultTimeString(PUMA_REQUEST); verifyPumaResults(results); } }