From 969e363bc68fb13e3e62af644802b2c1325b1c69 Mon Sep 17 00:00:00 2001 From: Romanas Sonkinas Date: Fri, 28 Apr 2017 14:46:24 +0100 Subject: [PATCH] Introduce harvesting timeout option --- src/main/java/org/ice4j/StackProperties.java | 6 ++++++ .../ice4j/ice/harvest/CandidateHarvesterSet.java | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/ice4j/StackProperties.java b/src/main/java/org/ice4j/StackProperties.java index da5b11d..7e1b622 100644 --- a/src/main/java/org/ice4j/StackProperties.java +++ b/src/main/java/org/ice4j/StackProperties.java @@ -232,6 +232,12 @@ public class StackProperties public static final String USE_DYNAMIC_HOST_HARVESTER = "org.ice4j.ice.harvest.USE_DYNAMIC_HOST_HARVESTER"; + /** + * Timeout, in seconds, of how long to wait for an individual harvest before timing out + */ + public static final String HARVESTING_TIMEOUT + = "org.ice4j.ice.harvest.HARVESTING_TIMEOUT"; + /** * Returns the String value of the specified property (minus all * encompassing whitespaces)and null in case no property value was mapped diff --git a/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java b/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java index 582f1eb..ebee607 100644 --- a/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java +++ b/src/main/java/org/ice4j/ice/harvest/CandidateHarvesterSet.java @@ -21,6 +21,7 @@ import java.util.*; import java.util.concurrent.*; import java.util.logging.*; +import org.ice4j.*; import org.ice4j.ice.*; /** @@ -197,7 +198,17 @@ public class CandidateHarvesterSet { try { - future.get(); + future.get(StackProperties.getInt(StackProperties.HARVESTING_TIMEOUT, 15), TimeUnit.SECONDS); + break; + } + catch (TimeoutException te) + { + CandidateHarvesterSetElement harvester = task.getKey().getHarvester(); + if (harvester != null) + { + harvester.setEnabled(false); + } + logger.warning("timed out while harvesting from " + harvester); break; } catch (CancellationException ce)