Merge pull request #127 from DSheirer/#108-thread-pool-cleanup

#108 thread pool cleanup
This commit is contained in:
Denny Sheirer
2017-01-22 09:38:44 -05:00
committed by GitHub
40 changed files with 8822 additions and 9121 deletions

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,19 +14,20 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package alias.action;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import message.Message;
import alias.Alias;
import alias.action.beep.BeepAction;
import alias.action.clip.ClipAction;
import alias.action.script.ScriptAction;
import controller.ThreadPoolManager;
import message.Message;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import java.util.concurrent.ScheduledExecutorService;
/**
* Alias action defines an action to execute when an alias is detected active.
@@ -48,9 +49,7 @@ public abstract class AliasAction
* action attached. The alias argument is the parent alias containing the
* alias action.
*/
public abstract void execute( ThreadPoolManager threadPoolManager,
Alias alias,
Message message );
public abstract void execute( ScheduledExecutorService scheduledExecutorService, Alias alias, Message message );
/**
* Dismiss a persistent alias action

View File

@@ -1,11 +1,29 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package alias.action;
import java.util.List;
import alias.Alias;
import message.Message;
import sample.Listener;
import alias.Alias;
import controller.ThreadPoolManager;
import util.ThreadPool;
import java.util.List;
/**
* Manages all alias action events. Each received message is interrogated for
@@ -16,11 +34,8 @@ import controller.ThreadPoolManager;
*/
public class AliasActionManager implements Listener<Message>
{
private ThreadPoolManager mThreadPoolManager;
public AliasActionManager( ThreadPoolManager threadPoolManager )
public AliasActionManager()
{
mThreadPoolManager = threadPoolManager;
}
@Override
@@ -44,7 +59,7 @@ public class AliasActionManager implements Listener<Message>
* action needs to setup a timer, and provide the original
* message to be used as part of the action (e.g. sending
* the message as a text message to a cell phone */
action.execute( mThreadPoolManager, alias, message );
action.execute(ThreadPool.SCHEDULED, alias, message);
}
}
}

View File

@@ -1,39 +1,35 @@
package alias.action;
import java.awt.EventQueue;
import alias.Alias;
import message.Message;
import javax.swing.*;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;
import java.awt.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JOptionPane;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;
import message.Message;
import alias.Alias;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
public abstract class RecurringAction extends AliasAction
{
@XmlTransient
protected AtomicBoolean mRunning = new AtomicBoolean(false);
@XmlTransient
private ScheduledFuture<?> mPerpetualAction;
@XmlTransient
protected ScheduledExecutorService mScheduledExecutorService;
protected Interval mInterval = Interval.ONCE;
protected int mPeriod = 5;
protected ThreadPoolManager mThreadPoolManager;
public abstract void performAction(Alias alias, Message message);
@Override
public void execute( ThreadPoolManager threadPoolManager,
Alias alias,
Message message )
public void execute(ScheduledExecutorService scheduledExecutorService, Alias alias, Message message)
{
mThreadPoolManager = threadPoolManager;
mScheduledExecutorService = scheduledExecutorService;
if(mRunning.compareAndSet(false, true))
{
@@ -45,14 +41,11 @@ public abstract class RecurringAction extends AliasAction
break;
case DELAYED_RESET:
performThreadedAction(alias, message);
mThreadPoolManager.scheduleOnce( new ResetTask(),
mPeriod, TimeUnit.SECONDS );
mScheduledExecutorService.schedule(new ResetTask(), mPeriod, TimeUnit.SECONDS);
break;
case UNTIL_DISMISSED:
mPerpetualAction = mThreadPoolManager
.scheduleFixedRate( ThreadType.DECODER,
new PerformActionTask( alias, message ),
mPeriod, TimeUnit.SECONDS );
mPerpetualAction = mScheduledExecutorService.scheduleAtFixedRate(
new PerformActionTask(alias, message), mPeriod, mPeriod, TimeUnit.SECONDS);
StringBuilder sb = new StringBuilder();
sb.append("<html><div width='250'>Alias [");
@@ -73,8 +66,7 @@ public abstract class RecurringAction extends AliasAction
dismiss(false);
mThreadPoolManager.scheduleOnce( new ResetTask(),
15, TimeUnit.SECONDS );
mScheduledExecutorService.schedule(new ResetTask(), 15, TimeUnit.SECONDS);
}
});
break;
@@ -89,13 +81,14 @@ public abstract class RecurringAction extends AliasAction
*/
private void performThreadedAction(final Alias alias, final Message message)
{
mThreadPoolManager.scheduleOnce( new Runnable() {
mScheduledExecutorService.schedule(new Runnable()
{
@Override
public void run()
{
performAction(alias, message);
}}, 0, TimeUnit.SECONDS );
}
}, 0, TimeUnit.SECONDS);
}
@Override

View File

@@ -22,8 +22,6 @@ import audio.AudioEvent.Type;
import audio.output.AudioOutput;
import audio.output.MonoAudioOutput;
import audio.output.StereoAudioOutput;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
@@ -32,6 +30,7 @@ import sample.Listener;
import source.mixer.MixerChannel;
import source.mixer.MixerChannelConfiguration;
import source.mixer.MixerManager;
import util.ThreadPool;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Mixer;
@@ -70,7 +69,6 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
private Broadcaster<AudioEvent> mControllerBroadcaster = new Broadcaster<>();
private ThreadPoolManager mThreadPoolManager;
private ScheduledFuture<?> mProcessingTask;
private MixerManager mMixerManager;
private MixerChannelConfiguration mMixerChannelConfiguration;
@@ -81,9 +79,8 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
* packets to any combination of outputs based on any alias audio routing
* options specified by the user.
*/
public AudioManager(ThreadPoolManager manager, MixerManager mixerManager)
public AudioManager(MixerManager mixerManager)
{
mThreadPoolManager = manager;
mMixerManager = mixerManager;
loadSettings();
@@ -145,14 +142,13 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
public void dispose()
{
if(mThreadPoolManager != null && mProcessingTask != null)
if(mProcessingTask != null)
{
mThreadPoolManager.cancel(mProcessingTask);
mProcessingTask.cancel(true);
}
mAudioPacketQueue.clear();
mThreadPoolManager = null;
mProcessingTask = null;
mChannelConnectionMap.clear();
@@ -224,9 +220,9 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
{
mControllerBroadcaster.broadcast(CONFIGURATION_CHANGE_STARTED);
if(mThreadPoolManager != null && mProcessingTask != null)
if(mProcessingTask != null)
{
mThreadPoolManager.cancel(mProcessingTask);
mProcessingTask.cancel(true);
}
disposeCurrentConfiguration();
@@ -234,19 +230,18 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
switch(entry.getMixerChannel())
{
case MONO:
AudioOutput mono = new MonoAudioOutput(mThreadPoolManager,
entry.getMixer());
AudioOutput mono = new MonoAudioOutput(entry.getMixer());
mAudioOutputConnections.add(new AudioOutputConnection(mono));
mAvailableConnectionCount++;
mAudioOutputMap.put(mono.getChannelName(), mono);
break;
case STEREO:
AudioOutput left = new StereoAudioOutput(mThreadPoolManager, entry.getMixer(), MixerChannel.LEFT);
AudioOutput left = new StereoAudioOutput(entry.getMixer(), MixerChannel.LEFT);
mAudioOutputConnections.add(new AudioOutputConnection(left));
mAvailableConnectionCount++;
mAudioOutputMap.put(left.getChannelName(), left);
AudioOutput right = new StereoAudioOutput(mThreadPoolManager, entry.getMixer(), MixerChannel.RIGHT);
AudioOutput right = new StereoAudioOutput(entry.getMixer(), MixerChannel.RIGHT);
mAudioOutputConnections.add(new AudioOutputConnection(right));
mAvailableConnectionCount++;
mAudioOutputMap.put(right.getChannelName(), right);
@@ -256,9 +251,8 @@ public class AudioManager implements Listener<AudioPacket>, IAudioController
+ "configuration: " + entry.getMixerChannel());
}
mProcessingTask = mThreadPoolManager.scheduleFixedRate(
ThreadType.AUDIO_PROCESSING, new AudioPacketProcessor(), 15,
TimeUnit.MILLISECONDS);
mProcessingTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new AudioPacketProcessor(),
0, 15, TimeUnit.MILLISECONDS);
mControllerBroadcaster.broadcast(CONFIGURATION_CHANGE_COMPLETE);

View File

@@ -20,10 +20,10 @@ package audio.broadcast;
import audio.convert.ISilenceGenerator;
import channel.metadata.Metadata;
import controller.ThreadPoolManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sample.Listener;
import util.ThreadPool;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -40,7 +40,6 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
public static final int PROCESSOR_RUN_INTERVAL_MS = 1000;
private ThreadPoolManager mThreadPoolManager;
private ScheduledFuture mScheduledTask;
private RecordingQueueProcessor mRecordingQueueProcessor = new RecordingQueueProcessor();
@@ -77,19 +76,13 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
* The last audio packet's metadata is automatically attached to the closed audio recording when it is enqueued for
* broadcast. That metadata will be updated on the remote server once the audio recording is opened for streaming.
*/
public AudioBroadcaster(ThreadPoolManager threadPoolManager, BroadcastConfiguration broadcastConfiguration)
public AudioBroadcaster(BroadcastConfiguration broadcastConfiguration)
{
mThreadPoolManager = threadPoolManager;
mBroadcastConfiguration = broadcastConfiguration;
mDelay = mBroadcastConfiguration.getDelay();
mSilenceGenerator = BroadcastFactory.getSilenceGenerator(broadcastConfiguration.getBroadcastFormat());
}
protected ThreadPoolManager getThreadPoolManager()
{
return mThreadPoolManager;
}
/**
* Broadcast binary audio data frames or sequences.
*/
@@ -129,11 +122,8 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
{
if(mScheduledTask == null)
{
if(mThreadPoolManager != null)
{
mScheduledTask = mThreadPoolManager.scheduleFixedRate(ThreadPoolManager.ThreadType.AUDIO_PROCESSING,
mRecordingQueueProcessor, PROCESSOR_RUN_INTERVAL_MS, TimeUnit.MILLISECONDS);
}
ThreadPool.SCHEDULED.scheduleAtFixedRate(mRecordingQueueProcessor, 0,
PROCESSOR_RUN_INTERVAL_MS, TimeUnit.MILLISECONDS);
}
}
}
@@ -145,9 +135,9 @@ public abstract class AudioBroadcaster implements Listener<AudioRecording>
{
if(mStreaming.compareAndSet(true, false))
{
if(mThreadPoolManager != null && mScheduledTask != null)
if(mScheduledTask != null)
{
mThreadPoolManager.cancel(mScheduledTask);
mScheduledTask.cancel(true);
}
disconnect();

View File

@@ -37,7 +37,6 @@ import audio.convert.IAudioConverter;
import audio.convert.ISilenceGenerator;
import audio.convert.MP3AudioConverter;
import audio.convert.MP3SilenceGenerator;
import controller.ThreadPoolManager;
import gui.editor.Editor;
import gui.editor.EmptyEditor;
import icon.IconManager;
@@ -45,7 +44,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import record.AudioRecorder;
import record.mp3.MP3Recorder;
import settings.SettingsManager;
import java.nio.file.Path;
@@ -58,12 +56,11 @@ public class BroadcastFactory
/**
* Creates an audio streaming broadcaster for the configuration
* @param threadPoolManager for creating an audio broadcasting connection thread
*
* @param configuration describing the server and audio types
* @return configured broadcaster or null
*/
public static AudioBroadcaster getBroadcaster(ThreadPoolManager threadPoolManager,
BroadcastConfiguration configuration)
public static AudioBroadcaster getBroadcaster(BroadcastConfiguration configuration)
{
if(configuration != null)
{
@@ -74,20 +71,15 @@ public class BroadcastFactory
switch(configuration.getBroadcastServerType())
{
case BROADCASTIFY:
return new IcecastTCPAudioBroadcaster(threadPoolManager,
(BroadcastifyConfiguration)configuration);
return new IcecastTCPAudioBroadcaster((BroadcastifyConfiguration) configuration);
case ICECAST_TCP:
return new IcecastTCPAudioBroadcaster(threadPoolManager,
(IcecastTCPConfiguration)configuration);
return new IcecastTCPAudioBroadcaster((IcecastTCPConfiguration) configuration);
case ICECAST_HTTP:
return new IcecastHTTPAudioBroadcaster(threadPoolManager,
(IcecastHTTPConfiguration)configuration);
return new IcecastHTTPAudioBroadcaster((IcecastHTTPConfiguration) configuration);
case SHOUTCAST_V1:
return new ShoutcastV1AudioBroadcaster(threadPoolManager,
(ShoutcastV1Configuration)configuration);
return new ShoutcastV1AudioBroadcaster((ShoutcastV1Configuration) configuration);
case SHOUTCAST_V2:
return new ShoutcastV2AudioBroadcaster(threadPoolManager,
(ShoutcastV2Configuration)configuration);
return new ShoutcastV2AudioBroadcaster((ShoutcastV2Configuration) configuration);
case UNKNOWN:
default:
mLog.info("Unrecognized broadcastAudio configuration: " + configuration.getBroadcastFormat().name());
@@ -101,6 +93,7 @@ public class BroadcastFactory
/**
* Creates an audio convert to convert from 8 kHz PCM audio to the specified format
*
* @param configuration containing the requested output audio format
* @return audio convert or null
*/
@@ -149,6 +142,7 @@ public class BroadcastFactory
/**
* Constructs an editor for the specified broadcastAudio configuration
*
* @param configuration to modify or view
* @param broadcastModel model for broadcastAudio configurations
* @return an editor for the specified broadcastAudio configuration

View File

@@ -21,13 +21,13 @@ package audio.broadcast;
import alias.id.broadcast.BroadcastChannel;
import audio.AudioPacket;
import channel.metadata.Metadata;
import controller.ThreadPoolManager;
import icon.IconManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import sample.Broadcaster;
import sample.Listener;
import util.ThreadPool;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
@@ -66,7 +66,6 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
private Map<String,BroadcastConfiguration> mBroadcastConfigurationMap = new HashMap<>();
private Map<String,AudioBroadcaster> mBroadcasterMap = new HashMap<>();
private ThreadPoolManager mThreadPoolManager;
private IconManager mIconManager;
private StreamManager mStreamManager;
private Broadcaster<BroadcastEvent> mBroadcastEventBroadcaster = new Broadcaster<>();
@@ -74,17 +73,16 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
/**
* Model for managing Broadcast configurations and any associated broadcaster instances.
*/
public BroadcastModel(ThreadPoolManager threadPoolManager, IconManager iconManager)
public BroadcastModel(IconManager iconManager)
{
mThreadPoolManager = threadPoolManager;
mIconManager = iconManager;
mStreamManager = new StreamManager(threadPoolManager, new CompletedRecordingListener(), BroadcastFormat.MP3,
mStreamManager = new StreamManager(new CompletedRecordingListener(), BroadcastFormat.MP3,
SystemProperties.getInstance().getApplicationFolder(TEMPORARY_STREAM_DIRECTORY));
mStreamManager.start();
//Monitor to remove temporary recording files that have been streamed by all audio broadcasters
mThreadPoolManager.scheduleFixedRate(ThreadPoolManager.ThreadType.AUDIO_RECORDING,
new RecordingDeletionMonitor(), 15l, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.scheduleAtFixedRate(new RecordingDeletionMonitor(),
15l, 15l, TimeUnit.SECONDS);
removeOrphanedTemporaryRecordings();
}
@@ -293,8 +291,7 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
broadcastConfiguration.isValid() &&
!mBroadcasterMap.containsKey(broadcastConfiguration.getName()))
{
AudioBroadcaster audioBroadcaster = BroadcastFactory.getBroadcaster(mThreadPoolManager,
broadcastConfiguration);
AudioBroadcaster audioBroadcaster = BroadcastFactory.getBroadcaster(broadcastConfiguration);
if(audioBroadcaster != null)
{
@@ -403,7 +400,8 @@ public class BroadcastModel extends AbstractTableModel implements Listener<Audio
deleteBroadcaster(previousChannelName);
//Delay restarting the broadcaster to allow remote server time to cleanup
mThreadPoolManager.scheduleOnce(new DelayedBroadcasterStartup(broadcastConfiguration), 1, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(new DelayedBroadcasterStartup(broadcastConfiguration),
1, TimeUnit.SECONDS);
break;
case CONFIGURATION_DELETE:
deleteBroadcaster(broadcastEvent.getBroadcastConfiguration().getName());

View File

@@ -19,11 +19,11 @@
package audio.broadcast;
import audio.AudioPacket;
import controller.ThreadPoolManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import record.AudioRecorder;
import sample.Listener;
import util.ThreadPool;
import util.TimeStamp;
import java.nio.file.Files;
@@ -44,7 +44,6 @@ public class StreamManager implements Listener<AudioPacket>
private static AtomicInteger sNextRecordingNumber = new AtomicInteger();
private ThreadPoolManager mThreadPoolManager;
private Listener<AudioRecording> mAudioRecordingListener;
private BroadcastFormat mBroadcastFormat;
private Path mTempDirectory;
@@ -61,17 +60,13 @@ public class StreamManager implements Listener<AudioPacket>
*
* Completed streamable audio recordings are nominated to the output listener (for broadcast) upon completion
*
* @param threadPoolManager for scheduling runnables
* @param listener to receive completed audio recordings
* @param tempDirectory where to store temporary audio recordings
*/
public StreamManager(ThreadPoolManager threadPoolManager, Listener<AudioRecording> listener,
BroadcastFormat broadcastFormat, Path tempDirectory)
public StreamManager(Listener<AudioRecording> listener, BroadcastFormat broadcastFormat, Path tempDirectory)
{
assert (tempDirectory != null && Files.isDirectory(tempDirectory));
assert (mThreadPoolManager != null);
mThreadPoolManager = threadPoolManager;
mAudioRecordingListener = listener;
mBroadcastFormat = broadcastFormat;
mTempDirectory = tempDirectory;
@@ -90,8 +85,8 @@ public class StreamManager implements Listener<AudioPacket>
mRecorderMonitor = new RecorderMonitor();
}
mRecorderMonitorFuture = mThreadPoolManager.scheduleFixedRate(ThreadPoolManager.ThreadType.AUDIO_PROCESSING,
mRecorderMonitor, 2, TimeUnit.SECONDS);
mRecorderMonitorFuture = ThreadPool.SCHEDULED.scheduleAtFixedRate(mRecorderMonitor,
0,2, TimeUnit.SECONDS);
}
}
@@ -145,7 +140,7 @@ public class StreamManager implements Listener<AudioPacket>
{
AudioRecorder recorder = BroadcastFactory.getAudioRecorder(getTemporaryRecordingPath(),
mBroadcastFormat);
recorder.start(mThreadPoolManager.getScheduledExecutorService());
recorder.start(ThreadPool.SCHEDULED);
recorder.receive(audioPacket);
mStreamRecorders.put(channelMetadataID, recorder);
}

View File

@@ -21,15 +21,14 @@ package audio.broadcast.icecast;
import audio.broadcast.AudioBroadcaster;
import audio.broadcast.BroadcastConfiguration;
import audio.broadcast.IBroadcastMetadataUpdater;
import controller.ThreadPoolManager;
public abstract class IcecastAudioBroadcaster extends AudioBroadcaster
{
private IBroadcastMetadataUpdater mMetadataUpdater;
public IcecastAudioBroadcaster(ThreadPoolManager threadPoolManager, BroadcastConfiguration broadcastConfiguration)
public IcecastAudioBroadcaster(BroadcastConfiguration broadcastConfiguration)
{
super(threadPoolManager, broadcastConfiguration);
super(broadcastConfiguration);
}
/**
@@ -45,7 +44,7 @@ public abstract class IcecastAudioBroadcaster extends AudioBroadcaster
{
if(mMetadataUpdater == null)
{
mMetadataUpdater = new IcecastBroadcastMetadataUpdater(getThreadPoolManager(), getConfiguration());
mMetadataUpdater = new IcecastBroadcastMetadataUpdater(getConfiguration());
}
return mMetadataUpdater;

View File

@@ -20,7 +20,6 @@ package audio.broadcast.icecast;
import audio.broadcast.IBroadcastMetadataUpdater;
import channel.metadata.Metadata;
import controller.ThreadPoolManager;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
@@ -33,6 +32,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import util.ThreadPool;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
@@ -50,7 +50,6 @@ public class IcecastBroadcastMetadataUpdater implements IBroadcastMetadataUpdate
private final static Logger mLog = LoggerFactory.getLogger(IcecastBroadcastMetadataUpdater.class);
private final static String UTF8 = "UTF-8";
private ThreadPoolManager mThreadPoolManager;
private IcecastConfiguration mIcecastConfiguration;
private NioSocketConnector mSocketConnector;
@@ -65,9 +64,8 @@ public class IcecastBroadcastMetadataUpdater implements IBroadcastMetadataUpdate
* broadcaster. When multiple metadata updates are received prior to completion of the current ongoing update
* sequence, those updates will be queued and processed in the order received.
*/
public IcecastBroadcastMetadataUpdater(ThreadPoolManager threadPoolManager, IcecastConfiguration icecastConfiguration)
public IcecastBroadcastMetadataUpdater(IcecastConfiguration icecastConfiguration)
{
mThreadPoolManager = threadPoolManager;
mIcecastConfiguration = icecastConfiguration;
}
@@ -128,7 +126,7 @@ public class IcecastBroadcastMetadataUpdater implements IBroadcastMetadataUpdate
if(updateRequest != null)
{
mThreadPoolManager.scheduleOnce(new Runnable()
ThreadPool.SCHEDULED.schedule(new Runnable()
{
@Override
public void run()

View File

@@ -20,7 +20,6 @@ package audio.broadcast.icecast;
import audio.broadcast.BroadcastState;
import audio.convert.MP3AudioConverter;
import controller.ThreadPoolManager;
import org.apache.mina.core.RuntimeIoException;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.future.ConnectFuture;
@@ -38,6 +37,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import util.ThreadPool;
import java.net.ConnectException;
import java.net.InetSocketAddress;
@@ -69,9 +69,9 @@ public class IcecastHTTPAudioBroadcaster extends IcecastAudioBroadcaster
*
* @param configuration for the Icecast stream
*/
public IcecastHTTPAudioBroadcaster(ThreadPoolManager threadPoolManager, IcecastHTTPConfiguration configuration)
public IcecastHTTPAudioBroadcaster(IcecastHTTPConfiguration configuration)
{
super(threadPoolManager, configuration);
super(configuration);
}
/**
@@ -159,7 +159,7 @@ public class IcecastHTTPAudioBroadcaster extends IcecastAudioBroadcaster
}
};
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
}

View File

@@ -21,7 +21,6 @@ package audio.broadcast.icecast;
import audio.broadcast.BroadcastState;
import audio.broadcast.icecast.codec.IcecastCodecFactory;
import audio.convert.MP3AudioConverter;
import controller.ThreadPoolManager;
import org.apache.mina.core.RuntimeIoException;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoHandlerAdapter;
@@ -31,6 +30,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import util.ThreadPool;
import java.io.IOException;
import java.net.ConnectException;
@@ -62,9 +62,9 @@ public class IcecastTCPAudioBroadcaster extends IcecastAudioBroadcaster
*
* @param configuration for the Icecast stream
*/
public IcecastTCPAudioBroadcaster(ThreadPoolManager threadPoolManager, IcecastTCPConfiguration configuration)
public IcecastTCPAudioBroadcaster(IcecastTCPConfiguration configuration)
{
super(threadPoolManager, configuration);
super(configuration);
}
/**
@@ -149,8 +149,7 @@ public class IcecastTCPAudioBroadcaster extends IcecastAudioBroadcaster
}
};
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
}
return connected();

View File

@@ -21,7 +21,6 @@ package audio.broadcast.shoutcast.v1;
import audio.broadcast.AudioBroadcaster;
import audio.broadcast.BroadcastState;
import audio.broadcast.IBroadcastMetadataUpdater;
import controller.ThreadPoolManager;
import org.apache.mina.core.RuntimeIoException;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.future.ConnectFuture;
@@ -32,6 +31,7 @@ import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import util.ThreadPool;
import java.io.IOException;
import java.net.ConnectException;
@@ -61,9 +61,9 @@ public class ShoutcastV1AudioBroadcaster extends AudioBroadcaster
*
* @param configuration for the Shoutcast stream
*/
public ShoutcastV1AudioBroadcaster(ThreadPoolManager threadPoolManager, ShoutcastV1Configuration configuration)
public ShoutcastV1AudioBroadcaster(ShoutcastV1Configuration configuration)
{
super(threadPoolManager, configuration);
super(configuration);
}
/**
@@ -79,7 +79,7 @@ public class ShoutcastV1AudioBroadcaster extends AudioBroadcaster
{
if(mMetadataUpdater == null)
{
mMetadataUpdater = new ShoutcastV1BroadcastMetadataUpdater(getThreadPoolManager(), getConfiguration());
mMetadataUpdater = new ShoutcastV1BroadcastMetadataUpdater(getConfiguration());
}
return mMetadataUpdater;
@@ -171,8 +171,7 @@ public class ShoutcastV1AudioBroadcaster extends AudioBroadcaster
}
};
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
}
return connected();

View File

@@ -20,7 +20,6 @@ package audio.broadcast.shoutcast.v1;
import audio.broadcast.IBroadcastMetadataUpdater;
import channel.metadata.Metadata;
import controller.ThreadPoolManager;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
@@ -32,6 +31,7 @@ import org.apache.mina.http.api.HttpVersion;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import util.ThreadPool;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
@@ -49,7 +49,6 @@ public class ShoutcastV1BroadcastMetadataUpdater implements IBroadcastMetadataUp
private final static Logger mLog = LoggerFactory.getLogger(ShoutcastV1BroadcastMetadataUpdater.class);
private final static String UTF8 = "UTF-8";
private ThreadPoolManager mThreadPoolManager;
private ShoutcastV1Configuration mShoutcastV1Configuration;
private NioSocketConnector mSocketConnector;
@@ -63,9 +62,8 @@ public class ShoutcastV1BroadcastMetadataUpdater implements IBroadcastMetadataUp
* broadcaster. When multiple metadata updates are received prior to completion of the current ongoing update
* sequence, those updates will be queued and processed in the order received.
*/
public ShoutcastV1BroadcastMetadataUpdater(ThreadPoolManager threadPoolManager, ShoutcastV1Configuration shoutcastV1Configuration)
public ShoutcastV1BroadcastMetadataUpdater(ShoutcastV1Configuration shoutcastV1Configuration)
{
mThreadPoolManager = threadPoolManager;
mShoutcastV1Configuration = shoutcastV1Configuration;
}
@@ -127,7 +125,7 @@ public class ShoutcastV1BroadcastMetadataUpdater implements IBroadcastMetadataUp
if(updateRequest != null)
{
mThreadPoolManager.scheduleOnce(new Runnable()
ThreadPool.SCHEDULED.schedule(new Runnable()
{
@Override
public void run()

View File

@@ -38,7 +38,6 @@ import audio.broadcast.shoutcast.v2.ultravox.UltravoxMessageType;
import audio.broadcast.shoutcast.v2.ultravox.UltravoxMetadata;
import audio.broadcast.shoutcast.v2.ultravox.UltravoxProtocolFactory;
import channel.metadata.Metadata;
import controller.ThreadPoolManager;
import org.apache.mina.core.RuntimeIoException;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoHandlerAdapter;
@@ -48,6 +47,7 @@ import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import util.ThreadPool;
import java.io.IOException;
import java.net.ConnectException;
@@ -81,12 +81,11 @@ public class ShoutcastV2AudioBroadcaster extends AudioBroadcaster implements IBr
* This broadcaster uses the Apache Mina library for the streaming socket connection. The
* ShoutcastV2IOHandler manages all interaction with the Shoutcast server and manages the overall broadcast state.
*
* @param threadPoolManager for thread pool access
* @param configuration for the Shoutcast V2 stream
*/
public ShoutcastV2AudioBroadcaster(ThreadPoolManager threadPoolManager, ShoutcastV2Configuration configuration)
public ShoutcastV2AudioBroadcaster(ShoutcastV2Configuration configuration)
{
super(threadPoolManager, configuration);
super(configuration);
}
public ShoutcastV2Configuration getConfiguration()
@@ -207,8 +206,7 @@ public class ShoutcastV2AudioBroadcaster extends AudioBroadcaster implements IBr
}
};
getThreadPoolManager().scheduleOnce(runnable, 0l, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(runnable, 0l, TimeUnit.SECONDS);
}
return connected();

View File

@@ -22,13 +22,12 @@ import audio.AudioEvent;
import audio.AudioPacket;
import audio.AudioPacket.Type;
import channel.metadata.Metadata;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sample.Broadcaster;
import sample.Listener;
import source.mixer.MixerChannel;
import util.ThreadPool;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.BooleanControl;
@@ -59,7 +58,6 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
private Listener<Metadata> mMetadataListener;
private Broadcaster<AudioEvent> mAudioEventBroadcaster = new Broadcaster<>();
private ThreadPoolManager mThreadPoolManager;
private ScheduledFuture<?> mProcessorTask;
private SourceDataLine mOutput;
@@ -82,21 +80,18 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
* Maintains an internal non-blocking audio packet queue and processes this
* queue 25 times a second (every 40 ms).
*
* @param threadPoolManager for assigning buffer processing schedule task
* @param mixer to obtain source data line
* @param mixerChannel either mono or left/right stereo
* @param audioFormat to use during playback
* @param lineInfo to use when obtaining the source data line
* @param requestedBufferSize of approximately 1 second of audio
*/
public AudioOutput(ThreadPoolManager threadPoolManager,
Mixer mixer,
public AudioOutput(Mixer mixer,
MixerChannel mixerChannel,
AudioFormat audioFormat,
Line.Info lineInfo,
int requestedBufferSize)
{
mThreadPoolManager = threadPoolManager;
mMixer = mixer;
mMixerChannel = mixerChannel;
@@ -141,9 +136,8 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
}
/* Run the queue processor task every 40 milliseconds or 25 times a second */
mProcessorTask = mThreadPoolManager.scheduleFixedRate(
ThreadType.AUDIO_PROCESSING, new BufferProcessor(),
40, TimeUnit.MILLISECONDS);
mProcessorTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferProcessor(),
0, 40, TimeUnit.MILLISECONDS);
}
mAudioStartEvent = new AudioEvent(AudioEvent.Type.AUDIO_STARTED,
@@ -170,12 +164,11 @@ public abstract class AudioOutput implements Listener<AudioPacket>, LineListener
{
mCanProcessAudio = false;
if(mProcessorTask != null && mThreadPoolManager != null)
if(mProcessorTask != null)
{
mThreadPoolManager.cancel(mProcessorTask);
mProcessorTask.cancel(true);
}
mThreadPoolManager = null;
mProcessorTask = null;
mBuffer.clear();

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,20 +14,19 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package audio.output;
import audio.AudioFormats;
import audio.AudioPacket;
import source.mixer.MixerChannel;
import javax.sound.sampled.Mixer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import javax.sound.sampled.Mixer;
import source.mixer.MixerChannel;
import audio.AudioFormats;
import audio.AudioPacket;
import controller.ThreadPoolManager;
/**
* Mono Audio output implementation
*/
@@ -35,14 +34,10 @@ public class MonoAudioOutput extends AudioOutput
{
private final static int BUFFER_SIZE = 8000;
public MonoAudioOutput( ThreadPoolManager threadPoolManager, Mixer mixer )
public MonoAudioOutput(Mixer mixer)
{
super( threadPoolManager,
mixer,
MixerChannel.MONO,
AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO,
AudioFormats.MONO_SOURCE_DATALINE_INFO,
BUFFER_SIZE );
super(mixer, MixerChannel.MONO, AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO,
AudioFormats.MONO_SOURCE_DATALINE_INFO, BUFFER_SIZE);
}
/**
@@ -55,9 +50,7 @@ public class MonoAudioOutput extends AudioOutput
float[] samples = packet.getAudioBuffer().getSamples();
/* Little-endian byte buffer */
ByteBuffer buffer =
ByteBuffer.allocate( samples.length * 2 )
.order( ByteOrder.LITTLE_ENDIAN );
ByteBuffer buffer = ByteBuffer.allocate(samples.length * 2).order(ByteOrder.LITTLE_ENDIAN);
ShortBuffer shortBuffer = buffer.asShortBuffer();

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,20 +14,19 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package audio.output;
import audio.AudioFormats;
import audio.AudioPacket;
import source.mixer.MixerChannel;
import javax.sound.sampled.Mixer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import javax.sound.sampled.Mixer;
import source.mixer.MixerChannel;
import audio.AudioFormats;
import audio.AudioPacket;
import controller.ThreadPoolManager;
/**
* Stereo audio output implementation.
*/
@@ -35,14 +34,9 @@ public class StereoAudioOutput extends AudioOutput
{
private final static int BUFFER_SIZE = 16000;
public StereoAudioOutput( ThreadPoolManager threadPoolManager,
Mixer mixer, MixerChannel channel )
public StereoAudioOutput(Mixer mixer, MixerChannel channel)
{
super( threadPoolManager,
mixer,
channel,
AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO,
AudioFormats.STEREO_SOURCE_DATALINE_INFO,
super(mixer, channel, AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO, AudioFormats.STEREO_SOURCE_DATALINE_INFO,
BUFFER_SIZE);
}

View File

@@ -20,7 +20,6 @@ package channel.metadata;
import alias.Alias;
import channel.state.State;
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
import controller.channel.Channel;
import controller.channel.ChannelProcessingManager;
import icon.IconManager;

View File

@@ -1,113 +0,0 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package controller;
import java.util.HashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ThreadPoolManager
{
private final static Logger mLog = LoggerFactory.getLogger( ThreadPoolManager.class );
private int THREAD_POOL_SIZE = 2;
private HashMap<ScheduledFuture<?>,ThreadType> mTasks =
new HashMap<ScheduledFuture<?>,ThreadType>();
private ScheduledExecutorService mExecutor;
public ThreadPoolManager()
{
}
public ScheduledExecutorService getScheduledExecutorService()
{
if( mExecutor == null )
{
mExecutor = Executors.newScheduledThreadPool( THREAD_POOL_SIZE,
new NamingThreadFactory( "sdrtrunk" ) );
}
return mExecutor;
}
public ScheduledFuture<?> scheduleFixedRate( ThreadType type,
Runnable command,
long period,
TimeUnit unit )
throws RejectedExecutionException
{
ScheduledExecutorService executorService = getScheduledExecutorService();
ScheduledFuture<?> task =
executorService.scheduleAtFixedRate( command, 0, period, unit );
mTasks.put( task, type );
return task;
}
public void scheduleOnce( Runnable command, long delay, TimeUnit unit )
throws RejectedExecutionException
{
ScheduledExecutorService executorService = getScheduledExecutorService();
executorService.schedule( command, delay, unit );
}
public boolean cancel( ScheduledFuture<?> task )
{
boolean success = task.cancel( true );
mTasks.remove( task );
return success;
}
public int getTaskCount( ThreadType type )
{
int count = 0;
for( ThreadType current: mTasks.values() )
{
if( current == type )
{
count++;
}
}
return count;
}
public enum ThreadType
{
AUDIO_PROCESSING,
AUDIO_RECORDING,
BASEBAND_RECORDING,
SOURCE_SAMPLE_PROCESSING,
DECIMATION,
DECODER;
}
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package gui;
@@ -24,9 +25,6 @@ import audio.broadcast.BroadcastModel;
import audio.broadcast.BroadcastStatusPanel;
import com.jidesoft.swing.JideSplitPane;
import controller.ControllerPanel;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
import controller.channel.ChannelEventListener;
import controller.channel.ChannelModel;
import controller.channel.ChannelProcessingManager;
import controller.channel.ChannelSelectionManager;
@@ -48,6 +46,7 @@ import source.tuner.TunerModel;
import source.tuner.TunerSpectralDisplayManager;
import source.tuner.configuration.TunerConfigurationModel;
import spectrum.SpectralDisplayPanel;
import util.ThreadPool;
import util.TimeStamp;
import javax.imageio.ImageIO;
@@ -61,7 +60,6 @@ import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
public class SDRTrunk implements Listener<TunerEvent>
{
@@ -80,22 +78,24 @@ public class SDRTrunk implements Listener<TunerEvent>
private String mTitle;
private boolean mLogChannelAndMemoryUsage = false;
public SDRTrunk()
{
mLog.info("");
mLog.info("");
mLog.info("*******************************************************************");
mLog.info("**** sdrtrunk: a trunked radio and digital decoding application ***");
mLog.info("**** website: https://github.com/dsheirer/sdrtrunk ***");
mLog.info("*******************************************************************");
mLog.info("");
mLog.info("");
mLog.info("Host CPU Cores: " + Runtime.getRuntime().availableProcessors());
mLog.info("Host Memory Total: " + Runtime.getRuntime().totalMemory());
mLog.info("Host Memory Max: " + Runtime.getRuntime().maxMemory());
mLog.info("Host Memory Free: " + Runtime.getRuntime().freeMemory());
//Setup the application home directory
Path home = getHomePath();
ThreadPool.logSettings();
mLog.info("Home path: " + home.toString());
//Load properties file
@@ -110,11 +110,9 @@ public class SDRTrunk implements Listener<TunerEvent>
TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel();
TunerModel tunerModel = new TunerModel(tunerConfigurationModel);
ThreadPoolManager threadPoolManager = new ThreadPoolManager();
mIconManager = new IconManager();
mIconManager = new IconManager(threadPoolManager);
mSettingsManager = new SettingsManager(threadPoolManager, tunerConfigurationModel);
mSettingsManager = new SettingsManager(tunerConfigurationModel);
AliasModel aliasModel = new AliasModel();
@@ -124,10 +122,9 @@ public class SDRTrunk implements Listener<TunerEvent>
EventLogManager eventLogManager = new EventLogManager();
RecorderManager recorderManager = new RecorderManager(threadPoolManager);
RecorderManager recorderManager = new RecorderManager();
SourceManager sourceManager = new SourceManager(tunerModel,
mSettingsManager, threadPoolManager);
SourceManager sourceManager = new SourceManager(tunerModel, mSettingsManager);
ChannelProcessingManager channelProcessingManager = new ChannelProcessingManager(
channelModel, channelMapModel, aliasModel, eventLogManager, recorderManager, sourceManager);
@@ -139,13 +136,13 @@ public class SDRTrunk implements Listener<TunerEvent>
new ChannelSelectionManager(channelModel);
channelModel.addListener(channelSelectionManager);
AliasActionManager aliasActionManager = new AliasActionManager(threadPoolManager);
AliasActionManager aliasActionManager = new AliasActionManager();
channelProcessingManager.addMessageListener(aliasActionManager);
AudioManager audioManager = new AudioManager(threadPoolManager, sourceManager.getMixerManager());
AudioManager audioManager = new AudioManager(sourceManager.getMixerManager());
channelProcessingManager.addAudioPacketListener(audioManager);
mBroadcastModel = new BroadcastModel(threadPoolManager, mIconManager);
mBroadcastModel = new BroadcastModel(mIconManager);
channelProcessingManager.addAudioPacketListener(mBroadcastModel);
@@ -165,19 +162,11 @@ public class SDRTrunk implements Listener<TunerEvent>
tunerModel.addListener(tunerSpectralDisplayManager);
tunerModel.addListener(this);
PlaylistManager playlistManager = new PlaylistManager(threadPoolManager,
aliasModel, mBroadcastModel, channelModel, channelMapModel);
PlaylistManager playlistManager = new PlaylistManager(aliasModel, mBroadcastModel, channelModel,
channelMapModel);
playlistManager.init();
if (mLogChannelAndMemoryUsage)
{
Runnable cml = new ChannelMemoryLogger();
channelModel.addListener((ChannelEventListener) cml);
threadPoolManager.scheduleFixedRate(
ThreadType.DECODER, cml, 5, TimeUnit.SECONDS);
}
mLog.info("starting main application gui");
//Initialize the GUI

View File

@@ -18,14 +18,12 @@
******************************************************************************/
package icon;
import controller.ThreadPoolManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import util.ThreadPool;
import javax.swing.*;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.xml.bind.JAXBContext;
@@ -54,16 +52,14 @@ public class IconManager
private Path mIconBackupFilePath;
private Path mIconLockFilePath;
private ThreadPoolManager mThreadPoolManager;
private IconEditor mIconEditor;
private IconTableModel mIconTableModel;
private AtomicBoolean mSavingIcons = new AtomicBoolean();
private Map<String,ImageIcon> mResizedIcons = new HashMap<>();
public IconManager(ThreadPoolManager threadPoolManager)
public IconManager()
{
mThreadPoolManager = threadPoolManager;
}
/**
@@ -412,7 +408,7 @@ public class IconManager
{
if(mSavingIcons.compareAndSet(false, true))
{
mThreadPoolManager.scheduleOnce(new IconSaveTask(), 2, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(new IconSaveTask(), 2, TimeUnit.SECONDS);
}
}

View File

@@ -1,22 +1,18 @@
package instrument.gui;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import alias.AliasModel;
import audio.broadcast.BroadcastModel;
import controller.channel.ChannelModel;
import controller.channel.map.ChannelMapModel;
import module.decode.DecodeConfigurationEditor;
import net.miginfocom.swing.MigLayout;
import playlist.PlaylistManager;
import source.IControllableFileSource;
import alias.AliasModel;
import controller.ThreadPoolManager;
import controller.channel.ChannelModel;
import controller.channel.map.ChannelMapModel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DecoderSelectionFrame extends JInternalFrame
{
@@ -31,14 +27,12 @@ public class DecoderSelectionFrame extends JInternalFrame
public DecoderSelectionFrame(JDesktopPane desktop,
IControllableFileSource source)
{
ThreadPoolManager tpm = new ThreadPoolManager();
AliasModel aliasModel = new AliasModel();
BroadcastModel broadcastModel = new BroadcastModel(tpm, null);
BroadcastModel broadcastModel = new BroadcastModel(null);
ChannelModel channelModel = new ChannelModel();
ChannelMapModel channelMapModel = new ChannelMapModel();
mPlaylistManager = new PlaylistManager( tpm, aliasModel, broadcastModel, channelModel, channelMapModel );
mPlaylistManager = new PlaylistManager(aliasModel, broadcastModel, channelModel, channelMapModel);
mDesktop = desktop;
mSource = source;

View File

@@ -19,7 +19,6 @@
package map;
import alias.Alias;
import controller.NamingThreadFactory;
import icon.IconManager;
import message.Message;
import sample.Listener;
@@ -28,9 +27,8 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
public class MapService implements Listener<Message>
{
@@ -39,12 +37,7 @@ public class MapService implements Listener<Message>
private static final Color sDEFAULT_COLOR = Color.BLACK;
private final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1,
new NamingThreadFactory("map tile fetcher"));
private ArrayList<PlottableUpdateListener> mListeners =
new ArrayList<PlottableUpdateListener>();
private List<PlottableUpdateListener> mListeners = new ArrayList<PlottableUpdateListener>();
private HashMap<String, PlottableEntity> mEntities =
new HashMap<String, PlottableEntity>();

View File

@@ -34,7 +34,6 @@ import channel.state.DecoderStateEvent.Event;
import channel.state.IDecoderStateEventListener;
import channel.state.IDecoderStateEventProvider;
import channel.state.State;
import controller.NamingThreadFactory;
import controller.channel.Channel.ChannelType;
import controller.channel.ChannelEvent;
import controller.channel.IChannelEventListener;
@@ -69,11 +68,10 @@ import source.tuner.TunerChannelSource;
import source.tuner.frequency.FrequencyChangeEvent;
import source.tuner.frequency.IFrequencyChangeListener;
import source.tuner.frequency.IFrequencyChangeProvider;
import util.ThreadPool;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -110,7 +108,6 @@ public class ProcessingChain implements IChannelEventListener
private Broadcaster<RealBuffer> mUnFilteredRealBufferBroadcaster = new Broadcaster<>();
private Broadcaster<SquelchState> mSquelchStateBroadcaster = new Broadcaster<>();
private ScheduledExecutorService mScheduledExecutorService;
private String mName;
private AtomicBoolean mRunning = new AtomicBoolean();
@@ -170,9 +167,6 @@ public class ProcessingChain implements IChannelEventListener
mModules.clear();
mScheduledExecutorService.shutdownNow();
mScheduledExecutorService = null;
mAudioPacketBroadcaster.dispose();
mCallEventBroadcaster.dispose();
mChannelEventBroadcaster.dispose();
@@ -180,11 +174,6 @@ public class ProcessingChain implements IChannelEventListener
mMessageBroadcaster.dispose();
mFilteredRealBufferBroadcaster.dispose();
mSquelchStateBroadcaster.dispose();
if(mScheduledExecutorService != null)
{
mScheduledExecutorService.shutdownNow();
}
}
/**
@@ -584,18 +573,12 @@ public class ProcessingChain implements IChannelEventListener
}
}
if(mScheduledExecutorService == null)
{
mScheduledExecutorService = Executors.newScheduledThreadPool(
1, new NamingThreadFactory("channel " + mName));
}
/* Start each of the modules */
for(Module module : mModules)
{
try
{
module.start(mScheduledExecutorService);
module.start(ThreadPool.SCHEDULED);
}
catch(Exception e)
{
@@ -603,7 +586,7 @@ public class ProcessingChain implements IChannelEventListener
}
}
mSource.start(mScheduledExecutorService);
mSource.start(ThreadPool.SCHEDULED);
}
else
{

View File

@@ -21,7 +21,6 @@ import alias.AliasEvent;
import alias.AliasModel;
import audio.broadcast.BroadcastEvent;
import audio.broadcast.BroadcastModel;
import controller.ThreadPoolManager;
import controller.channel.Channel.ChannelType;
import controller.channel.ChannelEvent;
import controller.channel.ChannelEventListener;
@@ -33,6 +32,7 @@ import org.slf4j.LoggerFactory;
import playlist.version1.PlaylistConverterV1ToV2;
import properties.SystemProperties;
import sample.Listener;
import util.ThreadPool;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -51,7 +51,6 @@ public class PlaylistManager implements ChannelEventListener
{
private final static Logger mLog = LoggerFactory.getLogger(PlaylistManager.class);
private ThreadPoolManager mThreadPoolManager;
private AliasModel mAliasModel;
private BroadcastModel mBroadcastModel;
private ChannelModel mChannelModel;
@@ -72,16 +71,10 @@ public class PlaylistManager implements ChannelEventListener
* Monitors playlist changes to automatically save configuration changes
* after they occur.
*
* @param threadPoolManager
* @param channelModel
*/
public PlaylistManager(ThreadPoolManager threadPoolManager,
AliasModel aliasModel,
BroadcastModel broadcastModel,
ChannelModel channelModel,
ChannelMapModel channelMapModel)
public PlaylistManager(AliasModel aliasModel, BroadcastModel broadcastModel, ChannelModel channelModel, ChannelMapModel channelMapModel)
{
mThreadPoolManager = threadPoolManager;
mAliasModel = aliasModel;
mBroadcastModel = broadcastModel;
mChannelModel = channelModel;
@@ -421,7 +414,7 @@ public class PlaylistManager implements ChannelEventListener
{
if(mPlaylistSavePending.compareAndSet(false, true))
{
mThreadPoolManager.scheduleOnce(new PlaylistSaveTask(), 2, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(new PlaylistSaveTask(), 2, TimeUnit.SECONDS);
}
}
}

View File

@@ -20,11 +20,11 @@ package properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import util.ThreadPool;
import java.awt.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -34,8 +34,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -54,7 +52,6 @@ public class SystemProperties
private Path mPropertiesPath;
private String mApplicationName;
private AtomicBoolean mSavePending = new AtomicBoolean();
private ScheduledExecutorService mScheduledExecutorService;
private SystemProperties()
{
@@ -83,12 +80,7 @@ public class SystemProperties
{
if(mSavePending.compareAndSet(false, true))
{
if(mScheduledExecutorService == null)
{
mScheduledExecutorService = Executors.newScheduledThreadPool(1);
}
mScheduledExecutorService.schedule(new SavePropertiesTask(), 2, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(new SavePropertiesTask(), 2, TimeUnit.SECONDS);
}
}

View File

@@ -19,13 +19,13 @@ package record;
import audio.AudioPacket;
import channel.metadata.Metadata;
import controller.ThreadPoolManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import record.wave.ComplexBufferWaveRecorder;
import record.wave.RealBufferWaveRecorder;
import sample.Listener;
import util.ThreadPool;
import java.io.File;
import java.util.HashMap;
@@ -39,22 +39,18 @@ public class RecorderManager implements Listener<AudioPacket>
private Map<String,RealBufferWaveRecorder> mRecorders = new HashMap<>();
private ThreadPoolManager mThreadPoolManager;
private boolean mCanStartNewRecorders = true;
/**
* Manages all audio recording for all processing channels. Reconstructs audio streams and distributes channel
* audio to each of the recorders, starting and stopping the recorders as needed.
*/
public RecorderManager(ThreadPoolManager threadPoolManager)
public RecorderManager()
{
mThreadPoolManager = threadPoolManager;
}
public void dispose()
{
mThreadPoolManager = null;
}
@Override
@@ -91,7 +87,7 @@ public class RecorderManager implements Listener<AudioPacket>
{
recorder = new RealBufferWaveRecorder(AUDIO_SAMPLE_RATE, filePrefix);
recorder.start(mThreadPoolManager.getScheduledExecutorService());
recorder.start(ThreadPool.SCHEDULED);
recorder.receive(audioPacket.getAudioBuffer());
mRecorders.put(identifier, recorder);

View File

@@ -19,37 +19,15 @@
package record.mp3;
import audio.AudioPacket;
import audio.IAudioPacketListener;
import audio.broadcast.BroadcastModel;
import audio.convert.MP3AudioConverter;
import module.Module;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import properties.SystemProperties;
import record.AudioRecorder;
import record.wave.AudioPacketMonoWaveReader;
import sample.Listener;
import util.TimeStamp;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
/**
* MP3 recorder for converting 8 kHz PCM audio packets to MP3 and writing to .mp3 file.

View File

@@ -17,7 +17,6 @@
******************************************************************************/
package settings;
import controller.ThreadPoolManager;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,6 +26,7 @@ import settings.ColorSetting.ColorSettingName;
import source.recording.RecordingConfiguration;
import source.tuner.configuration.TunerConfigurationEvent;
import source.tuner.configuration.TunerConfigurationModel;
import util.ThreadPool;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -54,18 +54,15 @@ public class SettingsManager implements Listener<TunerConfigurationEvent>
private Settings mSettings = new Settings();
private List<SettingChangeListener> mListeners = new ArrayList<>();
private TunerConfigurationModel mTunerConfigurationModel;
private ThreadPoolManager mThreadPoolManager;
private boolean mLoadingSettings = false;
private AtomicBoolean mSettingsSavePending = new AtomicBoolean();
public SettingsManager(ThreadPoolManager threadPoolManager,
TunerConfigurationModel tunerConfigurationModel)
public SettingsManager(TunerConfigurationModel tunerConfigurationModel)
{
//TODO: move settings into a SettingsModel
//and update this class to only provide loading, saving, and model
//change detection producing a save.
mThreadPoolManager = threadPoolManager;
mTunerConfigurationModel = tunerConfigurationModel;
//Register for tuner config events so that we can save the settings
@@ -481,8 +478,7 @@ public class SettingsManager implements Listener<TunerConfigurationEvent>
{
if(mSettingsSavePending.compareAndSet(false, true))
{
mThreadPoolManager.scheduleOnce(new SettingsSaveTask(),
2, TimeUnit.SECONDS);
ThreadPool.SCHEDULED.schedule(new SettingsSaveTask(), 2, TimeUnit.SECONDS);
}
}
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package source;
@@ -24,7 +25,6 @@ import source.mixer.MixerManager;
import source.recording.RecordingSourceManager;
import source.tuner.TunerManager;
import source.tuner.TunerModel;
import controller.ThreadPoolManager;
public class SourceManager
{
@@ -33,14 +33,12 @@ public class SourceManager
private TunerManager mTunerManager;
private TunerModel mTunerModel;
public SourceManager( TunerModel tunerModel,
SettingsManager settingsManager,
ThreadPoolManager threadPoolManager )
public SourceManager(TunerModel tunerModel, SettingsManager settingsManager)
{
mTunerModel = tunerModel;
mMixerManager = new MixerManager();
mRecordingSourceManager = new RecordingSourceManager(settingsManager);
mTunerManager = new TunerManager( mMixerManager, tunerModel, threadPoolManager );
mTunerManager = new TunerManager(mMixerManager, tunerModel);
//TODO: change mixer & recording managers to be models and hand them
//in via the constructor. Perform loading outside of this class.

View File

@@ -17,18 +17,12 @@
******************************************************************************/
package source.tuner;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import dsp.filter.FilterFactory;
import dsp.filter.Window.WindowType;
import dsp.filter.cic.ComplexPrimeCICDecimate;
import dsp.mixer.Oscillator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sample.Buffer;
import sample.Listener;
import sample.complex.Complex;
@@ -38,10 +32,15 @@ import source.SourceException;
import source.tuner.frequency.FrequencyChangeEvent;
import source.tuner.frequency.FrequencyChangeEvent.Event;
import source.tuner.frequency.IFrequencyChangeProcessor;
import dsp.filter.FilterFactory;
import dsp.filter.Window.WindowType;
import dsp.filter.cic.ComplexPrimeCICDecimate;
import dsp.mixer.Oscillator;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
public class TunerChannelSource extends ComplexSource
implements IFrequencyChangeProcessor, Listener<ComplexBuffer>
@@ -172,14 +171,14 @@ public class TunerChannelSource extends ComplexSource
{
/* Tell the tuner to release/unregister our resources */
mTuner.getTunerController().removeListener(this);
mTuner = null;
mTunerChannel = null;
mBuffer = null;
mFrequencyChangeProcessor = null;
mListener = null;
mMixer = null;
mDecimationFilter.dispose();
mDecimationFilter = null;
// mTuner = null;
// mTunerChannel = null;
// mBuffer = null;
// mFrequencyChangeProcessor = null;
// mListener = null;
// mMixer = null;
// mDecimationFilter.dispose();
// mDecimationFilter = null;
}
}
@@ -330,8 +329,6 @@ public class TunerChannelSource extends ComplexSource
if(mProcessing)
{
{
// long start = System.currentTimeMillis();
mBuffer.drainTo(mSampleBuffers, 8);
for(Buffer buffer : mSampleBuffers)
@@ -363,15 +360,14 @@ public class TunerChannelSource extends ComplexSource
samples[x], samples[x + 1], mMixer.inphase(), mMixer.quadrature());
}
if( mProcessing && mDecimationFilter != null )
if(mProcessing)
{
mDecimationFilter.receive( new ComplexBuffer( translated ) );
final ComplexPrimeCICDecimate filter = mDecimationFilter;
filter.receive(new ComplexBuffer(translated));
}
}
}
// mLog.debug( "Processed [" + mSampleBuffers.size() + "] in " + ( System.currentTimeMillis() - start ) );
mSampleBuffers.clear();
}
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 Dennis Sheirer
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,18 +14,16 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package source.tuner;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Device;
import org.usb4java.DeviceDescriptor;
import org.usb4java.DeviceList;
import org.usb4java.LibUsb;
import source.SourceException;
import source.mixer.MixerManager;
import source.tuner.airspy.AirspyTuner;
@@ -39,7 +37,8 @@ import source.tuner.rtl.RTL2832Tuner;
import source.tuner.rtl.RTL2832TunerController;
import source.tuner.rtl.e4k.E4KTunerController;
import source.tuner.rtl.r820t.R820TTunerController;
import controller.ThreadPoolManager;
import java.util.Collection;
public class TunerManager
{
@@ -48,15 +47,11 @@ public class TunerManager
private MixerManager mMixerManager;
private TunerModel mTunerModel;
private ThreadPoolManager mThreadPoolManager;
public TunerManager( MixerManager mixerManager,
TunerModel tunerModel,
ThreadPoolManager threadPoolManager )
public TunerManager(MixerManager mixerManager, TunerModel tunerModel)
{
mMixerManager = mixerManager;
mTunerModel = tunerModel;
mThreadPoolManager = threadPoolManager;
initTuners();
}
@@ -214,8 +209,7 @@ public class TunerManager
{
try
{
AirspyTunerController airspyController =
new AirspyTunerController( device, mThreadPoolManager );
AirspyTunerController airspyController = new AirspyTunerController(device);
airspyController.init();
@@ -233,7 +227,6 @@ public class TunerManager
}
private TunerInitStatus initEttusB100Tuner(Device device,
DeviceDescriptor descriptor)
{
@@ -323,9 +316,7 @@ public class TunerManager
{
try
{
HackRFTunerController hackRFController =
new HackRFTunerController( device, descriptor,
mThreadPoolManager );
HackRFTunerController hackRFController = new HackRFTunerController(device, descriptor);
hackRFController.init();
@@ -368,33 +359,27 @@ public class TunerManager
case ELONICS_E4000:
try
{
E4KTunerController controller =
new E4KTunerController( device, deviceDescriptor,
mThreadPoolManager );
E4KTunerController controller = new E4KTunerController(device, deviceDescriptor);
controller.init();
RTL2832Tuner rtlTuner =
new RTL2832Tuner( tunerClass, controller );
RTL2832Tuner rtlTuner = new RTL2832Tuner(tunerClass, controller);
return new TunerInitStatus(rtlTuner, "LOADED");
}
catch(SourceException se)
{
return new TunerInitStatus( null, "Error constructing E4K tuner "
+ "controller - " + se.getLocalizedMessage() );
return new TunerInitStatus(null, "Error constructing E4K tuner controller - " +
se.getLocalizedMessage());
}
case RAFAELMICRO_R820T:
try
{
R820TTunerController controller =
new R820TTunerController( device, deviceDescriptor,
mThreadPoolManager );
R820TTunerController controller = new R820TTunerController(device, deviceDescriptor);
controller.init();
RTL2832Tuner rtlTuner =
new RTL2832Tuner( tunerClass, controller );
RTL2832Tuner rtlTuner = new RTL2832Tuner(tunerClass, controller);
return new TunerInitStatus(rtlTuner, "LOADED");
}

View File

@@ -1,5 +1,25 @@
package source.tuner.airspy;
import dsp.filter.dc.DCRemovalFilter_RB;
import dsp.filter.hilbert.HilbertTransform;
import org.apache.commons.io.EndianUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Device;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;
import org.usb4java.Transfer;
import org.usb4java.TransferCallback;
import sample.Broadcaster;
import sample.Listener;
import sample.complex.ComplexBuffer;
import source.SourceException;
import source.tuner.TunerController;
import source.tuner.configuration.TunerConfiguration;
import util.ThreadPool;
import javax.usb.UsbException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.text.DecimalFormat;
@@ -11,32 +31,9 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.usb.UsbException;
import org.apache.commons.io.EndianUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Device;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;
import org.usb4java.Transfer;
import org.usb4java.TransferCallback;
import sample.Broadcaster;
import sample.Listener;
import sample.complex.ComplexBuffer;
import source.SourceException;
import source.tuner.TunerController;
import source.tuner.configuration.TunerConfiguration;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
import dsp.filter.dc.DCRemovalFilter_RB;
import dsp.filter.hilbert.HilbertTransform;
/**
* SDR Trunk
* Copyright (C) 2015-2016 Dennis Sheirer
* Copyright (C) 2015-2017 Dennis Sheirer
*
* Ported from libairspy at:
* https://github.com/airspy/host/tree/master/libairspy
@@ -113,15 +110,12 @@ public class AirspyTunerController extends TunerController
public static final DecimalFormat MHZ_FORMATTER = new DecimalFormat("#.00 MHz");
private final static Logger mLog =
LoggerFactory.getLogger( AirspyTunerController.class );
private final static Logger mLog = LoggerFactory.getLogger(AirspyTunerController.class);
private Device mDevice;
private DeviceHandle mDeviceHandle;
private ThreadPoolManager mThreadPoolManager;
private LinkedTransferQueue<byte[]> mFilledBuffers =
new LinkedTransferQueue<byte[]>();
private LinkedTransferQueue<byte[]> mFilledBuffers = new LinkedTransferQueue<byte[]>();
private Broadcaster<ComplexBuffer> mComplexBufferBroadcaster = new Broadcaster<>();
private int mBufferSize = 262144;
private BufferProcessor mBufferProcessor = new BufferProcessor();
@@ -133,13 +127,11 @@ public class AirspyTunerController extends TunerController
private List<AirspySampleRate> mSampleRates = new ArrayList<>();
private int mSampleRate = 0;
public AirspyTunerController( Device device, ThreadPoolManager threadPoolManager )
throws SourceException
public AirspyTunerController(Device device) throws SourceException
{
super(FREQUENCY_MIN, FREQUENCY_MAX, 0, USABLE_BANDWIDTH_PERCENT);
mDevice = device;
mThreadPoolManager = threadPoolManager;
}
public void init() throws SourceException
@@ -406,11 +398,9 @@ public class AirspyTunerController extends TunerController
* available sample rates map
*
* @param rate to a sample rate in the available samples rates map.
*
* @throws IllegalArgumentException if index is not a valid rate index
* @throws LibUsbException if there was a read error or if this operation
* is not supported by the current firmware
*
* @throws UsbException if there was a USB error
*/
public void setSampleRate(AirspySampleRate rate) throws
@@ -473,7 +463,6 @@ public class AirspyTunerController extends TunerController
* into 3 bytes (enabled) or 4 bytes (disabled).
*
* @param enabled
*
* @throws UsbException if sample packing is not supported by the current
* device firmware or if there were usb communication issues
*/
@@ -496,7 +485,6 @@ public class AirspyTunerController extends TunerController
* Enables/disables the mixer automatic gain setting
*
* @param enabled
*
* @throws LibUsbException on unsuccessful read operation
* @throws UsbException on USB error
*/
@@ -515,7 +503,6 @@ public class AirspyTunerController extends TunerController
* Enables/disables the low noise amplifier automatic gain setting
*
* @param enabled
*
* @throws LibUsbException on unsuccessful read operation
* @throws UsbException on USB error
*/
@@ -545,7 +532,6 @@ public class AirspyTunerController extends TunerController
* Sets LNA gain
*
* @param gain - value within range of LNA_GAIN_MIN to LNA_GAIN_MAX
*
* @throws LibUsbException on error in java USB wrapper
* @throws UsbException on error in USB transfer
* @throws IllegalArgumentException if gain value is invalid
@@ -573,7 +559,6 @@ public class AirspyTunerController extends TunerController
* Sets Mixer gain
*
* @param gain - value within range of MIXER_GAIN_MIN to MIXER_GAIN_MAX
*
* @throws LibUsbException on error in java USB wrapper
* @throws UsbException on error in USB transfer
* @throws IllegalArgumentException if gain value is invalid
@@ -601,7 +586,6 @@ public class AirspyTunerController extends TunerController
* Sets IF (VGA) gain
*
* @param gain - value within range of VGA_GAIN_MIN to VGA_GAIN_MAX
*
* @throws LibUsbException on error in java USB wrapper
* @throws UsbException on error in USB transfer
* @throws IllegalArgumentException if gain value is invalid
@@ -752,12 +736,9 @@ public class AirspyTunerController extends TunerController
* Reads a single byte value from the device.
*
* @param command - airspy command
*
* @param value - value field for usb setup packet
* @param index - index field for usb setup packet
*
* @return - byte value as an integer
*
* @throws LibUsbException if the operation is unsuccesful
* @throws UsbException on any usb errors
*/
@@ -807,7 +788,6 @@ public class AirspyTunerController extends TunerController
* @param index - usb packet index
* @param length - number of bytes to read
* @return - bytes read from the device
*
* @throws LibUsbException if quantity of bytes read doesn't equal the
* requested number of bytes
* @throws UsbException on error communicating with the device
@@ -1034,7 +1014,6 @@ public class AirspyTunerController extends TunerController
}
/**
* Airspy Board Identifier
*/
@@ -1285,9 +1264,8 @@ public class AirspyTunerController extends TunerController
{
prepareTransfers();
mSampleDispatcherTask = mThreadPoolManager.scheduleFixedRate(
ThreadType.SOURCE_SAMPLE_PROCESSING, new BufferDispatcher(),
20, TimeUnit.MILLISECONDS );
mSampleDispatcherTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferDispatcher(),
20, 20, TimeUnit.MILLISECONDS);
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
@@ -1309,8 +1287,7 @@ public class AirspyTunerController extends TunerController
}
else
{
mLog.error( "error submitting transfer [" +
LibUsb.errorName( result ) + "]" );
mLog.error("error submitting transfer [" + LibUsb.errorName(result) + "]");
}
}

View File

@@ -53,18 +53,6 @@
******************************************************************************/
package source.tuner.hackrf;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.usb.UsbException;
import org.apache.commons.io.EndianUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,7 +63,6 @@ import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;
import org.usb4java.Transfer;
import org.usb4java.TransferCallback;
import sample.Broadcaster;
import sample.Listener;
import sample.adapter.ByteSampleAdapter;
@@ -83,8 +70,18 @@ import sample.complex.ComplexBuffer;
import source.SourceException;
import source.tuner.TunerController;
import source.tuner.configuration.TunerConfiguration;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
import util.ThreadPool;
import javax.usb.UsbException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
public class HackRFTunerController extends TunerController
@@ -129,16 +126,13 @@ public class HackRFTunerController extends TunerController
private Device mDevice;
private DeviceDescriptor mDeviceDescriptor;
private DeviceHandle mDeviceHandle;
private ThreadPoolManager mThreadPoolManager;
public HackRFTunerController( Device device, DeviceDescriptor descriptor,
ThreadPoolManager threadPoolManager ) throws SourceException
public HackRFTunerController(Device device, DeviceDescriptor descriptor) throws SourceException
{
super(MIN_FREQUENCY, MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT);
mDevice = device;
mDeviceDescriptor = descriptor;
mThreadPoolManager = threadPoolManager;
}
public void init() throws SourceException
@@ -950,9 +944,8 @@ public class HackRFTunerController extends TunerController
{
prepareTransfers();
mSampleDispatcherTask = mThreadPoolManager.scheduleFixedRate(
ThreadType.SOURCE_SAMPLE_PROCESSING, new BufferDispatcher(),
20, TimeUnit.MILLISECONDS );
mSampleDispatcherTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferDispatcher(),
20, 20, TimeUnit.MILLISECONDS);
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);

View File

@@ -21,6 +21,27 @@
******************************************************************************/
package source.tuner.rtl;
import buffer.FloatAveragingBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Device;
import org.usb4java.DeviceDescriptor;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;
import org.usb4java.Transfer;
import org.usb4java.TransferCallback;
import sample.Broadcaster;
import sample.Listener;
import sample.adapter.ByteSampleAdapter;
import sample.complex.ComplexBuffer;
import source.SourceException;
import source.tuner.TunerController;
import source.tuner.TunerType;
import util.ThreadPool;
import javax.usb.UsbDisconnectedException;
import javax.usb.UsbException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
@@ -34,34 +55,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.usb.UsbDisconnectedException;
import javax.usb.UsbException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Device;
import org.usb4java.DeviceDescriptor;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;
import org.usb4java.Transfer;
import org.usb4java.TransferCallback;
import sample.Broadcaster;
import sample.Listener;
import sample.adapter.ByteSampleAdapter;
import sample.complex.ComplexBuffer;
import source.SourceException;
import source.tuner.TunerController;
import source.tuner.TunerType;
import buffer.FloatAveragingBuffer;
import controller.ThreadPoolManager;
import controller.ThreadPoolManager.ThreadType;
public abstract class RTL2832TunerController extends TunerController
{
private final static Logger mLog =
LoggerFactory.getLogger( RTL2832TunerController.class );
private final static Logger mLog = LoggerFactory.getLogger(RTL2832TunerController.class);
public final static int INT_NULL_VALUE = -1;
public final static long LONG_NULL_VALUE = -1l;
@@ -120,19 +116,14 @@ public abstract class RTL2832TunerController extends TunerController
public int mBufferSize = 131072;
protected Descriptor mDescriptor;
private ThreadPoolManager mThreadPoolManager;
/**
* Abstract tuner controller device. Use the static getTunerClass() method
* to determine the tuner type, and construct the corresponding child
* tuner controller class for that tuner type.
*/
public RTL2832TunerController( Device device,
DeviceDescriptor deviceDescriptor,
ThreadPoolManager threadPoolManager,
long minTunableFrequency,
long maxTunableFrequency,
int centerUnusableBandwidth,
public RTL2832TunerController(Device device, DeviceDescriptor deviceDescriptor, long minTunableFrequency,
long maxTunableFrequency, int centerUnusableBandwidth,
double usableBandwidthPercentage) throws SourceException
{
super(minTunableFrequency,
@@ -140,8 +131,6 @@ public abstract class RTL2832TunerController extends TunerController
centerUnusableBandwidth,
usableBandwidthPercentage);
mThreadPoolManager = threadPoolManager;
mDevice = device;
mDeviceDescriptor = deviceDescriptor;
}
@@ -613,6 +602,7 @@ public abstract class RTL2832TunerController extends TunerController
/**
* Enables GPIO Output
*
* @param handle - usb tuner device
* @param bitMask - mask containing one bit value in targeted bit field(s)
* @throws UsbDisconnectedException
@@ -910,7 +900,6 @@ public abstract class RTL2832TunerController extends TunerController
* Reads byte array from index at the address.
*
* @return big-endian byte array (needs to be swapped to be usable)
*
*/
protected static void read(DeviceHandle handle,
short address,
@@ -927,7 +916,6 @@ public abstract class RTL2832TunerController extends TunerController
* @param handle - handle to the usb tuner device
* @param controlI2CRepeater - indicates if the method should control the
* I2C repeater independently
*
* @return - true if the device is the specified tuner type
*/
protected static boolean isTuner(TunerTypeCheck type,
@@ -1312,6 +1300,7 @@ public abstract class RTL2832TunerController extends TunerController
/**
* Returns the sample rate that is equal to the argument or the next
* higher sample rate
*
* @param sampleRate
* @return
*/
@@ -1341,7 +1330,7 @@ public abstract class RTL2832TunerController extends TunerController
if(mBufferProcessor == null)
{
mBufferProcessor = new BufferProcessor( mThreadPoolManager );
mBufferProcessor = new BufferProcessor();
}
if(!mBufferProcessor.isRunning())
@@ -1382,13 +1371,11 @@ public abstract class RTL2832TunerController extends TunerController
private LinkedTransferQueue<Transfer> mAvailableTransfers;
private LinkedTransferQueue<Transfer> mTransfersInProgress = new LinkedTransferQueue<>();
private AtomicBoolean mRunning = new AtomicBoolean();
private ThreadPoolManager mThreadPoolManager;
private ByteBuffer mLibUsbHandlerStatus;
private boolean mCancel = false;
public BufferProcessor( ThreadPoolManager manager )
public BufferProcessor()
{
mThreadPoolManager = manager;
}
@Override
@@ -1411,16 +1398,8 @@ public abstract class RTL2832TunerController extends TunerController
prepareTransfers();
try
{
mSampleDispatcherTask = mThreadPoolManager.scheduleFixedRate(
ThreadType.SOURCE_SAMPLE_PROCESSING, new BufferDispatcher(),
20, TimeUnit.MILLISECONDS );
}
catch( NullPointerException npe )
{
mLog.error( "NPE! = tpm null: " + ( mThreadPoolManager == null ), npe );
}
mSampleDispatcherTask = ThreadPool.SCHEDULED.scheduleAtFixedRate(new BufferDispatcher(),
20, 20, TimeUnit.MILLISECONDS);
mLibUsbHandlerStatus = ByteBuffer.allocateDirect(4);
@@ -1491,7 +1470,7 @@ public abstract class RTL2832TunerController extends TunerController
{
if(mSampleDispatcherTask != null)
{
mThreadPoolManager.cancel( mSampleDispatcherTask );
mSampleDispatcherTask.cancel(true);
mSampleDispatcherTask = null;
mFilledBuffers.clear();
}
@@ -1628,10 +1607,11 @@ public abstract class RTL2832TunerController extends TunerController
}
public class USBEventHandlingThread implements Runnable
{
/** If thread should abort. */
/**
* If thread should abort.
*/
private volatile boolean mAbort;
/**
@@ -1794,6 +1774,7 @@ public abstract class RTL2832TunerController extends TunerController
}
}
}
/**
* RTL2832 EEPROM byte array descriptor parsing class
*/

View File

@@ -17,10 +17,6 @@
******************************************************************************/
package source.tuner.rtl.e4k;
import java.util.Arrays;
import javax.usb.UsbException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Device;
@@ -28,12 +24,13 @@ import org.usb4java.DeviceDescriptor;
import org.usb4java.DeviceHandle;
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;
import source.SourceException;
import source.tuner.TunerType;
import source.tuner.configuration.TunerConfiguration;
import source.tuner.rtl.RTL2832TunerController;
import controller.ThreadPoolManager;
import javax.usb.UsbException;
import java.util.Arrays;
public class E4KTunerController extends RTL2832TunerController
{
@@ -108,13 +105,9 @@ public class E4KTunerController extends RTL2832TunerController
public static final byte CHFCALIB_CMD = (byte) 0x01;
public E4KTunerController( Device device,
DeviceDescriptor deviceDescriptor,
ThreadPoolManager threadPoolManager )
throws SourceException
public E4KTunerController(Device device, DeviceDescriptor deviceDescriptor) throws SourceException
{
super( device, deviceDescriptor, threadPoolManager, MIN_FREQUENCY,
MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT );
super(device, deviceDescriptor, MIN_FREQUENCY, MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT);
}
@Override
@@ -702,6 +695,7 @@ public class E4KTunerController extends RTL2832TunerController
* Gets the enhanced gain setting in the E4K tuner.
*
* Note: requires I2C repeater
*
* @return
* @throws UsbException
*/
@@ -1432,6 +1426,7 @@ public class E4KTunerController extends RTL2832TunerController
/**
* Returns the correct filter to use for the bandwidth/sample rate
*
* @param bandwidth - current sample rate
* @return - correct filter to use for the bandwidth/sample rate
*/
@@ -1542,6 +1537,7 @@ public class E4KTunerController extends RTL2832TunerController
/**
* Returns the correct filter to use for the bandwidth/sample rate
*
* @param bandwidth - current sample rate
* @return - correct filter to use for the bandwidth/sample rate
*/
@@ -1668,6 +1664,7 @@ public class E4KTunerController extends RTL2832TunerController
/**
* Returns the correct filter to use for the bandwidth/sample rate
*
* @param bandwidth - current sample rate
* @return - correct filter to use for the bandwidth/sample rate
*/

View File

@@ -22,22 +22,19 @@
******************************************************************************/
package source.tuner.rtl.r820t;
import java.nio.ByteBuffer;
import javax.swing.JPanel;
import javax.usb.UsbException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Device;
import org.usb4java.DeviceDescriptor;
import org.usb4java.LibUsbException;
import source.SourceException;
import source.tuner.TunerType;
import source.tuner.configuration.TunerConfiguration;
import source.tuner.rtl.RTL2832TunerController;
import controller.ThreadPoolManager;
import javax.swing.*;
import javax.usb.UsbException;
import java.nio.ByteBuffer;
public class R820TTunerController extends RTL2832TunerController
{
@@ -75,13 +72,10 @@ public class R820TTunerController extends RTL2832TunerController
private JPanel mEditor;
public R820TTunerController( Device device,
DeviceDescriptor deviceDescriptor,
ThreadPoolManager threadPoolManager )
throws SourceException
public R820TTunerController(Device device, DeviceDescriptor deviceDescriptor) throws SourceException
{
super( device, deviceDescriptor, threadPoolManager, MIN_FREQUENCY,
MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER, USABLE_BANDWIDTH_PERCENT );
super(device, deviceDescriptor, MIN_FREQUENCY, MAX_FREQUENCY, DC_SPIKE_AVOID_BUFFER,
USABLE_BANDWIDTH_PERCENT);
}
@Override
@@ -561,6 +555,7 @@ public class R820TTunerController extends RTL2832TunerController
* Writes initial starting value of registers 0x05 through 0x1F using the
* default value initialized in the shadow register array. This method only
* needs to be called once, upon initialization.
*
* @throws UsbException
*/
private void initializeRegisters(boolean controlI2C) throws UsbException
@@ -1161,6 +1156,7 @@ public class R820TTunerController extends RTL2832TunerController
* Returns the correct frequency divider for the specified frequency,
* or returns divider #5, if the frequency is outside of the specified
* frequency ranges.
*
* @param frequency - desired frequency
* @return - FrequencyDivider to use for the specified frequency
*/
@@ -1231,7 +1227,6 @@ public class R820TTunerController extends RTL2832TunerController
* 8 I * 7.2 MHz
* 4 I * 14.4 MHz
* 2 I * 28.8 MHz
*
*/
public enum Integral
{

View File

@@ -18,7 +18,6 @@
******************************************************************************/
package spectrum;
import controller.NamingThreadFactory;
import dsp.filter.Window;
import dsp.filter.Window.WindowType;
import org.jtransforms.fft.FloatFFT_1D;
@@ -32,14 +31,14 @@ import sample.complex.ComplexBuffer;
import source.tuner.frequency.FrequencyChangeEvent;
import source.tuner.frequency.IFrequencyChangeProcessor;
import spectrum.converter.DFTResultsConverter;
import util.ThreadPool;
import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -60,8 +59,7 @@ public class DFTProcessor implements Listener<ComplexBuffer>, IFrequencyChangePr
//so we set it at 12.
private BlockingQueue<ComplexBuffer> mQueue = new ArrayBlockingQueue<>(12);
private ScheduledExecutorService mScheduler = Executors
.newScheduledThreadPool(1, new NamingThreadFactory("spectrum dft processor"));
private ScheduledFuture<?> mProcessorTaskHandle;
public static final String FRAME_RATE_PROPERTY = "spectral.display.frame.rate";
@@ -184,38 +182,20 @@ public class DFTProcessor implements Listener<ComplexBuffer>, IFrequencyChangePr
public void start()
{
/**
* Reset the scheduler
*/
mScheduler = Executors.newScheduledThreadPool(1, new NamingThreadFactory("spectrum dft"));
/**
* Schedule the DFT to run calculations at a fixed rate
*/
//Schedule the DFT to run calculations at a fixed rate
int initialDelay = 0;
int period = (int) (1000 / mFrameRate);
TimeUnit unit = TimeUnit.MILLISECONDS;
mScheduler.scheduleAtFixedRate(new DFTCalculationTask(),
initialDelay, period, unit);
mProcessorTaskHandle = ThreadPool.SCHEDULED.scheduleAtFixedRate(new DFTCalculationTask(), initialDelay, period,
TimeUnit.MILLISECONDS);
}
public void stop()
{
/**
* Shutdown the scheduler and clear out any remaining tasks
*/
try
//Cancel running DFT calculation task
if(mProcessorTaskHandle != null)
{
mScheduler.shutdown();
mScheduler.awaitTermination(100, TimeUnit.MILLISECONDS);
}
catch(InterruptedException e)
{
/* Do nothing ... we're shutting down */
// mLog.error( "DFTProcessor - exception while awaiting shutdown of "
// + "calculation scheduler for reset", e );
mProcessorTaskHandle.cancel(true);
}
}

54
src/util/ThreadPool.java Normal file
View File

@@ -0,0 +1,54 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
package util;
import controller.NamingThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
public class ThreadPool
{
private final static Logger mLog = LoggerFactory.getLogger(ThreadPool.class);
private static int CORES = Runtime.getRuntime().availableProcessors();
public static ScheduledExecutorService SCHEDULED;
static
{
//Create a scheduled thread pool sized according to the available processors/cores, minimum 2
CORES = (CORES < 2 ? 2 : CORES);
SCHEDULED = Executors.newScheduledThreadPool(CORES, new NamingThreadFactory("sdrtrunk"));
}
/**
* Application-wide shared thread pools and scheduled executor service.
*/
public ThreadPool()
{
}
public static void logSettings()
{
mLog.info("Application thread pool created with [" + CORES + "] threads");
}
}