refactor: Refactors the Component's socket API.
This commit is contained in:
parent
dae6d32875
commit
b4a5e2eb83
@ -124,16 +124,27 @@ public class Component
|
|||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link MergingDatagramSocket} instance which will serve as the
|
* The single {@link ComponentSocket} instance for this {@link Component},
|
||||||
* single socket instance for this {@link Component}, merging received
|
* which will merge the multiple sockets from the candidate/pairs.
|
||||||
* packets from all of its candidates.
|
|
||||||
*/
|
*/
|
||||||
private final MergingDatagramSocket mergingDatagramSocket;
|
private final ComponentSocket componentSocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around {@link #mergingDatagramSocket}.
|
* The public view of {@link #componentSocket}, wrapped in a
|
||||||
|
* {@link MultiplexingDatagramSocket} for the convenience of users of the
|
||||||
|
* library.
|
||||||
|
* This is the instance which should be used by applications for
|
||||||
|
* reading/writing application data.
|
||||||
*/
|
*/
|
||||||
private final IceUdpSocketWrapper mergingDatagramSocketWrapper;
|
private final MultiplexingDatagramSocket socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper around {@link #socket}, kept only to help preserve the old
|
||||||
|
* API (see {@link LocalCandidate#getIceSocketWrapper()} and
|
||||||
|
* {@link CandidatePair#getIceSocketWrapper()})
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
private final IceSocketWrapper socketWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <tt>Component</tt> with the specified <tt>componentID</tt>
|
* Creates a new <tt>Component</tt> with the specified <tt>componentID</tt>
|
||||||
@ -152,11 +163,9 @@ public class Component
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mergingDatagramSocket = new ComponentSocket(this);
|
componentSocket = new ComponentSocket(this);
|
||||||
mergingDatagramSocketWrapper
|
socket = new MultiplexingDatagramSocket(componentSocket);
|
||||||
= new IceUdpSocketWrapper(
|
socketWrapper = new IceUdpSocketWrapper(socket);
|
||||||
new MultiplexingDatagramSocket(
|
|
||||||
mergingDatagramSocket));
|
|
||||||
}
|
}
|
||||||
catch (SocketException se)
|
catch (SocketException se)
|
||||||
{
|
{
|
||||||
@ -807,7 +816,7 @@ public class Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSocket().close();
|
getComponentSocket().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -941,24 +950,30 @@ public class Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the single socket for this {@link Component} which should be
|
* @return the internal merging socket for this component. This is for
|
||||||
* used for reading and writing data.
|
* ice4j use only.
|
||||||
|
* For reading/writing application data, use {@link #getSocket()}.
|
||||||
*/
|
*/
|
||||||
public MergingDatagramSocket getSocket()
|
public ComponentSocket getComponentSocket()
|
||||||
{
|
{
|
||||||
return mergingDatagramSocket;
|
return componentSocket;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the socket for this {@link Component}, which should be used for
|
||||||
|
* reading/writing application data.
|
||||||
|
*/
|
||||||
|
public MultiplexingDatagramSocket getSocket()
|
||||||
|
{
|
||||||
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return an {@link IceSocketWrapper} instance wrapping the socket for this
|
* @return an {@link IceSocketWrapper} instance wrapping the socket for this
|
||||||
* candidate (see {@link #getSocket()}).
|
* candidate (see {@link #getComponentSocket()}).
|
||||||
* @deprecated Use {@link #getSocket()} directly. This is only introduced
|
|
||||||
* to ease the transition of applications which are already written to use
|
|
||||||
* an {@link IceSocketWrapper} instance.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public IceSocketWrapper getSocketWrapper()
|
public IceSocketWrapper getSocketWrapper()
|
||||||
{
|
{
|
||||||
return mergingDatagramSocketWrapper;
|
return socketWrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import java.util.logging.*;
|
|||||||
* Extends {@link MergingDatagramSocket} with functionality specific to
|
* Extends {@link MergingDatagramSocket} with functionality specific to
|
||||||
* an ICE {@link Component}.
|
* an ICE {@link Component}.
|
||||||
*/
|
*/
|
||||||
class ComponentSocket
|
public class ComponentSocket
|
||||||
extends MergingDatagramSocket
|
extends MergingDatagramSocket
|
||||||
implements PropertyChangeListener
|
implements PropertyChangeListener
|
||||||
{
|
{
|
||||||
@ -155,6 +155,7 @@ class ComponentSocket
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
component.getParentStream().removePairStateChangeListener(this);
|
||||||
component = null;
|
component = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -139,7 +139,7 @@ public class GoogleTurnCandidateHarvest
|
|||||||
= relayedCandidate.getCandidateIceSocketWrapper();
|
= relayedCandidate.getCandidateIceSocketWrapper();
|
||||||
|
|
||||||
Component component = relayedCandidate.getParentComponent();
|
Component component = relayedCandidate.getParentComponent();
|
||||||
component.getSocket().add(candidateSocket);
|
component.getComponentSocket().add(candidateSocket);
|
||||||
|
|
||||||
addCandidate(relayedCandidate);
|
addCandidate(relayedCandidate);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -158,7 +158,7 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
.getParentAgent()
|
.getParentAgent()
|
||||||
.getStunStack()
|
.getStunStack()
|
||||||
.addSocket(cand.getStunSocket(null));
|
.addSocket(cand.getStunSocket(null));
|
||||||
parentComponent.getSocket().add(multiplexing);
|
parentComponent.getComponentSocket().add(multiplexing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@ -418,7 +418,7 @@ public class HostCandidateHarvester
|
|||||||
// checks. In case we have enabled STUN, we are going to use
|
// checks. In case we have enabled STUN, we are going to use
|
||||||
// them as well while harvesting reflexive candidates.
|
// them as well while harvesting reflexive candidates.
|
||||||
createAndRegisterStunSocket(candidate);
|
createAndRegisterStunSocket(candidate);
|
||||||
component.getSocket().add(sock);
|
component.getComponentSocket().add(sock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,18 +18,14 @@
|
|||||||
package org.ice4j.ice.harvest;
|
package org.ice4j.ice.harvest;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.attribute.*;
|
|
||||||
import org.ice4j.ice.*;
|
import org.ice4j.ice.*;
|
||||||
import org.ice4j.message.*;
|
|
||||||
import org.ice4j.socket.*;
|
import org.ice4j.socket.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
import org.ice4j.util.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.*;
|
|
||||||
import java.util.logging.Logger; // Disambiguation
|
import java.util.logging.Logger; // Disambiguation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,7 +362,7 @@ public class SinglePortUdpHarvester
|
|||||||
new TransportAddress(remoteAddress, Transport.UDP));
|
new TransportAddress(remoteAddress, Transport.UDP));
|
||||||
|
|
||||||
// TODO: maybe move this code to the candidates.
|
// TODO: maybe move this code to the candidates.
|
||||||
component.getSocket().add(multiplexing);
|
component.getComponentSocket().add(multiplexing);
|
||||||
|
|
||||||
// XXX is this necessary?
|
// XXX is this necessary?
|
||||||
synchronized (candidateSockets)
|
synchronized (candidateSockets)
|
||||||
|
|||||||
@ -458,7 +458,7 @@ public class StunCandidateHarvester
|
|||||||
hostCand.getParentComponent().getParentStream().
|
hostCand.getParentComponent().getParentStream().
|
||||||
getParentAgent().getStunStack().addSocket(
|
getParentAgent().getStunStack().addSocket(
|
||||||
cand.getStunSocket(null));
|
cand.getStunSocket(null));
|
||||||
hostCand.getParentComponent().getSocket().add(multiplexing);
|
hostCand.getParentComponent().getComponentSocket().add(multiplexing);
|
||||||
}
|
}
|
||||||
catch(Exception io)
|
catch(Exception io)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -520,7 +520,7 @@ public class TcpHarvester
|
|||||||
candidate.addSocket(candidateSocket);
|
candidate.addSocket(candidateSocket);
|
||||||
|
|
||||||
// TODO: Maybe move this code to the candidate.
|
// TODO: Maybe move this code to the candidate.
|
||||||
component.getSocket().add(multiplexing);
|
component.getComponentSocket().add(multiplexing);
|
||||||
|
|
||||||
// the socket is not our responsibility anymore. It is up to
|
// the socket is not our responsibility anymore. It is up to
|
||||||
// the candidate/component to close/free it.
|
// the candidate/component to close/free it.
|
||||||
|
|||||||
@ -258,7 +258,7 @@ public class TurnCandidateHarvest
|
|||||||
harvester.getStunStack().addSocket(
|
harvester.getStunStack().addSocket(
|
||||||
relayedCandidate.getStunSocket(null));
|
relayedCandidate.getStunSocket(null));
|
||||||
|
|
||||||
relayedCandidate.getParentComponent().getSocket().add(
|
relayedCandidate.getParentComponent().getComponentSocket().add(
|
||||||
relayedCandidate.getCandidateIceSocketWrapper());
|
relayedCandidate.getCandidateIceSocketWrapper());
|
||||||
addCandidate(relayedCandidate);
|
addCandidate(relayedCandidate);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -223,7 +223,7 @@ public class UPNPHarvester
|
|||||||
= new UPNPCandidate(addr, base, component, device);
|
= new UPNPCandidate(addr, base, component, device);
|
||||||
IceSocketWrapper stunSocket = candidate.getStunSocket(null);
|
IceSocketWrapper stunSocket = candidate.getStunSocket(null);
|
||||||
candidate.getStunStack().addSocket(stunSocket);
|
candidate.getStunStack().addSocket(stunSocket);
|
||||||
component.getSocket().add(candidate.getCandidateIceSocketWrapper());
|
component.getComponentSocket().add(candidate.getCandidateIceSocketWrapper());
|
||||||
|
|
||||||
ret.add(candidate);
|
ret.add(candidate);
|
||||||
ret.add(base);
|
ret.add(base);
|
||||||
|
|||||||
@ -195,7 +195,7 @@ public class IceTcpServerSocketWrapper
|
|||||||
component.getParentStream().getParentAgent().
|
component.getParentStream().getParentAgent().
|
||||||
getStunStack().addSocket(
|
getStunStack().addSocket(
|
||||||
new IceTcpSocketWrapper(multiplexingSocket));
|
new IceTcpSocketWrapper(multiplexingSocket));
|
||||||
component.getSocket().add(multiplexingSocket);
|
component.getComponentSocket().add(multiplexingSocket);
|
||||||
|
|
||||||
sockets.add(multiplexingSocket);
|
sockets.add(multiplexingSocket);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user