mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Updates PlaylistManager to use faster jackson XML serialization.
Removes native xml.bind serialization for improved compatibility with Java 9. Global optimize imports on the entire project.
This commit is contained in:
@@ -18,41 +18,48 @@
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.alias.action;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.alias.action.beep.BeepAction;
|
||||
import io.github.dsheirer.alias.action.clip.ClipAction;
|
||||
import io.github.dsheirer.alias.action.script.ScriptAction;
|
||||
import io.github.dsheirer.message.Message;
|
||||
import io.github.dsheirer.alias.action.beep.BeepAction;
|
||||
|
||||
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.
|
||||
*/
|
||||
@XmlSeeAlso( { BeepAction.class, ClipAction.class, ScriptAction.class } )
|
||||
@XmlRootElement( name = "action" )
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = BeepAction.class, name="beepAction"),
|
||||
@JsonSubTypes.Type(value = ClipAction.class, name = "clipAction"),
|
||||
@JsonSubTypes.Type(value = RecurringAction.class, name = "recurringAction"),
|
||||
@JsonSubTypes.Type(value = ScriptAction.class, name = "scriptAction")
|
||||
})
|
||||
@JacksonXmlRootElement(localName = "action")
|
||||
public abstract class AliasAction
|
||||
{
|
||||
public AliasAction()
|
||||
{
|
||||
}
|
||||
public AliasAction()
|
||||
{
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public abstract AliasActionType getType();
|
||||
|
||||
/**
|
||||
* Task to execute when an alias action is defined. The message argument is
|
||||
* the original message containing one or more aliases that have an alias
|
||||
* action attached. The alias argument is the parent alias containing the
|
||||
* alias action.
|
||||
*/
|
||||
public abstract void execute(ScheduledExecutorService scheduledExecutorService, Alias alias, Message message );
|
||||
@JsonIgnore
|
||||
public abstract AliasActionType getType();
|
||||
|
||||
/**
|
||||
* Dismiss a persistent alias action
|
||||
*/
|
||||
public abstract void dismiss( boolean reset );
|
||||
/**
|
||||
* Task to execute when an alias action is defined. The message argument is
|
||||
* the original message containing one or more aliases that have an alias
|
||||
* action attached. The alias argument is the parent alias containing the
|
||||
* alias action.
|
||||
*/
|
||||
public abstract void execute(ScheduledExecutorService scheduledExecutorService, Alias alias, Message message);
|
||||
|
||||
/**
|
||||
* Dismiss a persistent alias action
|
||||
*/
|
||||
public abstract void dismiss(boolean reset);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
package io.github.dsheirer.alias.action;
|
||||
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.gui.editor.Editor;
|
||||
import io.github.dsheirer.gui.editor.EmptyEditor;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import io.github.dsheirer.alias.AliasEvent;
|
||||
import io.github.dsheirer.alias.AliasEvent.Event;
|
||||
import io.github.dsheirer.alias.AliasFactory;
|
||||
import io.github.dsheirer.alias.AliasModel;
|
||||
import io.github.dsheirer.gui.editor.Editor;
|
||||
import io.github.dsheirer.gui.editor.EmptyEditor;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package io.github.dsheirer.alias.action;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.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;
|
||||
@@ -14,11 +14,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public abstract class RecurringAction extends AliasAction
|
||||
{
|
||||
@XmlTransient
|
||||
@JsonIgnore
|
||||
protected AtomicBoolean mRunning = new AtomicBoolean(false);
|
||||
@XmlTransient
|
||||
@JsonIgnore
|
||||
private ScheduledFuture<?> mPerpetualAction;
|
||||
@XmlTransient
|
||||
@JsonIgnore
|
||||
protected ScheduledExecutorService mScheduledExecutorService;
|
||||
|
||||
protected Interval mInterval = Interval.ONCE;
|
||||
@@ -107,7 +107,7 @@ public abstract class RecurringAction extends AliasAction
|
||||
}
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "period")
|
||||
public int getPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
@@ -118,7 +118,7 @@ public abstract class RecurringAction extends AliasAction
|
||||
mPeriod = period;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "interval")
|
||||
public Interval getInterval()
|
||||
{
|
||||
return mInterval;
|
||||
@@ -164,8 +164,8 @@ public abstract class RecurringAction extends AliasAction
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
/* Don't use the performThreadedAction() method, since this is
|
||||
* already running in a separate thread */
|
||||
/* Don't use the performThreadedAction() method, since this is
|
||||
* already running in a separate thread */
|
||||
performAction(mAlias, mMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.dsheirer.alias.action.beep;
|
||||
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.alias.action.AliasActionType;
|
||||
import io.github.dsheirer.alias.action.RecurringAction;
|
||||
@@ -8,6 +9,7 @@ import io.github.dsheirer.message.Message;
|
||||
public class BeepAction extends RecurringAction
|
||||
{
|
||||
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance")
|
||||
@Override
|
||||
public AliasActionType getType()
|
||||
{
|
||||
|
||||
@@ -1,107 +1,109 @@
|
||||
package io.github.dsheirer.alias.action.clip;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.alias.action.AliasActionType;
|
||||
import io.github.dsheirer.alias.action.RecurringAction;
|
||||
import io.github.dsheirer.message.Message;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import io.github.dsheirer.alias.action.RecurringAction;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import java.io.File;
|
||||
|
||||
public class ClipAction extends RecurringAction
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( ClipAction.class );
|
||||
private final static Logger mLog = LoggerFactory.getLogger(ClipAction.class);
|
||||
|
||||
private String mFilePath;
|
||||
private String mFilePath;
|
||||
|
||||
@XmlTransient
|
||||
private Clip mClip;
|
||||
|
||||
public ClipAction()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public AliasActionType getType()
|
||||
{
|
||||
return AliasActionType.CLIP;
|
||||
}
|
||||
@JsonIgnore
|
||||
private Clip mClip;
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return mFilePath;
|
||||
}
|
||||
|
||||
public void setPath( String path )
|
||||
{
|
||||
mFilePath = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(Alias alias, Message message )
|
||||
{
|
||||
try
|
||||
{
|
||||
play();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "Couldn't play audio clip", e );
|
||||
}
|
||||
}
|
||||
|
||||
public void play() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
if( mFilePath != null )
|
||||
{
|
||||
if( mClip == null )
|
||||
{
|
||||
mClip = AudioSystem.getClip();
|
||||
|
||||
AudioInputStream ais =
|
||||
AudioSystem.getAudioInputStream( new File( mFilePath ) );
|
||||
|
||||
mClip.open( ais );
|
||||
}
|
||||
public ClipAction()
|
||||
{
|
||||
}
|
||||
|
||||
if( mClip.isRunning() )
|
||||
{
|
||||
mClip.stop();
|
||||
}
|
||||
|
||||
mClip.setFramePosition( 0 );
|
||||
|
||||
mClip.start();
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mClip = null;
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance")
|
||||
@Override
|
||||
public AliasActionType getType()
|
||||
{
|
||||
return AliasActionType.CLIP;
|
||||
}
|
||||
|
||||
mLog.error( "Error playing sound clip [" + mFilePath + "] - " + e.getMessage() );
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return mFilePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if( mFilePath == null )
|
||||
{
|
||||
return "Play Clip";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Play Clip: " + mFilePath;
|
||||
}
|
||||
}
|
||||
public void setPath(String path)
|
||||
{
|
||||
mFilePath = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(Alias alias, Message message)
|
||||
{
|
||||
try
|
||||
{
|
||||
play();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't play audio clip", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void play() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
if(mFilePath != null)
|
||||
{
|
||||
if(mClip == null)
|
||||
{
|
||||
mClip = AudioSystem.getClip();
|
||||
|
||||
AudioInputStream ais =
|
||||
AudioSystem.getAudioInputStream(new File(mFilePath));
|
||||
|
||||
mClip.open(ais);
|
||||
}
|
||||
|
||||
if(mClip.isRunning())
|
||||
{
|
||||
mClip.stop();
|
||||
}
|
||||
|
||||
mClip.setFramePosition(0);
|
||||
|
||||
mClip.start();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mClip = null;
|
||||
|
||||
mLog.error("Error playing sound clip [" + mFilePath + "] - " + e.getMessage());
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(mFilePath == null)
|
||||
{
|
||||
return "Play Clip";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Play Clip: " + mFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +1,98 @@
|
||||
package io.github.dsheirer.alias.action.script;
|
||||
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.alias.action.AliasActionType;
|
||||
import io.github.dsheirer.alias.action.RecurringAction;
|
||||
import io.github.dsheirer.message.Message;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import io.github.dsheirer.alias.action.RecurringAction;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class ScriptAction extends RecurringAction
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( ScriptAction.class );
|
||||
private final static Logger mLog = LoggerFactory.getLogger(ScriptAction.class);
|
||||
|
||||
private String mScript;
|
||||
private String mScript;
|
||||
|
||||
public ScriptAction()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public AliasActionType getType()
|
||||
{
|
||||
return AliasActionType.SCRIPT;
|
||||
}
|
||||
public ScriptAction()
|
||||
{
|
||||
}
|
||||
|
||||
public String getScript()
|
||||
{
|
||||
return mScript;
|
||||
}
|
||||
|
||||
public void setScript( String script )
|
||||
{
|
||||
mScript = script;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(Alias alias, Message message )
|
||||
{
|
||||
try
|
||||
{
|
||||
play();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "Couldn't execute script [" + mScript + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
public void play() throws Exception
|
||||
{
|
||||
if( mScript != null )
|
||||
{
|
||||
ProcessBuilder pb = new ProcessBuilder( mScript );
|
||||
|
||||
pb.redirectErrorStream( true );
|
||||
@JacksonXmlProperty(isAttribute = true, localName = "type", namespace = "http://www.w3.org/2001/XMLSchema-instance")
|
||||
@Override
|
||||
public AliasActionType getType()
|
||||
{
|
||||
return AliasActionType.SCRIPT;
|
||||
}
|
||||
|
||||
Process p = pb.start();
|
||||
|
||||
int exitCode = p.waitFor();
|
||||
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader( p.getInputStream() ) );
|
||||
public String getScript()
|
||||
{
|
||||
return mScript;
|
||||
}
|
||||
|
||||
String line = "";
|
||||
public void setScript(String script)
|
||||
{
|
||||
mScript = script;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(Alias alias, Message message)
|
||||
{
|
||||
try
|
||||
{
|
||||
play();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't execute script [" + mScript + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void play() throws Exception
|
||||
{
|
||||
if(mScript != null)
|
||||
{
|
||||
ProcessBuilder pb = new ProcessBuilder(mScript);
|
||||
|
||||
pb.redirectErrorStream(true);
|
||||
|
||||
Process p = pb.start();
|
||||
|
||||
int exitCode = p.waitFor();
|
||||
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(p.getInputStream()));
|
||||
|
||||
String line = "";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
while( ( line = reader.readLine() ) != null )
|
||||
|
||||
while((line = reader.readLine()) != null)
|
||||
{
|
||||
sb.append(line + "\n");
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
|
||||
if( exitCode != 0 )
|
||||
|
||||
if(exitCode != 0)
|
||||
{
|
||||
throw new RuntimeException( "Exit Code: " + exitCode +
|
||||
" Console:" + sb.toString() );
|
||||
throw new RuntimeException("Exit Code: " + exitCode +
|
||||
" Console:" + sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if( mScript == null )
|
||||
{
|
||||
return "Run Script";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Run Script: " + mScript;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(mScript == null)
|
||||
{
|
||||
return "Run Script";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Run Script: " + mScript;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user