Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/UNC-Libraries/Carolina-Di…
- Loading branch information
Showing
7 changed files
with
133 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../src/main/java/edu/unc/lib/dl/httpclient/ConnectionInterruptedHttpMethodRetryHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package edu.unc.lib.dl.httpclient; | ||
|
||
import java.io.IOException; | ||
import java.net.SocketException; | ||
|
||
import org.apache.commons.httpclient.HttpMethod; | ||
import org.apache.commons.httpclient.HttpMethodRetryHandler; | ||
import org.apache.commons.httpclient.NoHttpResponseException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ConnectionInterruptedHttpMethodRetryHandler implements HttpMethodRetryHandler { | ||
private static final Logger log = LoggerFactory.getLogger(ConnectionInterruptedHttpMethodRetryHandler.class); | ||
|
||
private int retries = 5; | ||
private long retryDelay = 0; | ||
|
||
public ConnectionInterruptedHttpMethodRetryHandler(int retries, long retryDelay) { | ||
super(); | ||
this.retries = retries; | ||
this.retryDelay = retryDelay; | ||
} | ||
|
||
@Override | ||
public boolean retryMethod(final HttpMethod method, final IOException e, int executionCount) { | ||
if (executionCount >= retries) { | ||
return false; | ||
} | ||
if (e instanceof NoHttpResponseException || e instanceof SocketException) { | ||
log.warn("Connection interrupted, retrying connection to {}", method.getPath()); | ||
if (retryDelay > 0) { | ||
try { | ||
Thread.sleep(retryDelay); | ||
} catch (InterruptedException e1) { | ||
log.warn("Interrupted while waiting to retry connect"); | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |