Java Code Examples for com.alipay.remoting.Url#setConnectTimeout()
The following examples show how to use
com.alipay.remoting.Url#setConnectTimeout() .
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: BoltClientTransport.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * For convert provider to bolt url. * * @param transportConfig ClientTransportConfig * @param providerInfo ProviderInfo * @return Bolt Url */ protected Url convertProviderToUrl(ClientTransportConfig transportConfig, ProviderInfo providerInfo) { // Url的第一个参数,如果不用事件的话,其实无所谓 Url boltUrl = new Url(providerInfo.toString(), providerInfo.getHost(), providerInfo.getPort()); boltUrl.setConnectTimeout(transportConfig.getConnectTimeout()); // 默认初始化connNum个长连接,为了slb和vip的情况 final int connectionNum = transportConfig.getConnectionNum(); if (connectionNum > 0) { boltUrl.setConnNum(connectionNum); } else { boltUrl.setConnNum(1); } boltUrl.setConnWarmup(false); // true的话 if (RpcConstants.PROTOCOL_TYPE_BOLT.equals(providerInfo.getProtocolType())) { boltUrl.setProtocol(RemotingConstants.PROTOCOL_BOLT); } else { boltUrl.setProtocol(RemotingConstants.PROTOCOL_TR); } return boltUrl; }
Example 2
Source File: ReuseBoltClientConnectionManagerTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
private Url buildUrl(ClientTransportConfig clientTransportConfig) { ProviderInfo providerInfo2 = clientTransportConfig.getProviderInfo(); Url url = new Url(providerInfo2.toString(), providerInfo2.getHost(), providerInfo2.getPort()); url.setConnectTimeout(4500); url.setProtocol(RemotingConstants.PROTOCOL_BOLT); url.setConnNum(1); // 默认初始化connNum个长连接 url.setConnWarmup(false); return url; }
Example 3
Source File: RpcAddressParser.java From sofa-bolt with Apache License 2.0 | 4 votes |
/** * @see com.alipay.remoting.RemotingAddressParser#initUrlArgs(Url) */ @Override public void initUrlArgs(Url url) { String connTimeoutStr = url.getProperty(RpcConfigs.CONNECT_TIMEOUT_KEY); int connTimeout = Configs.DEFAULT_CONNECT_TIMEOUT; if (StringUtils.isNotBlank(connTimeoutStr)) { if (StringUtils.isNumeric(connTimeoutStr)) { connTimeout = Integer.parseInt(connTimeoutStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.CONNECT_TIMEOUT_KEY + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setConnectTimeout(connTimeout); String protocolStr = url.getProperty(RpcConfigs.URL_PROTOCOL); byte protocol = RpcProtocol.PROTOCOL_CODE; if (StringUtils.isNotBlank(protocolStr)) { if (StringUtils.isNumeric(protocolStr)) { protocol = Byte.parseByte(protocolStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.URL_PROTOCOL + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setProtocol(protocol); String versionStr = url.getProperty(RpcConfigs.URL_VERSION); byte version = RpcProtocolV2.PROTOCOL_VERSION_1; if (StringUtils.isNotBlank(versionStr)) { if (StringUtils.isNumeric(versionStr)) { version = Byte.parseByte(versionStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.URL_VERSION + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setVersion(version); String connNumStr = url.getProperty(RpcConfigs.CONNECTION_NUM_KEY); int connNum = Configs.DEFAULT_CONN_NUM_PER_URL; if (StringUtils.isNotBlank(connNumStr)) { if (StringUtils.isNumeric(connNumStr)) { connNum = Integer.parseInt(connNumStr); } else { throw new IllegalArgumentException( "Url args illegal value of key [" + RpcConfigs.CONNECTION_NUM_KEY + "] must be positive integer! The origin url is [" + url.getOriginUrl() + "]"); } } url.setConnNum(connNum); String connWarmupStr = url.getProperty(RpcConfigs.CONNECTION_WARMUP_KEY); boolean connWarmup = false; if (StringUtils.isNotBlank(connWarmupStr)) { connWarmup = Boolean.parseBoolean(connWarmupStr); } url.setConnWarmup(connWarmup); }
Example 4
Source File: RpcClient.java From sofa-bolt with Apache License 2.0 | 4 votes |
@Override public Connection getConnection(Url url, int connectTimeout) throws RemotingException, InterruptedException { url.setConnectTimeout(connectTimeout); return this.connectionManager.getAndCreateIfAbsent(url); }