Package com.tagtraum.tunes
Class TunesUtilities
- java.lang.Object
-
- com.tagtraum.tunes.TunesUtilities
-
public final class TunesUtilities extends Object
Utility class that makes it easier to obtain aTrack
object. Also allows to serialize calls to the tunes library, i.e. to iTunes.- Author:
- Hendrik Schreiber
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MultiQueueExecutor
getExecutorService()
SpecialExecutorService
for synchronizing access to external resources.static String
getPath(Track track)
static File
getPrimaryArtworkFileFromCache(File libraryXML, Long songId, Long libraryId)
static Image
getPrimaryArtworkFromCache(File libraryXML, Long songId, Long libraryId)
static Track
getTrack(Playlist playlist, AudioSong song)
Deprecated.static Track
getTrack(Playlist playlist, Long persistentId)
Deprecated.static void
interruptTunesUtilitiesThread()
CallsThread.interrupt()
on the Tunes Utilities thread.static void
invokeAndWait(Runnable runnable, long timeout, TimeUnit unit)
Executes the runnable synchronously in the TunesUtilities executor thread.static <T> T
invokeAndWait(Callable<T> callable, long timeout, TimeUnit unit)
Executes the callable synchronously in the TunesUtilities executor thread.static Future<?>
invokeLater(Runnable runnable)
Executes the runnable asynchronously in the TunesUtilities executor thread.static boolean
isInTunesUtilitiesThread()
Checks whether are already in the TunesUtilityThreadstatic boolean
isPrimaryArtworkInCache(File libraryXML, Long songId, Long libraryId)
static InputStream
openPrimaryArtworkStreamFromCache(File libraryXML, Long songId, Long libraryId)
-
-
-
Method Detail
-
getExecutorService
public static MultiQueueExecutor getExecutorService()
SpecialExecutorService
for synchronizing access to external resources. This service is typically single threaded.Note that the simpler methods like
ExecutorService.submit(Runnable)
,Executor.execute(Runnable)
orExecutorService.submit(Callable)
execute runnables and callables out of order, if you are already in the executor's thread. In other words, typically tasks are queued (i.e. executed in order), but when you are already in the executor thread, your task is executed right away (i.e. executed out of order).- Returns:
- executor service
-
getTrack
@Deprecated public static Track getTrack(Playlist playlist, AudioSong song)
Deprecated.Attempts to get aTrack
object from the given playlist for the given song. Will be deleted in beaTunes 6.- Parameters:
playlist
- playlist to search insong
- song to search for- Returns:
- track for the given song
-
getTrack
@Deprecated public static Track getTrack(Playlist playlist, Long persistentId)
Deprecated.Will be deleted in beaTunes 6.- See Also:
ITunes.getTrack(long)
,Playlist.getTrack(long)
-
invokeLater
public static Future<?> invokeLater(Runnable runnable)
Executes the runnable asynchronously in the TunesUtilities executor thread.- Parameters:
runnable
- runnable- Returns:
- future
-
isInTunesUtilitiesThread
public static boolean isInTunesUtilitiesThread()
Checks whether are already in the TunesUtilityThread- Returns:
- true or false
-
interruptTunesUtilitiesThread
public static void interruptTunesUtilitiesThread()
CallsThread.interrupt()
on the Tunes Utilities thread.
-
invokeAndWait
public static void invokeAndWait(Runnable runnable, long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException
Executes the runnable synchronously in the TunesUtilities executor thread. If a timeout occurs, the TunesUtilities executor thread is automatically interrupted.- Parameters:
runnable
- runnabletimeout
- timeoutunit
- unit for the timeout- Throws:
InterruptedException
- when interruptedExecutionException
- if the execution leads to some sort exceptionTimeoutException
-
invokeAndWait
public static <T> T invokeAndWait(Callable<T> callable, long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException
Executes the callable synchronously in the TunesUtilities executor thread. If a timeout occurs, the TunesUtilities executor thread is automatically interrupted.- Parameters:
callable
- callabletimeout
- timeoutunit
- unit for the timeout- Throws:
InterruptedException
- when interruptedExecutionException
- if the execution leads to some sort exceptionTimeoutException
-
getPath
public static String getPath(Track track)
- Parameters:
track
- track- Returns:
- location that is guaranteed to start with a slash
-
openPrimaryArtworkStreamFromCache
public static InputStream openPrimaryArtworkStreamFromCache(File libraryXML, Long songId, Long libraryId)
-
isPrimaryArtworkInCache
public static boolean isPrimaryArtworkInCache(File libraryXML, Long songId, Long libraryId)
-
getPrimaryArtworkFileFromCache
public static File getPrimaryArtworkFileFromCache(File libraryXML, Long songId, Long libraryId)
-
-