Implements a default NOMINATE_FIRST_VALID nomination strategy.
This commit is contained in:
parent
1eb48f91a5
commit
b8c6760b96
@ -84,7 +84,14 @@ public class Agent
|
|||||||
/**
|
/**
|
||||||
* Our internal nominator implementing several nomination strategies.
|
* Our internal nominator implementing several nomination strategies.
|
||||||
*/
|
*/
|
||||||
private final DefaultNominator nominator = new DefaultNominator(this);
|
private final DefaultNominator nominator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the {@link PropertyChangeEvent} that we use to deliver
|
||||||
|
* events on changes in the state of ICE processing in this agent.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_ICE_PROCESSING_STATE
|
||||||
|
= "IceProcessingState";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the value of <tt>Ta</tt> as specified by the application or <tt>-1</tt>
|
* the value of <tt>Ta</tt> as specified by the application or <tt>-1</tt>
|
||||||
@ -197,6 +204,9 @@ public class Agent
|
|||||||
|
|
||||||
//add the FINGERPRINT attribute to all messages.
|
//add the FINGERPRINT attribute to all messages.
|
||||||
System.setProperty(StackProperties.ALWAYS_SIGN, "true");
|
System.setProperty(StackProperties.ALWAYS_SIGN, "true");
|
||||||
|
|
||||||
|
|
||||||
|
nominator = new DefaultNominator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -322,6 +332,9 @@ public class Agent
|
|||||||
synchronized(startLock)
|
synchronized(startLock)
|
||||||
{
|
{
|
||||||
initCheckLists();
|
initCheckLists();
|
||||||
|
|
||||||
|
//change state before we actually send checks so that we don't
|
||||||
|
//miss responses and hence the possibility to nominate a pair.
|
||||||
setState(IceProcessingState.RUNNING);
|
setState(IceProcessingState.RUNNING);
|
||||||
connCheckClient.startChecks();
|
connCheckClient.startChecks();
|
||||||
}
|
}
|
||||||
@ -409,7 +422,7 @@ public class Agent
|
|||||||
}
|
}
|
||||||
|
|
||||||
PropertyChangeEvent evt = new PropertyChangeEvent(
|
PropertyChangeEvent evt = new PropertyChangeEvent(
|
||||||
this, "IceProcessingState", oldState, newState);
|
this, PROPERTY_ICE_PROCESSING_STATE, oldState, newState);
|
||||||
|
|
||||||
for(PropertyChangeListener l : listenersCopy)
|
for(PropertyChangeListener l : listenersCopy)
|
||||||
{
|
{
|
||||||
@ -1027,8 +1040,8 @@ public class Agent
|
|||||||
/**
|
/**
|
||||||
* Raises <tt>pair</tt>'s nomination flag and schedules a triggered check.
|
* Raises <tt>pair</tt>'s nomination flag and schedules a triggered check.
|
||||||
* Applications only need to use this method if they disable this
|
* Applications only need to use this method if they disable this
|
||||||
* <tt>Agent</tt>'s internal nomination and implement their own nomination
|
* <tt>Agent</tt>'s internal nomination and implement their own nominator
|
||||||
* strategy.
|
* and turn off nominations in this agent.
|
||||||
*
|
*
|
||||||
* @param pair the {@link CandidatePair} that we'd like to nominate and that
|
* @param pair the {@link CandidatePair} that we'd like to nominate and that
|
||||||
* we'd like to schedule a triggered check for.
|
* we'd like to schedule a triggered check for.
|
||||||
@ -1036,7 +1049,7 @@ public class Agent
|
|||||||
* @throws IllegalStateException if this <tt>Agent</tt> is not a controlling
|
* @throws IllegalStateException if this <tt>Agent</tt> is not a controlling
|
||||||
* agent and can therefore not nominate pairs.
|
* agent and can therefore not nominate pairs.
|
||||||
*
|
*
|
||||||
* @see Agent#setAutoNominationEnabled(boolean)
|
* @see Agent#setNominationStrategy(NominationStrategy)
|
||||||
*/
|
*/
|
||||||
public void nominate(CandidatePair pair)
|
public void nominate(CandidatePair pair)
|
||||||
throws IllegalStateException
|
throws IllegalStateException
|
||||||
@ -1060,9 +1073,16 @@ public class Agent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNominationStrategy()
|
/**
|
||||||
|
* Specifies the {@link NominationStrategy} that we should use in order to
|
||||||
|
* decide if and when we should nominate valid pairs.
|
||||||
|
*
|
||||||
|
* @param strategy the strategy that we'd like to use for nominating
|
||||||
|
* valid {@link CandidatePair}s.
|
||||||
|
*/
|
||||||
|
public void setNominationStrategy(NominationStrategy strategy)
|
||||||
{
|
{
|
||||||
|
this.nominator.setStrategy(strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -53,6 +53,12 @@ public class CheckList
|
|||||||
private List<PropertyChangeListener> stateListeners
|
private List<PropertyChangeListener> stateListeners
|
||||||
= new LinkedList<PropertyChangeListener>();
|
= new LinkedList<PropertyChangeListener>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the {@link PropertyChangeEvent} that we use to deliver
|
||||||
|
* changes on the state of this check list.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_CHECK_LIST_STATE = "CheckListState";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a check list with the specified name.
|
* Creates a check list with the specified name.
|
||||||
*
|
*
|
||||||
@ -449,7 +455,7 @@ public class CheckList
|
|||||||
}
|
}
|
||||||
|
|
||||||
PropertyChangeEvent evt = new PropertyChangeEvent(
|
PropertyChangeEvent evt = new PropertyChangeEvent(
|
||||||
this, "CheckListState", oldState, newState);
|
this, PROPERTY_CHECK_LIST_STATE, oldState, newState);
|
||||||
|
|
||||||
for(PropertyChangeListener l : listenersCopy)
|
for(PropertyChangeListener l : listenersCopy)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,23 +7,88 @@
|
|||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import java.beans.*;
|
import java.beans.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements nomination strategies
|
* Implements ice4j internal nomination strategies.
|
||||||
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
public class DefaultNominator
|
public class DefaultNominator
|
||||||
implements PropertyChangeListener
|
implements PropertyChangeListener
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The Agent that created us.
|
||||||
|
*/
|
||||||
private final Agent parentAgent;
|
private final Agent parentAgent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The strategy that this nominator should use to nominate valid pairs.
|
||||||
|
*/
|
||||||
|
private NominationStrategy strategy
|
||||||
|
= NominationStrategy.NOMINATE_FIRST_VALID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of this nominator using <tt>parentAgent</tt> as
|
||||||
|
* a reference to the <tt>Agent</tt> instance that we should use to
|
||||||
|
* nominate pairs.
|
||||||
|
*
|
||||||
|
* @param parentAgent the {@link Agent} that created us.
|
||||||
|
*/
|
||||||
public DefaultNominator(Agent parentAgent)
|
public DefaultNominator(Agent parentAgent)
|
||||||
{
|
{
|
||||||
this.parentAgent = parentAgent;
|
this.parentAgent = parentAgent;
|
||||||
|
parentAgent.addStateChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks changes of state in {@link IceMediaStream}s and {@link
|
||||||
|
* CheckList}s.
|
||||||
|
*
|
||||||
|
* @param evt the event that we should use in case it means we should
|
||||||
|
* nominate someone.
|
||||||
|
*/
|
||||||
public void propertyChange(PropertyChangeEvent evt)
|
public void propertyChange(PropertyChangeEvent evt)
|
||||||
{
|
{
|
||||||
|
if(Agent.PROPERTY_ICE_PROCESSING_STATE.equals(evt.getPropertyName()))
|
||||||
|
{
|
||||||
|
IceProcessingState newState = (IceProcessingState)evt.getNewValue();
|
||||||
|
|
||||||
|
if(newState != IceProcessingState.RUNNING)
|
||||||
|
return;
|
||||||
|
|
||||||
|
List<IceMediaStream> streams = parentAgent.getStreams();
|
||||||
|
|
||||||
|
for(IceMediaStream stream : streams)
|
||||||
|
{
|
||||||
|
stream.addStreamChangeListener(this);
|
||||||
|
stream.getCheckList().addStateChangeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parentAgent.isControlling())
|
||||||
|
{
|
||||||
|
//CONTROLLED agents cannot nominate pairs
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName()))
|
||||||
|
{
|
||||||
|
CandidatePair validPair = (CandidatePair)evt.getNewValue();
|
||||||
|
parentAgent.nominate(validPair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link NominationStrategy} that this nominator should use when
|
||||||
|
* deciding whether or not a valid {@link CandidatePair} is suitable for
|
||||||
|
* nomination.
|
||||||
|
*
|
||||||
|
* @param strategy the {@link NominationStrategy} we should be using.
|
||||||
|
*/
|
||||||
|
public void setStrategy(NominationStrategy strategy)
|
||||||
|
{
|
||||||
|
this.strategy = strategy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -719,7 +719,7 @@ public class IceMediaStream
|
|||||||
}
|
}
|
||||||
|
|
||||||
PropertyChangeEvent evt = new PropertyChangeEvent(
|
PropertyChangeEvent evt = new PropertyChangeEvent(
|
||||||
this, "CheckListState", oldValue, newValue);
|
this, PROPERTY_PAIR_VALIDATED, oldValue, newValue);
|
||||||
|
|
||||||
for(PropertyChangeListener l : listenersCopy)
|
for(PropertyChangeListener l : listenersCopy)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -21,6 +21,12 @@ import org.ice4j.*;
|
|||||||
*/
|
*/
|
||||||
public enum NominationStrategy
|
public enum NominationStrategy
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Indicates that ice4j's nominator should nominate valid pairs and that
|
||||||
|
* the application will be handling this.
|
||||||
|
*/
|
||||||
|
NONE("None"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The strategy consists in nominating the first candidate pair that's
|
* The strategy consists in nominating the first candidate pair that's
|
||||||
* confirmed as valid.
|
* confirmed as valid.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user