public TTransport getTransport(HostAndPort location, long milliseconds, ClientContext context) throws TTransportException { return getTransport(new ThriftTransportKey(location, milliseconds, context)); }
public final void precomputeHashCode() { hashCode(); }
private TTransport createNewTransport(ThriftTransportKey cacheKey) throws TTransportException { TTransport transport = ThriftUtil.createClientTransport(cacheKey.getServer(), (int) cacheKey.getTimeout(), cacheKey.getSslParams(), cacheKey.getSaslParams()); log.trace("Creating new connection to connection to {}", cacheKey.getServer()); CachedTTransport tsc = new CachedTTransport(transport, cacheKey); CachedConnection cc = new CachedConnection(tsc); cc.reserve(); try { synchronized (this) { CachedConnections cachedConns = getCache().get(cacheKey); if (cachedConns == null) { cachedConns = new CachedConnections(); getCache().put(cacheKey, cachedConns); } cachedConns.reserved.put(cc.transport, cc); } } catch (TransportPoolShutdownException e) { cc.transport.close(); throw e; } return cc.transport; }
private TTransport getTransport(ThriftTransportKey cacheKey) throws TTransportException { // compute hash code outside of lock, this lowers the time the lock is held cacheKey.precomputeHashCode(); synchronized (this) { // atomically reserve location if it exist in cache CachedConnections ccl = getCache().get(cacheKey); if (ccl == null) { ccl = new CachedConnections(); getCache().put(cacheKey, ccl); } CachedConnection cachedConnection = ccl.reserveAny(); if (cachedConnection != null) { log.trace("Using existing connection to {}", cacheKey.getServer()); return cachedConnection.transport; } } return createNewTransport(cacheKey); }
CachedConnection cachedConnection = getCache().get(ttk).reserveAny(); if (cachedConnection != null) { final String serverAddr = ttk.getServer().toString(); log.trace("Using existing connection to {}", serverAddr); return new Pair<>(serverAddr, cachedConnection.transport); CachedConnection cachedConnection = cachedConns.reserveAny(); if (cachedConnection != null) { final String serverAddr = ttk.getServer().toString(); return new Pair<>(serverAddr, cachedConnection.transport); return new Pair<>(ttk.getServer().toString(), createNewTransport(ttk)); } catch (TTransportException tte) { log.debug("Failed to connect to {}", servers.get(index), tte);
@Override public boolean equals(Object o) { if (!(o instanceof ThriftTransportKey)) return false; ThriftTransportKey ttk = (ThriftTransportKey) o; return server.equals(ttk.server) && timeout == ttk.timeout && (!isSsl() || (ttk.isSsl() && sslParams.equals(ttk.sslParams))) && (!isSasl() || (ttk.isSasl() && saslParams.equals(ttk.saslParams))); }
String strData = new String(data, UTF_8); if (!strData.equals("master")) servers.add(new ThriftTransportKey( new ServerServices(strData).getAddress(Service.TSERV_CLIENT), rpcTimeout, context));