|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.lyra.Host.Terminus
public class Terminus
The Terminus Class deals with establishing the Multimedia Player Daemon connection. Effectively creating a terminus at our end enabling us to extract status information and control the player.
Field Summary | |
---|---|
private int |
Attempts
|
private static int |
ATTEMPTS
|
static java.lang.String |
AUDIT_ADDED
Descriptor used for the auditing of entries added to the current playlist. |
static java.lang.String |
AUDIT_REMOVED
Descriptor used for the auditing of entries removed to the current playlist. |
private static java.lang.String |
CLASS
|
private java.lang.String |
dHost
|
static java.lang.String |
DIRECTORY
Part of the protocol which is normally ignored by this application. |
private java.lang.String |
dPass
|
private java.lang.Integer |
dPort
|
private java.net.Socket |
dSocket
|
private static java.lang.String |
ENCODING
|
private static java.util.List<Terminus> |
Instances
|
private Ledger |
Logger
|
static int |
MAX_COL
In multiple reply key/pair elements, this defines how many splits can be accomplished. |
private LossListener |
mySource
|
static java.lang.String |
PLAYLIST
Part of the stored playlist listing which defines a new playlist. |
static java.util.Map<java.lang.String,java.lang.String> |
PROTOCOL
The protocol is well defined, however in order to reduce changes to the code if there are changes in the future they have been embedded into a HashMap. |
static java.util.TreeSet<java.lang.String> |
ROW_ALLOW
Certain elements of song information may fall outside what the database allows. |
static java.util.TreeSet<java.lang.String> |
ROW_REQUIRED
Certain elements are required by the database. |
static java.lang.String |
SECTION
Part of the protocol which defines a new song entry. |
static java.lang.String |
SEPARATOR
Separator for key/pair elements. |
private java.io.BufferedReader |
sIn
|
private java.io.PrintWriter |
sOut
|
static java.lang.String |
STATE_PAUSE
Descriptor which applies to the daemon state when playback is paused. |
static java.lang.String |
STATE_PLAY
Descriptor which applies to the daemon state when playback is started. |
static java.lang.String |
STATE_STOP
Descriptor which applies to the daemon state when playback has stopped. |
static java.lang.String |
UNIQUE
Rarely used but at times its useful to know what makes a song set unique which is the existence of the File identifier. |
static java.util.Map<java.lang.String,java.lang.String> |
UPDATES
Holds the update elements and uses terminology that is hopefully less confusing and consistent with the application. |
static java.lang.String |
UPDATING
Element that should never be found when doing a host database synch with our own store. |
Constructor Summary | |
---|---|
Terminus(Ledger logger,
java.lang.String host,
java.lang.String port,
java.lang.String pass)
Constructor for the class, requires the provision of information related to the host and an optional password. |
|
Terminus(Ledger logger,
java.lang.String host,
java.lang.String port,
java.lang.String pass,
LossListener source)
Constructor for the class, requires the provision of information related to the host and an optional password. |
Method Summary | |
---|---|
boolean |
Connect()
As the name implies, deals with the connection to the host establishing a socket and permitting command/status information to be passed from connection onward. |
void |
Disconnect()
Prior to exiting we close the connection properly and clean up all memory handles. |
void |
hostLost(LossEvent e)
Notifies a client that the connection to the Music Player Daemon (MPD) has been interrupted. |
private java.lang.String |
readChannel()
It was discovered that channels would return a NullPointerException when the channel is not properly closed such as when the computer is suspended. |
java.lang.String |
readLine()
Basic reading method used to extract a single row of information. |
java.util.List<java.lang.String> |
readList()
Basic reading method used to extract all information. |
java.util.List<java.lang.String> |
readList(int col)
The main readList() method does not parse the line as it is extracted from the socket. |
java.util.Map<java.lang.String,java.lang.String> |
readMap()
Reads and parses the returned input treating it as a Key/Pair structure which is returned by elements like STATS and STATUS of the MPD protocol. |
boolean |
readResult()
This method is used primarily in circumstances where bulk entries are dropped into place. |
private boolean |
readResult(java.lang.String reply)
General method to cover the basics about reading from the protocol in order to avoid repeating the same lines everywhere. |
boolean |
Recover(java.lang.Exception e)
The recover function is used to recover from IOExceptions or NullPointerException that have been triggered. |
static boolean |
testConnect(java.lang.String host,
java.lang.Integer port)
Provides a quick and painless way of checking the connection without much overhead. |
static boolean |
testConnect(java.lang.String host,
java.lang.String port)
Provides a quick and painless way of checking the connection without much overhead. |
void |
writeArgument(java.lang.String command,
java.lang.String... args)
For more complex commands which have a requirement to pass on arguments useful when dealing with the play lists. |
void |
writeBatch(java.lang.String... command)
Method which will write a specific series of commands to the socket for processing by the host. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.String dHost
private java.lang.Integer dPort
private java.lang.String dPass
private java.net.Socket dSocket
private java.io.PrintWriter sOut
private java.io.BufferedReader sIn
private LossListener mySource
private Ledger Logger
private int Attempts
private static java.util.List<Terminus> Instances
private static final java.lang.String CLASS
private static final int ATTEMPTS
private static final java.lang.String ENCODING
public static final java.lang.String DIRECTORY
public static final java.lang.String SECTION
public static final java.lang.String SEPARATOR
public static final java.lang.String PLAYLIST
public static final int MAX_COL
public static final java.lang.String UNIQUE
public static final java.lang.String UPDATING
public static final java.util.TreeSet<java.lang.String> ROW_ALLOW
public static final java.util.TreeSet<java.lang.String> ROW_REQUIRED
public static final java.util.Map<java.lang.String,java.lang.String> PROTOCOL
public static final java.util.Map<java.lang.String,java.lang.String> UPDATES
public static final java.lang.String STATE_PLAY
public static final java.lang.String STATE_PAUSE
public static final java.lang.String STATE_STOP
public static final java.lang.String AUDIT_ADDED
public static final java.lang.String AUDIT_REMOVED
Constructor Detail |
---|
public Terminus(Ledger logger, java.lang.String host, java.lang.String port, java.lang.String pass)
logger
- Ledger instance for logging of faults.host
- String containing host name or IP address.port
- String containing the port number.pass
- String containing the optional password.public Terminus(Ledger logger, java.lang.String host, java.lang.String port, java.lang.String pass, LossListener source)
logger
- Ledger instance for logging of faults.host
- String containing host name or IP address.port
- String containing the port number.pass
- String containing the optional password.source
- LossListener instance to inform up the chain.Method Detail |
---|
public boolean Connect()
public void Disconnect()
public boolean Recover(java.lang.Exception e)
e
- Exception received and handled.
private boolean readResult(java.lang.String reply) throws java.io.IOException
reply
- Reply received from the host.
java.io.IOException
private java.lang.String readChannel() throws java.io.IOException
java.io.IOException
public static boolean testConnect(java.lang.String host, java.lang.Integer port)
host
- String containing host element.port
- Integer containing host element.
public static boolean testConnect(java.lang.String host, java.lang.String port)
host
- String containing host element.port
- String containing host element.
public java.lang.String readLine() throws java.io.IOException
java.io.IOException
public java.util.List<java.lang.String> readList() throws java.io.IOException
java.io.IOException
public java.util.List<java.lang.String> readList(int col) throws java.io.IOException
col
- Returns elements at specified integer.
java.io.IOException
public java.util.Map<java.lang.String,java.lang.String> readMap() throws java.io.IOException
java.io.IOException
public boolean readResult() throws java.io.IOException, java.lang.NullPointerException
java.io.IOException
java.lang.NullPointerException
public void writeArgument(java.lang.String command, java.lang.String... args)
command
- String containing completed command.args
- String array containing arguments to pass.public void writeBatch(java.lang.String... command)
command
- String array of commands which will be sent.public void hostLost(LossEvent e)
LossListener
hostLost
in interface LossListener
e
- Update notification method.UpdateEvent
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |