List of usage examples for org.apache.thrift.transport TTransport close
public abstract void close();
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 ww w . j a v a2s . c o 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 {/*w ww. jav a 2s .co 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);// w w w .ja va 2 s . c om } 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();//from www.j a va 2s . co m 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); 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:alluxio.Configuration.java
License:Apache License
/** * Loads cluster default values from the meta master. * * @param address the master address/*from w w w . ja va2s . c om*/ */ 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
/** * A helper function to close thrift clients. * * @param client the thrift client to close * @param <C> the thrift client type *//* w w w .j ava2s . c om*/ public static <C extends AlluxioService.Client> void closeThriftClient(C client) { // Note that the input and output protocol is the same in Alluxio. TTransport transport = client.getOutputProtocol().getTransport(); if (transport.isOpen()) { transport.close(); } }
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 */// w w w . j a v a 2 s.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//from w w w.j a va 2s. c o m */ @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(); }
From source file:alluxio.security.authentication.AuthenticationUtilsTest.java
License:Apache License
/** * In CUSTOM mode, the TTransport mechanism is PLAIN. When server authenticate the connected * client user, it use configured AuthenticationProvider. If the username:password pair matches, a * connection should be built.// w ww .j a va2 s . co m * * @throws Exception thrown when the server cannot be started or the retrieval of the plain client * transport fails */ @Test public void customAuthenticationExactNamePasswordMatchTest() throws Exception { mConfiguration.set(Constants.SECURITY_AUTHENTICATION_TYPE, "CUSTOM"); mConfiguration.set(Constants.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER, ExactlyMatchAuthenticationProvider.class.getName()); // start server startServerThread(); // when connecting, authentication happens. User's name:pwd pair matches and auth pass. TTransport client = PlainSaslUtils.getPlainClientTransport("alluxio", "correct-password", mClientTSocket); client.open(); Assert.assertTrue(client.isOpen()); // clean up client.close(); mServer.stop(); }
From source file:alluxio.security.authentication.TransportProviderTest.java
License:Apache License
/** * In NOSASL mode, the TTransport used should be the same as Alluxio original code. *///from ww w.j a v a 2 s. co m @Test public void nosaslAuthentrication() throws Exception { Configuration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.NOSASL.getAuthName()); mTransportProvider = TransportProvider.Factory.create(); // start server startServerThread(); // create client and connect to server TTransport client = mTransportProvider.getClientTransport(mServerAddress); client.open(); Assert.assertTrue(client.isOpen()); // clean up client.close(); mServer.stop(); }