fix: Makes the keep alive strategy final.
This commit is contained in:
parent
19e86e3bc9
commit
0d769bb46d
@ -448,18 +448,62 @@ public class Agent
|
||||
int preferredPort,
|
||||
int minPort,
|
||||
int maxPort)
|
||||
throws IllegalArgumentException,
|
||||
IOException,
|
||||
BindException
|
||||
{
|
||||
return createComponent(
|
||||
stream, transport,
|
||||
preferredPort, minPort, maxPort,
|
||||
KeepAliveStrategy.SELECTED_ONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Component} for the specified <tt>stream</tt> and
|
||||
* allocates potentially all local candidates that should belong to it.
|
||||
*
|
||||
* @param stream the {@link IceMediaStream} that the new {@link Component}
|
||||
* should belong to.
|
||||
* @param transport the transport protocol used by the component
|
||||
* @param preferredPort the port number that should be tried first when
|
||||
* binding local <tt>Candidate</tt> sockets for this <tt>Component</tt>.
|
||||
* @param minPort the port number where we should first try to bind before
|
||||
* moving to the next one (i.e. <tt>minPort + 1</tt>)
|
||||
* @param maxPort the maximum port number where we should try binding
|
||||
* before giving up and throwing an exception.
|
||||
* @param keepAliveStrategy the keep-alive strategy, which dictates which
|
||||
* candidates pairs are going to be kept alive.
|
||||
*
|
||||
* @return the newly created {@link Component} and with a list containing
|
||||
* all and only local candidates.
|
||||
*
|
||||
* @throws IllegalArgumentException if either <tt>minPort</tt> or
|
||||
* <tt>maxPort</tt> is not a valid port number or if <tt>minPort >
|
||||
* maxPort</tt>, or if <tt>transport</tt> is not currently supported.
|
||||
* @throws IOException if an error occurs while the underlying resolver lib
|
||||
* is using sockets.
|
||||
* @throws BindException if we couldn't find a free port between
|
||||
* <tt>minPort</tt> and <tt>maxPort</tt> before reaching the maximum allowed
|
||||
* number of retries.
|
||||
*/
|
||||
public Component createComponent( IceMediaStream stream,
|
||||
Transport transport,
|
||||
int preferredPort,
|
||||
int minPort,
|
||||
int maxPort,
|
||||
KeepAliveStrategy keepAliveStrategy)
|
||||
throws IllegalArgumentException,
|
||||
IOException,
|
||||
BindException
|
||||
{
|
||||
if(transport != Transport.UDP)
|
||||
if (transport != Transport.UDP)
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"This implementation does not currently support transport: "
|
||||
+ transport);
|
||||
}
|
||||
|
||||
Component component = stream.createComponent();
|
||||
Component component = stream.createComponent(keepAliveStrategy);
|
||||
|
||||
gatherCandidates(component, preferredPort, minPort, maxPort);
|
||||
|
||||
|
||||
@ -153,8 +153,7 @@ public class Component
|
||||
* The {@link KeepAliveStrategy} used by this component to select which
|
||||
* pairs are to be kept alive.
|
||||
*/
|
||||
private KeepAliveStrategy keepAliveStrategy
|
||||
= KeepAliveStrategy.SELECTED_ONLY;
|
||||
private final KeepAliveStrategy keepAliveStrategy;
|
||||
|
||||
/**
|
||||
* The set of pairs which this component wants to keep alive.
|
||||
@ -172,11 +171,14 @@ public class Component
|
||||
* parent of this component.
|
||||
*/
|
||||
protected Component(int componentID,
|
||||
IceMediaStream mediaStream)
|
||||
IceMediaStream mediaStream,
|
||||
KeepAliveStrategy keepAliveStrategy)
|
||||
{
|
||||
// the max value for componentID is 256
|
||||
this.componentID = componentID;
|
||||
this.parentStream = mediaStream;
|
||||
this.keepAliveStrategy
|
||||
= Objects.requireNonNull(keepAliveStrategy, "keepAliveStrategy");
|
||||
|
||||
Logger agentLogger = mediaStream.getParentAgent().getLogger();
|
||||
|
||||
@ -981,7 +983,9 @@ public class Component
|
||||
*/
|
||||
public static Component build(int componentID, IceMediaStream mediaStream)
|
||||
{
|
||||
return new Component(componentID, mediaStream);
|
||||
return
|
||||
new Component(
|
||||
componentID, mediaStream, KeepAliveStrategy.SELECTED_ONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1084,14 +1088,4 @@ public class Component
|
||||
keepAlivePairs.add(pair);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link KeepAliveStrategy} for this {@link Component}.
|
||||
* @param strategy the strategy to set.
|
||||
*/
|
||||
public void setKeepAliveStrategy(KeepAliveStrategy strategy)
|
||||
{
|
||||
keepAliveStrategy = Objects.requireNonNull(strategy, "strategy");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -173,16 +173,20 @@ public class IceMediaStream
|
||||
* when creating the component so make sure you keep that in mind in case
|
||||
* assigning a specific component ID is important to you.
|
||||
*
|
||||
* @param keepAliveStrategy the keep-alive strategy, which dictates which
|
||||
* candidates pairs are going to be kept alive.
|
||||
*
|
||||
* @return the newly created stream <tt>Component</tt> after adding it to
|
||||
* the stream first.
|
||||
*/
|
||||
protected Component createComponent()
|
||||
protected Component createComponent(KeepAliveStrategy keepAliveStrategy)
|
||||
{
|
||||
Component component;
|
||||
|
||||
synchronized (components)
|
||||
{
|
||||
component = new Component(++lastComponentID, this);
|
||||
component
|
||||
= new Component(++lastComponentID, this, keepAliveStrategy);
|
||||
components.put(component.getComponentID(), component);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user