diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java index 1f22240..c83acca 100644 --- a/src/main/java/org/ice4j/ice/Agent.java +++ b/src/main/java/org/ice4j/ice/Agent.java @@ -422,6 +422,28 @@ public class Agent return component; } + /** + * Initializes a new {@link CandidatePair} instance from a + * {@link LocalCandidate} and a {@link RemoteCandidate}. The method + * represents a {@code CandidatePair} factory and is preferable to + * explicitly calling the {@code CandidatePair} constructor because it + * allows this {@code Agent} to easily track the initialization of its + * {@code CandidatePair}s. + * + * @param local the {@code LocalCandidate} to initialize the new instance + * with + * @param remote the {@code RemoteCandidate} to initialize the new instance + * with + * @return a new {@code CandidatePair} instance initializes with + * {@code local} and {@code remote} + */ + protected CandidatePair createCandidatePair( + LocalCandidate local, + RemoteCandidate remote) + { + return new CandidatePair(local, remote); + } + /** * Uses all CandidateHarvesters currently registered with this * Agent to obtain whatever addresses they can discover. @@ -1445,7 +1467,7 @@ public class Agent ufrag); CandidatePair triggeredPair - = new CandidatePair(localCandidate, remoteCandidate); + = createCandidatePair(localCandidate, remoteCandidate); logger.fine("set use-candidate " + useCandidate + " for pair " + triggeredPair.toShortString()); diff --git a/src/main/java/org/ice4j/ice/Component.java b/src/main/java/org/ice4j/ice/Component.java index 3b860b2..64708a3 100644 --- a/src/main/java/org/ice4j/ice/Component.java +++ b/src/main/java/org/ice4j/ice/Component.java @@ -289,7 +289,7 @@ public class Component */ public void updateRemoteCandidates() { - List checkList = null; + List checkList; List newRemoteCandidates; synchronized(remoteUpdateCandidates) @@ -342,7 +342,9 @@ public class Component */ CandidatePair pair - = new CandidatePair(localCnd, remoteCnd); + = getParentStream() + .getParentAgent() + .createCandidatePair(localCnd, remoteCnd); logger.info("new Pair added: " + pair.toShortString()); checkList.add(pair); } diff --git a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java index 7561ac2..e5895bb 100644 --- a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java @@ -575,7 +575,9 @@ class ConnectivityCheckClient // by a STUN connectivity check. CandidatePair validPair = (existingPair == null) - ? new CandidatePair(validLocalCandidate, validRemoteCandidate) + ? parentAgent.createCandidatePair( + validLocalCandidate, + validRemoteCandidate) : existingPair; // we synchronize here because the same pair object can be processed (in diff --git a/src/main/java/org/ice4j/ice/IceMediaStream.java b/src/main/java/org/ice4j/ice/IceMediaStream.java index 6768e81..548601a 100644 --- a/src/main/java/org/ice4j/ice/IceMediaStream.java +++ b/src/main/java/org/ice4j/ice/IceMediaStream.java @@ -394,8 +394,9 @@ public class IceMediaStream if(localCnd.canReach(remoteCnd) && remoteCnd.getTransportAddress().getPort() != 0) { - CandidatePair pair = new CandidatePair(localCnd, - remoteCnd); + CandidatePair pair + = getParentAgent() + .createCandidatePair(localCnd, remoteCnd); checkList.add(pair); } }