List of usage examples for org.apache.thrift.transport TTransport open
public abstract void open() throws TTransportException;
From source file:appSetup.java
License:Apache License
private static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws TTransportException { TSocket socket = new TSocket(host, port); TTransport trans = framed ? new TFramedTransport(socket) : socket; trans.open(); TProtocol protocol = new TBinaryProtocol(trans); return new Cassandra.Client(protocol); }
From source file:JavaClient2.java
License:Apache License
public static void main(String[] args) { // 1st args is "simple", 2nd args is server address if (args.length != 2 || !args[0].contains("simple")) { System.out.println("Please enter 'simple' "); System.exit(0);//from w w w. j a va2s . co m } try { TTransport transport; transport = new TSocket(args[1], 14264); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); Myservice.Client client = new Myservice.Client(protocol); perform(client); transport.close(); } catch (TException x) { x.printStackTrace(); } }
From source file:FilesystemClient.java
public static void main(String[] args) { try {/*www . j a v a 2s . c o m*/ TTransport transport; transport = new TSocket("localhost", 9090); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); FilesystemService.Client client = new FilesystemService.Client(protocol); perform(client); transport.close(); } catch (TException x) { x.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:JavaClient.java
License:Apache License
public static void main(String[] args) { if (args.length != 1) { System.out.println("Please enter 'simple' or 'secure'"); System.exit(0);/* ww w . ja v a 2 s .co m*/ } try { TTransport transport; if (args[0].contains("simple")) { transport = new TSocket("localhost", 9090); transport.open(); } else { /* * Similar to the server, you can use the parameters to setup client parameters or * use the default settings. On the client side, you will need a TrustStore which * contains the trusted certificate along with the public key. * For this example it's a self-signed cert. */ TSSLTransportParameters params = new TSSLTransportParameters(); params.setTrustStore("../../lib/java/test/.truststore", "thrift", "SunX509", "JKS"); /* * Get a client transport instead of a server transport. The connection is opened on * invocation of the factory method, no need to specifically call open() */ transport = TSSLTransportFactory.getClientSocket("localhost", 9091, 0, params); } TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); perform(client); transport.close(); } catch (TException x) { x.printStackTrace(); } }
From source file:StreamerClientTest.java
License:Open Source License
public static void main(String[] args) throws Exception { TTransport transport; transport = new TSocket("localhost", 7911); TProtocol protocol = new TBinaryProtocol(transport); Streamer.Client client = new Streamer.Client(protocol); transport.open(); String accessKey = "defaultAccessKey"; String secretKey = "defaultSecretKey"; int count = 100; Random rnd = new Random(); for (int i = 0; i < count; i++) { Tuple tuple = new Tuple(); String id = UUID.randomUUID().toString(); tuple.setId(id);/*from w w w.ja va2s.c o m*/ String topic = "testTopic01"; tuple.setTopic(topic); String correlationId = UUID.randomUUID().toString(); tuple.setCorrelationId(correlationId); Map<String, String> headers = new HashMap<String, String>(); headers.put("category", "test"); tuple.setHeaders(headers); Map<String, String> payload = new HashMap<String, String>(); payload.put("id", 6900 + i + ""); String name = "Aditya" + rnd.nextInt(); payload.put("name", name); tuple.setPayload(payload); client.tellTuple(accessKey, secretKey, tuple); System.out.println("Sent: " + name); } transport.close(); System.out.println("Done!"); System.exit(0); }
From source file:MapDExample.java
License:Apache License
public static MapD.Client get_client(String host_or_uri, int port, boolean http) { THttpClient httpTransport;/*from w ww .j a v a 2s . c o m*/ TTransport transport; TBinaryProtocol protocol; TJSONProtocol jsonProtocol; TSocket socket; MapD.Client client; try { if (http) { httpTransport = new THttpClient(host_or_uri); jsonProtocol = new TJSONProtocol(httpTransport); client = new MapD.Client(jsonProtocol); httpTransport.open(); return client; } else { transport = new TSocket(host_or_uri, port); protocol = new TBinaryProtocol(transport); client = new MapD.Client(protocol); transport.open(); return client; } } catch (TException x) { x.printStackTrace(); } return null; }
From source file:alluxio.Configuration.java
License:Apache License
/** * Loads cluster default values from the meta master. * * @param address the master address/*from w w w.jav a2 s .c o m*/ */ public static void loadClusterDefault(InetSocketAddress address) throws AlluxioStatusException { if (!Configuration.getBoolean(PropertyKey.USER_CONF_CLUSTER_DEFAULT_ENABLED) || CLUSTER_DEFAULT_LOADED.get()) { return; } synchronized (Configuration.class) { if (CLUSTER_DEFAULT_LOADED.get()) { return; } LOG.info("Alluxio client (version {}) is trying to bootstrap-connect with {}", RuntimeConstants.VERSION, address); // A plain socket transport to bootstrap TSocket socket = ThriftUtils.createThriftSocket(address); TTransport bootstrapTransport = new BootstrapClientTransport(socket); TProtocol protocol = ThriftUtils.createThriftProtocol(bootstrapTransport, Constants.META_MASTER_CLIENT_SERVICE_NAME); List<ConfigProperty> clusterConfig; try { bootstrapTransport.open(); // We didn't use RetryHandlingMetaMasterClient because it inherits AbstractClient, // and AbstractClient uses Configuration.loadClusterDefault inside. MetaMasterClientService.Client client = new MetaMasterClientService.Client(protocol); // The credential configuration properties use displayValue clusterConfig = client.getConfiguration(new GetConfigurationTOptions().setRawValue(true)) .getConfigList().stream().map(ConfigProperty::fromThrift).collect(Collectors.toList()); } catch (TException e) { throw new UnavailableException(String.format( "Failed to handshake with master %s to load cluster default configuration values", address), e); } finally { bootstrapTransport.close(); } // merge conf returned by master as the cluster default into Configuration Properties clusterProps = new Properties(); for (ConfigProperty property : clusterConfig) { String name = property.getName(); // TODO(binfan): support propagating unsetting properties from master if (PropertyKey.isValid(name) && property.getValue() != null) { PropertyKey key = PropertyKey.fromString(name); if (!key.getScope().contains(Scope.CLIENT)) { // Only propagate client properties. continue; } String value = property.getValue(); clusterProps.put(key, value); LOG.debug("Loading cluster default: {} ({}) -> {}", key, key.getScope(), value); } } String clientVersion = Configuration.get(PropertyKey.VERSION); String clusterVersion = clusterProps.get(PropertyKey.VERSION).toString(); if (!clientVersion.equals(clusterVersion)) { LOG.warn("Alluxio client version ({}) does not match Alluxio cluster version ({})", clientVersion, clusterVersion); clusterProps.remove(PropertyKey.VERSION); } Configuration.merge(clusterProps, Source.CLUSTER_DEFAULT); Configuration.validate(); // This needs to be the last CLUSTER_DEFAULT_LOADED.set(true); LOG.info("Alluxio client has bootstrap-connected with {}", address); } }
From source file:alluxio.network.connection.ThriftClientPool.java
License:Apache License
/** * Creates a thrift client instance.//from w ww . j a v a 2 s. c o m * * @return the thrift client created * @throws IOException if it fails to create a thrift client */ @Override protected T createNewResource() throws IOException { TTransport transport = mTransportProvider.getClientTransport(mAddress); TProtocol binaryProtocol = new TBinaryProtocol(transport); T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName)); RetryPolicy retry = new ExponentialBackoffRetry(CONNECTION_OPEN_RETRY_BASE_SLEEP_MS, Constants.SECOND_MS, CONNECTION_OPEN_RETRY_MAX); while (true) { try { if (!transport.isOpen()) { transport.open(); } if (transport.isOpen()) { checkVersion(client); } } catch (TTransportException e) { LOG.error("Failed to connect (" + retry.getRetryCount() + ") to " + getServiceNameForLogging() + " @ " + mAddress, e); if (e.getCause() instanceof java.net.SocketTimeoutException) { // Do not retry if socket timeout. String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode."; throw new IOException(message, e); } if (!retry.attemptRetry()) { throw new IOException(e); } } break; } LOG.info("Created a new thrift client {}", client.toString()); return client; }
From source file:alluxio.security.authentication.AuthenticationUtilsTest.java
License:Apache License
/** * In NOSASL mode, the TTransport used should be the same as Alluxio original code. * * @throws Exception thrown when the server cannot be started *///from ww w .j av a 2s . c o m @Test public void nosaslAuthenticationTest() throws Exception { mConfiguration.set(Constants.SECURITY_AUTHENTICATION_TYPE, "NOSASL"); // start server startServerThread(); // create client and connect to server TTransport client = AuthenticationUtils.getClientTransport(mConfiguration, mServerAddress); client.open(); Assert.assertTrue(client.isOpen()); // clean up client.close(); mServer.stop(); }
From source file:alluxio.security.authentication.AuthenticationUtilsTest.java
License:Apache License
/** * In SIMPLE mode, the TTransport mechanism is PLAIN. When server authenticate the connected * client user, it use {@link SimpleAuthenticationProvider}. * * @throws Exception thrown when the server cannot be started or the retrieval of the plain client * transport fails/* www. j av a2 s. c om*/ */ @Test public void simpleAuthenticationTest() throws Exception { mConfiguration.set(Constants.SECURITY_AUTHENTICATION_TYPE, "SIMPLE"); // start server startServerThread(); // when connecting, authentication happens. It is a no-op in Simple mode. TTransport client = PlainSaslUtils.getPlainClientTransport("anyone", "whatever", mClientTSocket); client.open(); Assert.assertTrue(client.isOpen()); // clean up client.close(); mServer.stop(); }