diff --git a/src/net/java/sip/communicator/service/protocol/media/TransportManager.java b/src/net/java/sip/communicator/service/protocol/media/TransportManager.java index 419a0011f..ae9a6d31c 100644 --- a/src/net/java/sip/communicator/service/protocol/media/TransportManager.java +++ b/src/net/java/sip/communicator/service/protocol/media/TransportManager.java @@ -42,7 +42,8 @@ public abstract class TransportManager> * Initialized by {@link #initializePortNumbers()}. *

*/ - private static PortTracker defaultPortTracker = new PortTracker(5000, 6000); + private static final PortTracker defaultPortTracker + = new PortTracker(5000, 6000); /** * The port tracker that we should use when binding video media streams. @@ -51,25 +52,25 @@ public abstract class TransportManager> * necessary properties are set. *

*/ - private static PortTracker videoPortTracker = null; + private static PortTracker videoPortTracker; /** * The port tracker that we should use when binding data channels. *

* Potentially initialized by {@link #initializePortNumbers()} if the - * necessary properties are set + * necessary properties are set. *

*/ - private static PortTracker dataChannelPortTracker = null; + private static PortTracker dataPortTracker; /** * The port tracker that we should use when binding data media streams. *

* Potentially initialized by {@link #initializePortNumbers()} if the - * necessary properties are set + * necessary properties are set. *

*/ - private static PortTracker audioPortTracker = null; + private static PortTracker audioPortTracker; /** * RTP audio DSCP configuration property name. @@ -281,70 +282,72 @@ protected StreamConnector createStreamConnector(MediaType mediaType) } /** - * (Re)Sets the all the port allocators to reflect current values specified - * in the ConfigurationService. Calling this method may very well - * result in creating new port allocators or destroying existing ones. + * Tries to set the ranges of the PortTrackers (e.g. default, + * audio, video, data channel) to the values specified in the + * ConfigurationService. */ - protected static void initializePortNumbers() + protected synchronized static void initializePortNumbers() { //try the default tracker first ConfigurationService cfg = ProtocolMediaActivator.getConfigurationService(); - String minPortNumberStr + String minPort = cfg.getString( OperationSetBasicTelephony .MIN_MEDIA_PORT_NUMBER_PROPERTY_NAME); - String maxPortNumberStr + String maxPort = cfg.getString( OperationSetBasicTelephony .MAX_MEDIA_PORT_NUMBER_PROPERTY_NAME); - //try to send the specified range. If there's no specified range in - //configuration, we'll just leave the tracker as it is: [5000 to 6000] - defaultPortTracker.tryRange(minPortNumberStr, maxPortNumberStr); + //Try the specified range; otherwise, leave the tracker as it is: + //[5000, 6000]. + defaultPortTracker.tryRange(minPort, maxPort); //try the VIDEO tracker - minPortNumberStr + minPort = cfg.getString( OperationSetBasicTelephony .MIN_VIDEO_PORT_NUMBER_PROPERTY_NAME); - maxPortNumberStr + maxPort = cfg.getString( OperationSetBasicTelephony .MAX_VIDEO_PORT_NUMBER_PROPERTY_NAME); - //try to send the specified range. If there's no specified range in - //configuration, we'll just leave this tracker to null - videoPortTracker - = PortTracker.createTracker(minPortNumberStr, maxPortNumberStr); + //Try the specified range; otherwise, leave the tracker to null. + if (videoPortTracker == null) + videoPortTracker = PortTracker.createTracker(minPort, maxPort); + else + videoPortTracker.tryRange(minPort, maxPort); //try the AUDIO tracker - minPortNumberStr + minPort = cfg.getString( OperationSetBasicTelephony .MIN_AUDIO_PORT_NUMBER_PROPERTY_NAME); - maxPortNumberStr + maxPort = cfg.getString( OperationSetBasicTelephony .MAX_AUDIO_PORT_NUMBER_PROPERTY_NAME); - //try to send the specified range. If there's no specified range in - //configuration, we'll just leave this tracker to null - audioPortTracker - = PortTracker.createTracker(minPortNumberStr, maxPortNumberStr); + //Try the specified range; otherwise, leave the tracker to null. + if (audioPortTracker == null) + audioPortTracker = PortTracker.createTracker(minPort, maxPort); + else + audioPortTracker.tryRange(minPort, maxPort); //try the DATA CHANNEL tracker - minPortNumberStr + minPort = cfg.getString( OperationSetBasicTelephony .MIN_DATA_CHANNEL_PORT_NUMBER_PROPERTY_NAME); - maxPortNumberStr + maxPort = cfg.getString( OperationSetBasicTelephony .MAX_DATA_CHANNEL_PORT_NUMBER_PROPERTY_NAME); - - //try to send the specified range. If there's no specified range in - //configuration, we'll just leave this tracker to null - dataChannelPortTracker - = PortTracker.createTracker(minPortNumberStr, maxPortNumberStr); + //Try the specified range; otherwise, leave the tracker to null. + if (dataPortTracker == null) + dataPortTracker = PortTracker.createTracker(minPort, maxPort); + else + dataPortTracker.tryRange(minPort, maxPort); } /** @@ -594,11 +597,13 @@ protected static PortTracker getPortTracker(MediaType mediaType) case AUDIO: if (audioPortTracker != null) return audioPortTracker; - break; + else + break; case VIDEO: if (videoPortTracker != null) return videoPortTracker; - break; + else + break; } return defaultPortTracker;