Java Code Examples for org.apache.thrift.transport.TTransport#open()
The following examples show how to use
org.apache.thrift.transport.TTransport#open() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiServiceClient.java From ThriftBook with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws TException { TTransport trans = new TFramedTransport(new TSocket("localhost", 9090)); TProtocol proto = new TJSONProtocol(trans); TMultiplexedProtocol proto_msg = new TMultiplexedProtocol(proto, "Message"); Message.Client client_msg = new Message.Client(proto_msg); TMultiplexedProtocol proto_time = new TMultiplexedProtocol(proto, "ServerTime"); ServerTime.Client client_time = new ServerTime.Client(proto_time); trans.open(); String line; do { System.out.println("Message from server: " + client_msg.motd()); System.out.println("Time at server: " + client_time.time_at_server((short)-1)); System.out.println("Enter to continue, 'q' to quit: "); line = System.console().readLine(); } while (0 != line.compareToIgnoreCase("q")); }
Example 2
Source File: ThriftTest.java From java-specialagent with Apache License 2.0 | 6 votes |
@Test public void test(final MockTracer tracer) throws Exception { startNewThreadPoolServer(); final TTransport transport = new TSocket("localhost", port); transport.open(); final TProtocol protocol = new TBinaryProtocol(transport); final CustomService.Client client = new CustomService.Client(protocol); assertEquals("Say Good bye World", client.say("Good bye", "World")); await().atMost(5, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2)); final List<MockSpan> mockSpans = tracer.finishedSpans(); assertEquals(2, mockSpans.size()); assertTrue(mockSpans.get(0).parentId() != 0 || mockSpans.get(1).parentId() != 0); assertNull(tracer.activeSpan()); }
Example 3
Source File: rpcClient.java From leaf-snowflake with Apache License 2.0 | 6 votes |
public static void startClient2(String ip ,int port ,int timeout) throws Exception { TTransport transport = new TFramedTransport(new TSocket(ip,port,timeout)); TProtocol protocol = new TBinaryProtocol(transport); leafrpc.Client client = new leafrpc.Client(protocol); transport.open(); for(int i = 0; i< 1000000; i++) { client.getID(""); if (i % 100000 == 0) { System.out.println(Thread.currentThread().getName() + " " + client.getID("")); } //ai.incrementAndGet(); } transport.close(); }
Example 4
Source File: AbstractTransportPool.java From jigsaw-payment with Apache License 2.0 | 6 votes |
@Override public TTransport create(ServiceInstance<RpcPayload> instance) throws Exception { TTransport transport = this.createNativeTransport(instance); try { transport.open(); } catch (TException ex) { LOG.warn( "Error when creating new transport on server: " + instance.getAddress() + ":" + instance.getPort(), ex); markError(instance); throw ex; } return new ManagedTransport(transport, instance); }
Example 5
Source File: DefaultThriftConnectionPoolImpl.java From thrift-pool-client with Artistic License 2.0 | 5 votes |
@Override public PooledObject<TTransport> makeObject(ThriftServerInfo info) throws Exception { TTransport transport = transportProvider.apply(info); transport.open(); DefaultPooledObject<TTransport> result = new DefaultPooledObject<>(transport); logger.trace("make new thrift connection:{}", info); return result; }
Example 6
Source File: ScribeTransport.java From incubator-retired-htrace with Apache License 2.0 | 5 votes |
private Scribe.Iface newScribe(String collectorHostname, int collectorPort) throws IOException { TTransport transport = new TFramedTransport( new TSocket(collectorHostname, collectorPort)); try { transport.open(); } catch (TTransportException e) { throw new IOException(e); } TBinaryProtocol.Factory factory = new TBinaryProtocol.Factory(); TProtocol protocol = factory.getProtocol(transport); return new Scribe.Client(protocol); }
Example 7
Source File: EmbeddedCassandraServiceTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Gets a connection to the localhost client * * @return * @throws TTransportException */ private Cassandra.Client getClient() throws TTransportException { TTransport tr = new TFramedTransport(new TSocket("localhost", DatabaseDescriptor.getRpcPort())); TProtocol proto = new TBinaryProtocol(tr); Cassandra.Client client = new Cassandra.Client(proto); tr.open(); return client; }
Example 8
Source File: TFramedTransportFactory.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public TTransport openTransport(String host, int port) throws TTransportException { TSocket socket = new TSocket(host, port); TTransport transport = new TFramedTransport(socket, thriftFramedTransportSizeMb * 1024 * 1024); transport.open(); return transport; }
Example 9
Source File: rpcClient.java From leaf-snowflake with Apache License 2.0 | 5 votes |
public static long getTimestamp(String ip, int port ,int timeout) throws Exception { TTransport transport = new TSocket(ip,port,timeout); TProtocol protocol = new TBinaryProtocol(transport); leafrpc.Client client = new leafrpc.Client(protocol); transport.open(); long timestamp = client.gettimestamp(Utils.currentTimeMs()); transport.close(); return timestamp; }
Example 10
Source File: WordCountSetup.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private static Cassandra.Client createConnection(String host, Integer port) throws TTransportException { TSocket socket = new TSocket(host, port); TTransport trans = new TFramedTransport(socket); trans.open(); TProtocol protocol = new TBinaryProtocol(trans); return new Cassandra.Client(protocol); }
Example 11
Source File: Schema.java From janusgraph_tutorial with Apache License 2.0 | 5 votes |
private void dropOldKeyspace() throws InvalidRequestException, SchemaDisagreementException, TException { TTransport tr = new TFramedTransport(new TSocket("localhost", 9160)); TProtocol proto = new TBinaryProtocol(tr); Cassandra.Client client = new Cassandra.Client(proto); tr.open(); client.system_drop_keyspace(JANUSGRAPH); LOGGER.info("DROPPED keyspace janusgraph"); tr.close(); }
Example 12
Source File: HiveTables.java From iceberg with Apache License 2.0 | 5 votes |
private ThriftHiveMetastore.Client getClient() { final URI metastoreUri = URI.create(MetastoreConf.getAsString(conf, THRIFT_URIS)); final int socketTimeOut = (int) MetastoreConf.getTimeVar(conf, CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); TTransport transport = new TSocket(metastoreUri.getHost(), metastoreUri.getPort(), socketTimeOut); try { transport.open(); } catch (TTransportException e) { throw new RuntimeException("failed to open socket for " + metastoreUri + " with timeoutMillis " + socketTimeOut); } return new ThriftHiveMetastore.Client(new TBinaryProtocol(transport)); }
Example 13
Source File: SimpleClient.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TException { TTransport trans = new TSocket("localhost", 9090); TProtocol proto = new TBinaryProtocol(trans); SocialLookup.Iface client = new SocialLookup.Client(proto); trans.open(); System.out.println("Number 1 site: " + client.GetSiteByRank(1)); System.out.println("Twitter rank : " + client.GetSiteRankByName("Twitter")); trans.close(); }
Example 14
Source File: ThriftClient.java From deep-spark with Apache License 2.0 | 5 votes |
/** * Returns a new client for the specified host, setting the specified keyspace. * * @param host the Cassandra host address. * @param port the Cassandra host RPC port. * @param keyspace the name of the Cassandra keyspace to set. * @return a new client for the specified host, setting the specified keyspace. * @throws TException if there is any problem with the {@code set_keyspace} call. */ public static ThriftClient build(String host, int port, String keyspace) throws TException { TTransport transport = new TFramedTransport(new TSocket(host, port)); TProtocol protocol = new TBinaryProtocol(transport); ThriftClient client = new ThriftClient(protocol); transport.open(); if (keyspace != null) { client.set_keyspace(keyspace); } return client; }
Example 15
Source File: FactoryClient.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TException { TTransport trans = new TFramedTransport(new TSocket("localhost", 9090)); TProtocol proto = new TJSONProtocol(trans); Message.Iface client = new Message.Client(proto); trans.open(); String line; do { System.out.println("Message from server: " + client.motd()); System.out.println("Enter to continue, 'q' to quit: "); line = System.console().readLine(); } while (0 != line.compareToIgnoreCase("q")); }
Example 16
Source File: SimpleTransportPlugin.java From jstorm with Apache License 2.0 | 5 votes |
/** * Connect to the specified server via framed transport * * @param transport The underlying Thrift transport. * @param serverHost unused. * @param asUser unused. */ @Override public TTransport connect(TTransport transport, String serverHost, String asUser) throws TTransportException { int maxBufferSize = type.getMaxBufferSize(storm_conf); // create a framed transport TTransport conn = new TFramedTransport(transport, maxBufferSize); // connect conn.open(); LOG.debug("Simple client transport has been established"); return conn; }
Example 17
Source File: ThriftTest.java From java-specialagent with Apache License 2.0 | 5 votes |
@Test public void withError() throws Exception { TestUtil.setGlobalTracer(tracer); startNewThreadPoolServer(); final TTransport transport = new TSocket("localhost", port); transport.open(); final TProtocol protocol = new TBinaryProtocol(transport); CustomService.Client client = new CustomService.Client(protocol); try { assertEquals("Say Good bye", client.withError()); fail(); } catch (final Exception ignore) { } await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2)); final List<MockSpan> mockSpans = tracer.finishedSpans(); assertEquals(2, mockSpans.size()); assertTrue(mockSpans.get(0).parentId() != 0 || mockSpans.get(1).parentId() != 0); assertNull(tracer.activeSpan()); verify(tracer, times(2)).buildSpan(anyString()); verify(tracer, times(1)).inject(any(SpanContext.class), any(Format.class), any()); }
Example 18
Source File: HealthCheck.java From suro with Apache License 2.0 | 5 votes |
private SuroServer.Client getClient(String host, int port, int timeout) throws SocketException, TTransportException { TSocket socket = new TSocket(host, port, timeout); socket.getSocket().setTcpNoDelay(true); socket.getSocket().setKeepAlive(true); socket.getSocket().setSoLinger(true, 0); TTransport transport = new TFramedTransport(socket); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); return new SuroServer.Client(protocol); }
Example 19
Source File: RemoteShaderDispatcher.java From graphicsfuzz with Apache License 2.0 | 5 votes |
private Iface getFuzzerServiceManagerProxy(CloseableHttpClient httpClient) throws TTransportException { TTransport transport = new THttpClient(url, httpClient); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); return new FuzzerServiceManager.Client( protocol); }
Example 20
Source File: ThriftTest.java From java-specialagent with Apache License 2.0 | 4 votes |
@Test public void oneWay() throws Exception { TestUtil.setGlobalTracer(tracer); startNewThreadPoolServer(); final TTransport transport = new TSocket("localhost", port); transport.open(); final TProtocol protocol = new TBinaryProtocol(transport); CustomService.Client client = new CustomService.Client(protocol); client.oneWay(); await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2)); final List<MockSpan> mockSpans = tracer.finishedSpans(); assertEquals(2, mockSpans.size()); assertTrue(mockSpans.get(0).parentId() != 0 || mockSpans.get(1).parentId() != 0); verify(tracer, times(2)).buildSpan(anyString()); verify(tracer, times(1)).inject(any(SpanContext.class), any(Format.class), any()); }