diff --git a/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java
index d2f748c..4f25851 100644
--- a/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java
+++ b/src/main/java/org/ice4j/ice/harvest/AwsCandidateHarvester.java
@@ -18,11 +18,9 @@
package org.ice4j.ice.harvest;
import org.ice4j.*;
-import org.ice4j.ice.*;
import java.io.*;
import java.net.*;
-import java.util.*;
import java.util.logging.*;
/**
@@ -74,6 +72,11 @@ public class AwsCandidateHarvester
*/
private static TransportAddress face;
+ /**
+ * Whether we have already checked and found the mapping addresses.
+ */
+ private static boolean addressChecked = false;
+
/**
* Creates an AWS harvester. The actual addresses wil be retrieved later,
* during the first harvest.
@@ -83,39 +86,17 @@ public class AwsCandidateHarvester
super(null, null);
}
- /**
- * Maps all candidates to this harvester's mask and adds them to
- * component.
- *
- * @param component the {@link Component} that we'd like to map candidates
- * to.
- * @return the LocalCandidates gathered by this
- * CandidateHarvester or null if no mask is specified.
- */
- public Collection harvest(Component component)
- {
- if (mask == null || face == null)
- {
- if(!obtainEC2Addresses())
- return null;
- }
-
- return super.harvest(component);
- }
-
/**
* Sends HTTP GET queries to
* http://169.254.169.254/latest/meta-data/local-ipv4 and
* http://169.254.169.254/latest/meta-data/public-ipv4 to learn the
* private (face) and public (mask) addresses of this EC2 instance.
- *
- * @return true if we managed to obtain addresses or someone else
- * had already achieved that before us, false otherwise.
*/
- private synchronized boolean obtainEC2Addresses()
+ private static synchronized void obtainEC2Addresses()
{
- if(mask != null && face != null)
- return true;
+ if (addressChecked)
+ return;
+ addressChecked = true;
String localIPStr = null;
String publicIPStr = null;
@@ -142,11 +123,7 @@ public class AwsCandidateHarvester
+ "for the following reason: ", exc);
logger.info("String for local IP: " + localIPStr);
logger.info("String for public IP: " + publicIPStr);
-
- return false;
}
-
- return true;
}
/**
diff --git a/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java
index 105287a..62e7217 100644
--- a/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java
+++ b/src/main/java/org/ice4j/ice/harvest/StunMappingCandidateHarvester.java
@@ -20,7 +20,6 @@ package org.ice4j.ice.harvest;
import org.ice4j.*;
import org.ice4j.ice.*;
-import java.util.*;
import java.util.logging.*;
/**
@@ -81,38 +80,16 @@ public class StunMappingCandidateHarvester
super(null, null);
}
- /**
- * Maps all candidates to this harvester's mask and adds them to
- * component.
- *
- * @param component the {@link Component} that we'd like to map candidates
- * to.
- * @return the LocalCandidates gathered by this
- * CandidateHarvester or null if no mask is specified.
- */
- public Collection harvest(Component component)
- {
- if (mask == null || face == null)
- {
- if(!obtainAddresses())
- return null;
- }
-
- return super.harvest(component);
- }
-
/**
* Uses the pre-configured list of stun servers to discover our public
* address. Uses the first successful one and ignore the rest.
* Learn the private (face) and public (mask) addresses of this instance.
- *
- * @return true if we managed to obtain addresses or someone else
- * had already achieved that before us, false otherwise.
*/
- private synchronized boolean obtainAddresses()
+ private static synchronized void obtainAddresses()
{
- if(mask != null && face != null)
- return true;
+ if (addressChecked)
+ return;
+ addressChecked = true;
try
{
@@ -140,43 +117,28 @@ public class StunMappingCandidateHarvester
TransportAddress addr = iceMediaStream
.getComponent(Component.RTP).getDefaultCandidate()
.getTransportAddress();
- StunMappingCandidateHarvester.mask = addr;
+ mask = addr;
Candidate> candidate =
iceMediaStream.getComponents().get(0).getDefaultCandidate();
- StunMappingCandidateHarvester.face = candidate.getHostAddress();
+ face = candidate.getHostAddress();
agent.free();
- if(StunMappingCandidateHarvester.mask != null
- && StunMappingCandidateHarvester.face != null)
+ if (mask != null && face != null)
break;
}
logger.info("Detected through stun local IP: " + face);
logger.info("Detected through stun public IP: " + mask);
- addressChecked = true;
}
catch (Exception exc)
{
//whatever happens, we just log and fail
logger.log(Level.INFO, "We failed to obtain addresses "
+ "for the following reason: ", exc);
-
- return false;
}
-
- return true;
- }
-
- /**
- * Whether we had already checked and succeeded finding address.
- * @return whether we had already checked and succeeded finding address.
- */
- private boolean isAddressChecked()
- {
- return addressChecked;
}
/**
@@ -185,7 +147,7 @@ public class StunMappingCandidateHarvester
*/
public TransportAddress getMask()
{
- if (!isAddressChecked())
+ if (mask == null)
{
obtainAddresses();
}
@@ -198,7 +160,7 @@ public class StunMappingCandidateHarvester
*/
public TransportAddress getFace()
{
- if (!isAddressChecked())
+ if (face == null)
{
obtainAddresses();
}