List of usage examples for org.apache.thrift.transport TFramedTransport TFramedTransport
public TFramedTransport(TTransport transport, int maxLength)
From source file:alluxio.security.authentication.NoSaslTransportProvider.java
License:Apache License
@Override public TTransport getClientTransport(InetSocketAddress serverAddress) { TTransport tTransport = TransportProviderUtils.createThriftSocket(serverAddress, mSocketTimeoutMs); return new TFramedTransport(tTransport, mThriftFrameSizeMax); }
From source file:alluxio.security.authentication.NoSaslTransportProvider.java
License:Apache License
@Override public TTransport getClientTransport(Subject subject, InetSocketAddress serverAddress) { TTransport tTransport = TransportProviderUtils.createThriftSocket(serverAddress, mSocketTimeoutMs); return new TFramedTransport(tTransport, mThriftFrameSizeMax); }
From source file:com.github.odiszapc.casskit.repair.CassandraClientFactory.java
License:Apache License
@Override public ICassandraClient newClient(String host, int port, String ks, int frameSize) throws Exception { TTransport transport = new TFramedTransport(new TSocket(host, port), frameSize); TBinaryProtocol protocol = new TBinaryProtocol(transport, true, true); Cassandra.Client client = new Cassandra.Client(protocol); transport.open();/* w w w . j av a 2 s . c om*/ client.set_keyspace(ks); return new CassandraClient(client, ks); }
From source file:com.miraclelinux.historygluon.CassandraDriver.java
License:Open Source License
@Override public boolean init() { TSocket socket = new TSocket("localhost", DEFALUT_PORT); m_transport = new TFramedTransport(socket, MAX_TRANSPORT_BYTES); TProtocol protocol = new TBinaryProtocol(m_transport); try {// w w w . ja v a 2 s . c o m m_transport.open(); } catch (TTransportException e) { m_log.error(e); e.printStackTrace(); return false; } m_client = new Cassandra.Client(protocol); return true; }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraClientFactory.java
License:Open Source License
public static Cassandra.Client getClientInternal(InetSocketAddress addr, boolean isSsl, int socketTimeoutMillis, int socketQueryTimeoutMillis) throws TTransportException { TSocket tSocket = new TSocket(addr.getHostString(), addr.getPort(), socketTimeoutMillis); tSocket.open();// ww w .j av a 2s. com try { tSocket.getSocket().setKeepAlive(true); tSocket.getSocket().setSoTimeout(socketQueryTimeoutMillis); } catch (SocketException e) { log.error("Couldn't set socket keep alive for {}", addr); } if (isSsl) { boolean success = false; try { SSLSocketFactory factory = sslSocketFactories.getUnchecked(addr); SSLSocket socket = (SSLSocket) factory.createSocket(tSocket.getSocket(), addr.getHostString(), addr.getPort(), true); tSocket = new TSocket(socket); success = true; } catch (IOException e) { throw new TTransportException(e); } finally { if (!success) { tSocket.close(); } } } TTransport tFramedTransport = new TFramedTransport(tSocket, CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES); TProtocol protocol = new TBinaryProtocol(tFramedTransport); Cassandra.Client client = new Cassandra.Client(protocol); return client; }
From source file:io.warp10.continuum.egress.ThriftDirectoryClient.java
License:Apache License
@Override public void cacheChanged() { Sensision.update(SensisionConstants.SENSISION_CLASS_CONTINUUM_DIRECTORY_CLIENT_CACHE_CHANGED, Sensision.EMPTY_LABELS, 1);/*from w w w . ja va 2 s . com*/ synchronized (clientCacheMutex) { // // Clear transportException // transportException.set(false); //System.out.println("in cacheChanged"); // // Rebuild the Client cache // List<ServiceInstance<Map>> instances = serviceCache.getInstances(); // // Allocate new clients // Map<String, Client> newClients = new ConcurrentHashMap<String, DirectoryService.Client>(); Map<String, Integer> newModulus = new ConcurrentHashMap<String, Integer>(); Map<String, Integer> newRemainder = new ConcurrentHashMap<String, Integer>(); Map<String, String> newHosts = new ConcurrentHashMap<String, String>(); Map<String, Integer> newStreamingPorts = new ConcurrentHashMap<String, Integer>(); // // Determine which instances we should retain. // Only the instances which cover the full range of remainders for a given // modulus should be retained // // Set of available remainders per modulus Map<Integer, Set<Integer>> remaindersPerModulus = new HashMap<Integer, Set<Integer>>(); for (ServiceInstance<Map> instance : instances) { int modulus = Integer.parseInt(instance.getPayload().get(Directory.PAYLOAD_MODULUS_KEY).toString()); int remainder = Integer .parseInt(instance.getPayload().get(Directory.PAYLOAD_REMAINDER_KEY).toString()); // Skip invalid modulus/remainder if (modulus <= 0 || remainder >= modulus) { continue; } if (!remaindersPerModulus.containsKey(modulus)) { remaindersPerModulus.put(modulus, new HashSet<Integer>()); } remaindersPerModulus.get(modulus).add(remainder); } // // Only retain the moduli which have a full set of remainders // Set<Integer> validModuli = new HashSet<Integer>(); for (Entry<Integer, Set<Integer>> entry : remaindersPerModulus.entrySet()) { if (entry.getValue().size() == entry.getKey()) { validModuli.add(entry.getKey()); } } for (ServiceInstance<Map> instance : instances) { int modulus = Integer.parseInt(instance.getPayload().get(Directory.PAYLOAD_MODULUS_KEY).toString()); // // Skip instance if it is not associated with a valid modulus // if (!validModuli.contains(modulus)) { continue; } String id = instance.getId(); String host = instance.getAddress(); int port = instance.getPort(); TTransport transport = new TSocket(host, port); try { transport.open(); } catch (TTransportException tte) { // FIXME(hbs): log continue; } if (instance.getPayload().containsKey(Directory.PAYLOAD_THRIFT_MAXFRAMELEN_KEY)) { transport = new TFramedTransport(transport, Integer.parseInt( instance.getPayload().get(Directory.PAYLOAD_THRIFT_MAXFRAMELEN_KEY).toString())); } else { transport = new TFramedTransport(transport); } if (instance.getPayload().containsKey(Directory.PAYLOAD_STREAMING_PORT_KEY)) { newHosts.put(id, instance.getAddress()); newStreamingPorts.put(id, Integer .parseInt(instance.getPayload().get(Directory.PAYLOAD_STREAMING_PORT_KEY).toString())); } DirectoryService.Client client = new DirectoryService.Client(new TCompactProtocol(transport)); newClients.put(id, client); newModulus.put(id, modulus); newRemainder.put(id, Integer.parseInt(instance.getPayload().get(Directory.PAYLOAD_REMAINDER_KEY).toString())); } // // Close current clients and allocate new ones // synchronized (clientCacheMutex) { for (Entry<String, DirectoryService.Client> entry : clientCache.entrySet()) { synchronized (entry.getValue()) { try { entry.getValue().getInputProtocol().getTransport().close(); } catch (Exception e) { } } } clientCache = newClients; modulus = newModulus; remainder = newRemainder; hosts = newHosts; streamingPorts = newStreamingPorts; // // Shut down the current executor // if (null != executor) { ExecutorService oldexecutor = executor; synchronized (executorMutex) { // // Allocate a new executor with 4x as many threads as there are clients // executor = Executors.newCachedThreadPool(); } oldexecutor.shutdown(); } else { synchronized (executorMutex) { executor = Executors.newCachedThreadPool(); } } } } }
From source file:io.warp10.continuum.geo.GeoDirectoryThriftClient.java
License:Apache License
@Override public void cacheChanged() { ////from w w w.j av a 2 s .c om // Rebuild the Client cache // List<ServiceInstance<Map>> instances = serviceCache.getInstances(); // // Allocate new clients // Map<String, Client> newClients = new ConcurrentHashMap<String, GeoDirectoryService.Client>(); Map<String, Integer> newModulus = new ConcurrentHashMap<String, Integer>(); Map<String, Integer> newRemainder = new ConcurrentHashMap<String, Integer>(); Map<String, String> newGeoDirectory = new ConcurrentHashMap<String, String>(); for (ServiceInstance<Map> instance : instances) { String id = instance.getId(); String host = instance.getAddress(); int port = instance.getPort(); TTransport transport = new TSocket(host, port); try { transport.open(); } catch (TTransportException tte) { // FIXME(hbs): log continue; } if (instance.getPayload().containsKey(GeoDirectory.INSTANCE_PAYLOAD_THRIFT_MAXFRAMELEN)) { transport = new TFramedTransport(transport, Integer.parseInt( instance.getPayload().get(GeoDirectory.INSTANCE_PAYLOAD_THRIFT_MAXFRAMELEN).toString())); } else { transport = new TFramedTransport(transport); } GeoDirectoryService.Client client = new GeoDirectoryService.Client(new TCompactProtocol(transport)); newClients.put(id, client); newModulus.put(id, Integer.parseInt(instance.getPayload().get(GeoDirectory.INSTANCE_PAYLOAD_MODULUS).toString())); newRemainder.put(id, Integer .parseInt(instance.getPayload().get(GeoDirectory.INSTANCE_PAYLOAD_REMAINDER).toString())); newGeoDirectory.put(id, instance.getPayload().get(GeoDirectory.INSTANCE_PAYLOAD_GEODIR).toString()); } // // Close current clients and allocate new ones // synchronized (clientCache) { for (Entry<String, GeoDirectoryService.Client> entry : clientCache.entrySet()) { synchronized (entry.getValue()) { entry.getValue().getInputProtocol().getTransport().close(); } } clientCache = newClients; modulus = newModulus; remainder = newRemainder; names = newGeoDirectory; // // Shut down the current executor // if (null != executor) { executor.shutdown(); } // // Allocate a new executor with 4x as many threads as there are clients // executor = Executors.newCachedThreadPool(); } }
From source file:org.apache.cassandra.cli.transport.FramedTransportFactory.java
License:Apache License
public TTransport getTransport(TTransport base) { return new TFramedTransport(base, DEFAULT_MAX_FRAME_SIZE); }
From source file:org.apache.cassandra.thrift.SSLTransportFactory.java
License:Apache License
@Override @SuppressWarnings("resource") public TTransport openTransport(String host, int port) throws Exception { TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters( protocol, cipherSuites);/* w w w.j av a 2 s .c o m*/ params.setTrustStore(truststore, truststorePassword); if (null != keystore) params.setKeyStore(keystore, keystorePassword); TTransport trans = TSSLTransportFactory.getClientSocket(host, port, SOCKET_TIMEOUT, params); return new TFramedTransport(trans, DEFAULT_MAX_FRAME_SIZE); }
From source file:org.apache.cassandra.thrift.TFramedTransportFactory.java
License:Apache License
@SuppressWarnings("resource") 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();//from ww w. jav a2 s . com return transport; }