Updated to use concurrent containers to avoid concurrent modification

exceptions.
This commit is contained in:
denny
2016-01-22 16:30:58 -05:00
parent cffc6b6eed
commit abca4ebbd7
2 changed files with 14 additions and 19 deletions

View File

@@ -128,10 +128,13 @@ public class ChannelList extends JPanel implements ChannelEventListener
public void setSelectedChannel( Channel channel ) public void setSelectedChannel( Channel channel )
{ {
/* Send channel selection to each channel panel */ synchronized( mDisplayedPanels )
for( ChannelCollectionPanel panel: mDisplayedPanels.values() )
{ {
panel.setSelectedChannel( channel ); /* Send channel selection to each channel panel */
for( ChannelCollectionPanel panel: mDisplayedPanels.values() )
{
panel.setSelectedChannel( channel );
}
} }
} }

View File

@@ -17,8 +17,8 @@
******************************************************************************/ ******************************************************************************/
package source.tuner; package source.tuner;
import java.util.ArrayList; import java.util.SortedSet;
import java.util.Collections; import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -36,8 +36,7 @@ public abstract class TunerController implements Tunable
LoggerFactory.getLogger( TunerController.class ); LoggerFactory.getLogger( TunerController.class );
/* List of currently tuned channels being served to demod channels */ /* List of currently tuned channels being served to demod channels */
protected ArrayList<TunerChannel> mTunedChannels = private SortedSet<TunerChannel> mTunedChannels = new ConcurrentSkipListSet<>();
new ArrayList<TunerChannel>();
protected FrequencyController mFrequencyController; protected FrequencyController mFrequencyController;
private int mMiddleUnusable; private int mMiddleUnusable;
private double mUsableBandwidthPercentage; private double mUsableBandwidthPercentage;
@@ -147,13 +146,9 @@ public abstract class TunerController implements Tunable
} }
else else
{ {
//Sort the existing locks and get the min/max locked frequencies
Collections.sort( mTunedChannels );
int usableBandwidth = getUsableBandwidth(); int usableBandwidth = getUsableBandwidth();
long minLockedFrequency = mTunedChannels.get( 0 ).getMinFrequency(); long minLockedFrequency = mTunedChannels.first().getMinFrequency();
long maxLockedFrequency = mTunedChannels long maxLockedFrequency = mTunedChannels.last().getMaxFrequency();
.get( mTunedChannels.size() - 1 ).getMaxFrequency();
//Requested channel is within current locked channel frequency range //Requested channel is within current locked channel frequency range
if( minLockedFrequency <= channel.getMinFrequency() && if( minLockedFrequency <= channel.getMinFrequency() &&
@@ -282,8 +277,6 @@ public abstract class TunerController implements Tunable
*/ */
private void updateLOFrequency() throws SourceException private void updateLOFrequency() throws SourceException
{ {
Collections.sort( mTunedChannels );
long frequency = getFrequency(); long frequency = getFrequency();
boolean frequencyValid = true; boolean frequencyValid = true;
@@ -291,13 +284,12 @@ public abstract class TunerController implements Tunable
//If there is only 1 channel, position it to the right of center //If there is only 1 channel, position it to the right of center
if( mTunedChannels.size() == 1 ) if( mTunedChannels.size() == 1 )
{ {
frequency = mTunedChannels.get( 0 ).getMinFrequency() - mMiddleUnusable; frequency = mTunedChannels.first().getMinFrequency() - mMiddleUnusable;
} }
else else
{ {
long minLockedFrequency = mTunedChannels.get( 0 ).getMinFrequency(); long minLockedFrequency = mTunedChannels.first().getMinFrequency();
long maxLockedFrequency = mTunedChannels long maxLockedFrequency = mTunedChannels.last().getMaxFrequency();
.get( mTunedChannels.size() - 1 ).getMaxFrequency();
//Start by placing the highest frequency channel at the high end of //Start by placing the highest frequency channel at the high end of
//the spectrum //the spectrum