[
https://issues.apache.org/jira/browse/HTTPCLIENT-898?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12788684#action_12788684
]
Glyn Davies commented on HTTPCLIENT-898:
----------------------------------------
Hi Oleg,
I don't know if this is of use, but is the logic I am using at the moment,
which is an extension of the existing DefaultMultihomePlainSocketFactory
Essentially, this shares the set timeout between the available 'A' records, and
allows iteration through those.
List<InetAddress> addresses = new ArrayList<InetAddress>(inetadrs.length);
addresses.addAll(Arrays.asList(inetadrs));
Collections.shuffle(addresses);
IOException lastEx = null;
int individualTimeout = timeout / addresses.size();
for (int i=0;i<addresses.size();i++) {
InetAddress remoteAddress = addresses.get(i);
try {
wireLog.debug("Attempting to connect to
"+remoteAddress+":"+port+" with timeout value of "+individualTimeout);
sock.connect(new InetSocketAddress(remoteAddress, port),
individualTimeout);
wireLog.debug("RETURNING SOCKET - "+sock.toString());
return sock;
} catch (SocketTimeoutException ex) {
// If the last socket on the list, then throw a timeout
exception
if (i == addresses.size()-1)
{
wireLog.warn("Connect to " + remoteAddress + " timed out.
Throwing timeout exception.");
throw new ConnectTimeoutException("Connect to " +
remoteAddress + " timed out");
}
else
{
wireLog.warn("Connect to " + remoteAddress + " timed out.
Trying next in the list.");
// should we close the old socket?!
sock = new Socket();
}
} catch (IOException ex) {
// create new socket
// should we close the old socket?!
sock = new Socket();
wireLog.warn("Connect to " + remoteAddress + " caused
exception. Trying next in the list.", ex);
// keep the last exception and retry
lastEx = ex;
}
}
> Improve multihome support
> -------------------------
>
> Key: HTTPCLIENT-898
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-898
> Project: HttpComponents HttpClient
> Issue Type: Improvement
> Components: HttpConn
> Affects Versions: 4.0 Final, 4.0.1, 4.1 Alpha1
> Reporter: Oleg Kalnichevski
> Fix For: 4.1 Alpha2
>
>
> MultihomePlainSocketFactory is basically broken and should be deprecated.
> Multihome logic needs to be moved to the DefaultClientConnectionOperator
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]