Class AbstractMediaLibrary<T extends ApplicationComponent>
- java.lang.Object
-
- com.tagtraum.beatunes.library.AbstractMediaLibrary<T>
-
- All Implemented Interfaces:
MediaLibrary
,ApplicationComponent<T>
- Direct Known Subclasses:
HibernateMediaLibrary
public abstract class AbstractMediaLibrary<T extends ApplicationComponent> extends Object implements MediaLibrary, ApplicationComponent<T>
Abstract media library.- Author:
- Hendrik Schreiber
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
AUTO_DETECT_ITUNESLIBRARY
protected File
databaseDir
protected PropertyChangeSupport
propertyChangeSupport
protected static long
TEN_MINUTES
protected static int
TOTALTIME_DEVIATION
protected MediaLibrary
wrappingProxy
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMediaLibrary(T application)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addMediaLibraryListener(MediaLibraryListener listener)
void
addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
void
addPropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
void
cancelSynchronization()
Cancels any ongoing synchronization.protected void
fireAsynchronousSynchronizationEvent()
protected void
fireLibrarySynchronizedEvent(MediaLibraryEvent event)
protected void
fireSynchronousSynchronizationEvent()
T
getApplication()
Returns the main application component.ExecutorService
getAudioMetaDataExecutor()
Returns en executor service that should be used for any write access toAudioMetaData
related tasks.GenreIRILookupService
getGenreIRILookupService()
Returns current genre IRI lookup service.<T> T
getImplementation(Class<T> klass)
long
getLastSynchronizationTimestamp()
Timestamp of last synchronization of the current library.LibraryDescriptor
getLibraryDescriptor()
Returns the library descriptor.protected abstract LibraryLoader
getLibraryLoader()
ReentrantLock
getLock(Long songId)
Provides a lock object for a song id.PlayList
getPlayList(long id)
Get aPlayList
for an id.long
getPreviousToLastSynchronizationTimestamp()
Timestamp of the previous to last synchronization of the current library.PropertyChangeListener[]
getPropertyChangeListeners()
PropertyChangeListener[]
getPropertyChangeListeners(String property)
Set<Long>
getSongIds(PlayList.Kind... kinds)
Returns all ids that are in the given set ofPlayList.Kind
s.Iterable<AudioSong>
getSongs()
Returns anIterable
that can be used to iterate over all songs.Iterable<AudioSong>
getSongsOrderedBy(String sortProperty, PlayList.SortDirection direction)
Returns anIterable
that can be used to iterate over all songs.Iterable<AudioSong>
getSongsOrderedBy(String sortProperty, PlayList.SortDirection direction, int limit)
Returns anIterable
that can be used to iterate over all songs.ITunes
getTunes()
Returns the currently associated audio player, probably iTunes.MultiQueueExecutor
getTunesExecutor()
Returns en executor service that should be used for any write access toITunes
related tasks.MediaLibraryUIDelegate
getUIDelegate()
MediaLibrary
getWrappingProxy()
WrappingProxyFactory
getWrappingProxyFactory()
boolean
isEmbedAudioMetaData()
Shall all data be embedded into the audio files, when writing?boolean
isForceAudioMetaDataWrites()
Shall new values always be written, even, if the old value seems to be identical? This can happen, when the internal database is out of sync with actual values in audio files or iTunes.boolean
isForceRecovery()
Is the recovery flag set?boolean
isNewDatabase()
boolean
isOneWeekOld()
protected abstract boolean
isProgressDialogVisible(boolean firstTime, boolean manuallyInitiated)
boolean
isRebuildPlayLists()
boolean
isSupportedPlayList(PlayList.Kind kind)
Indicates whether a distinguished kind ofPlayList
is supported.boolean
isSynchronizing()
Indicates, whether we are currently synchronizing.Lock
lock(Long songId)
Provides a locked lock for a song id.boolean
needsRefresh()
void
refresh()
Reloads all objects that are connected to the music library.void
refresh(boolean blockingCall, boolean manuallyInitiated, boolean full)
Reloads all objects that are connected to the music library.void
refreshOnNextUpdate()
boolean
removeMediaLibraryListener(MediaLibraryListener listener)
void
removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
void
removePropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
void
serialExecute(Runnable runnable)
Execute the runnable withMediaLibrary.getTunesExecutor()
, but not beforeMediaLibrary.getAudioMetaDataExecutor()
has run through.<V> V
serialExecute(Callable<V> callable)
Execute the callable withMediaLibrary.getTunesExecutor()
, but not beforeMediaLibrary.getAudioMetaDataExecutor()
has run through.void
setApplication(T application)
Sets the main application component.void
setDatabaseDir(File databaseDir)
void
setEmbedAudioMetaData(boolean embedAudioMetaData)
Shall all data be embedded into audio files or just those fields that are supported by iTunes.void
setForceAudioMetaDataWrites(boolean forceAudioMetaDataWrites)
Shall new values always be written, even, if the old value seems to be identical? This can happen, when the internal database is out of sync with actual values in audio files or iTunes.void
setGenreIRILookupService(GenreIRILookupService service)
Lets you set theGenreIRILookupService
.void
setLibraryDescriptor(LibraryDescriptor libraryDescriptor)
Sets the library descriptor.void
setNewDatabase(boolean newDatabase)
void
setRebuildPlayLists(boolean rebuildPlayLists)
If set to true, the library will attempt to re-build all playlists on nextload(boolean, boolean, boolean)
.void
setRecoveryFlag()
Call this method beforeMediaLibrary.init()
in order to force recovery of the database that will be opened upon callingMediaLibrary.init()
.void
setRecoveryFlag(boolean forceRecovery)
void
setUIDelegate(MediaLibraryUIDelegate uiDelegate)
<V> V
smuggle(Callable<V> callable)
Smuggles read-only calls to theMediaLibrary.getTunesExecutor()
even when it's blocked.void
store(AudioSong song)
Stores a song in the beaTunes database.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tagtraum.core.app.ApplicationComponent
getId, init, shutdown
-
Methods inherited from interface com.tagtraum.beatunes.library.MediaLibrary
addPlayListDataListener, addPlayListPropertyChangeListener, addPlayListPropertyChangeListener, countSongs, countSongsWithPropertyValue, countUnprotectedSongsAddedAfter, createFolder, createFolder, createPlayList, createPlayList, createPlayList, deleteAllFingerprints, deletePlayList, fetchCollections, flushPendingWrites, getAcousticallyIdenticalSongIds, getAcousticallyIdenticalSongIds, getAcousticallyIdenticalSongIds, getAcousticallyIdenticalSongIds, getAlbum, getAlbumKeys, getAlbumSongIds, getAlbumSongs, getApplicationVersion, getDatabaseDir, getDuplicateTitles, getDuplicateTrackIds, getGenres, getLibrary, getPersistentId, getPlayListPropertyChangeListeners, getPlayListPropertyChangeListeners, getPlayLists, getPopularTagCollection, getSimilarTitles, getSong, getSongIds, getSongIdsWithoutProperties, getSongIdsWithProperties, getSongIdsWithPropertiesILike, getSongIdsWithPropertiesLike, getSongPropertyValues, getSongPropertyValues, getSongPropertyValues, getSongs, getSongsOrderedBy, getSongsWithFileAndSize, getSongsWithNameArtistAlbumTotalTime, getSongsWithoutProperties, getSongsWithProperties, getSongsWithPropertiesLike, getSongsWithTrackIdTotalTime, getTagCollection, getUnprotectedSongsAddedAfter, init, removePlayListDataListener, removePlayListPropertyChangeListener, removePlayListPropertyChangeListener, shutdown, store, store, store, store
-
-
-
-
Field Detail
-
AUTO_DETECT_ITUNESLIBRARY
public static final boolean AUTO_DETECT_ITUNESLIBRARY
-
TEN_MINUTES
protected static final long TEN_MINUTES
- See Also:
- Constant Field Values
-
TOTALTIME_DEVIATION
protected static final int TOTALTIME_DEVIATION
- See Also:
- Constant Field Values
-
propertyChangeSupport
protected PropertyChangeSupport propertyChangeSupport
-
databaseDir
protected File databaseDir
-
wrappingProxy
protected final MediaLibrary wrappingProxy
-
-
Constructor Detail
-
AbstractMediaLibrary
protected AbstractMediaLibrary(T application)
-
-
Method Detail
-
getWrappingProxyFactory
public WrappingProxyFactory getWrappingProxyFactory()
-
getWrappingProxy
public MediaLibrary getWrappingProxy()
-
getUIDelegate
public MediaLibraryUIDelegate getUIDelegate()
-
setUIDelegate
public void setUIDelegate(MediaLibraryUIDelegate uiDelegate)
- Specified by:
setUIDelegate
in interfaceMediaLibrary
-
isEmbedAudioMetaData
public boolean isEmbedAudioMetaData()
Description copied from interface:MediaLibrary
Shall all data be embedded into the audio files, when writing?- Specified by:
isEmbedAudioMetaData
in interfaceMediaLibrary
- Returns:
- true or false
-
setEmbedAudioMetaData
public void setEmbedAudioMetaData(boolean embedAudioMetaData)
Description copied from interface:MediaLibrary
Shall all data be embedded into audio files or just those fields that are supported by iTunes.- Specified by:
setEmbedAudioMetaData
in interfaceMediaLibrary
- Parameters:
embedAudioMetaData
- embed
-
isForceAudioMetaDataWrites
public boolean isForceAudioMetaDataWrites()
Description copied from interface:MediaLibrary
Shall new values always be written, even, if the old value seems to be identical? This can happen, when the internal database is out of sync with actual values in audio files or iTunes.- Specified by:
isForceAudioMetaDataWrites
in interfaceMediaLibrary
- Returns:
- true or false
-
setForceAudioMetaDataWrites
public void setForceAudioMetaDataWrites(boolean forceAudioMetaDataWrites)
Description copied from interface:MediaLibrary
Shall new values always be written, even, if the old value seems to be identical? This can happen, when the internal database is out of sync with actual values in audio files or iTunes.- Specified by:
setForceAudioMetaDataWrites
in interfaceMediaLibrary
- Parameters:
forceAudioMetaDataWrites
- force writing
-
getTunes
public ITunes getTunes()
Description copied from interface:MediaLibrary
Returns the currently associated audio player, probably iTunes.- Specified by:
getTunes
in interfaceMediaLibrary
- Returns:
- audio player
-
getApplication
public T getApplication()
Description copied from interface:ApplicationComponent
Returns the main application component.- Specified by:
getApplication
in interfaceApplicationComponent<T extends ApplicationComponent>
- Returns:
- application object
-
getImplementation
public <T> T getImplementation(Class<T> klass)
- Specified by:
getImplementation
in interfaceMediaLibrary
-
setRecoveryFlag
public void setRecoveryFlag()
Description copied from interface:MediaLibrary
Call this method beforeMediaLibrary.init()
in order to force recovery of the database that will be opened upon callingMediaLibrary.init()
. The flag will be reset automatically, once a database recovery was attempted.- Specified by:
setRecoveryFlag
in interfaceMediaLibrary
-
isForceRecovery
public boolean isForceRecovery()
Description copied from interface:MediaLibrary
Is the recovery flag set?- Specified by:
isForceRecovery
in interfaceMediaLibrary
- Returns:
- true or false
-
setRecoveryFlag
public void setRecoveryFlag(boolean forceRecovery)
-
getGenreIRILookupService
public GenreIRILookupService getGenreIRILookupService()
Description copied from interface:MediaLibrary
Returns current genre IRI lookup service.- Specified by:
getGenreIRILookupService
in interfaceMediaLibrary
- Returns:
- service
-
setGenreIRILookupService
public void setGenreIRILookupService(GenreIRILookupService service)
Description copied from interface:MediaLibrary
Lets you set theGenreIRILookupService
.- Specified by:
setGenreIRILookupService
in interfaceMediaLibrary
- Parameters:
service
- service
-
setApplication
public void setApplication(T application)
Description copied from interface:ApplicationComponent
Sets the main application component.- Specified by:
setApplication
in interfaceApplicationComponent<T extends ApplicationComponent>
- Parameters:
application
- main application component
-
getLock
public ReentrantLock getLock(Long songId)
Description copied from interface:MediaLibrary
Provides a lock object for a song id.- Specified by:
getLock
in interfaceMediaLibrary
- Parameters:
songId
- song id- Returns:
- exclusive, reentrant lock
-
lock
public Lock lock(Long songId)
Description copied from interface:MediaLibrary
Provides a locked lock for a song id.- Specified by:
lock
in interfaceMediaLibrary
- Parameters:
songId
- song id- Returns:
- exclusive, reentrant lock
-
getTunesExecutor
public MultiQueueExecutor getTunesExecutor()
Description copied from interface:MediaLibrary
Returns en executor service that should be used for any write access toITunes
related tasks. This takes care of synchronizing your access as well as using the correct thread.Typically when working with
AudioSong
objects, synchronization happens behind the scenes, so you don't have to use this service. However, there may be situations in which you want to access aTrack
directly. If you intend to write, you should use this executor.The service is managed by the application, i.e. you cannot terminate or shut it down.
- Specified by:
getTunesExecutor
in interfaceMediaLibrary
- Returns:
- executor service
- See Also:
TunesUtilities.getExecutorService()
-
getAudioMetaDataExecutor
public ExecutorService getAudioMetaDataExecutor()
Description copied from interface:MediaLibrary
Returns en executor service that should be used for any write access toAudioMetaData
related tasks. This takes care of synchronizing your access as well as using the correct thread.Typically when working with
AudioSong
objects, synchronization happens behind the scenes, so you don't have to use this service. However, there may be situations in which you want to access aAudioMetaData
directly. If you intend to write, you should use this executor.The service is managed by the application, i.e. you cannot terminate or shut it down.
- Specified by:
getAudioMetaDataExecutor
in interfaceMediaLibrary
- Returns:
- executor service
- See Also:
AudioMetaData.getExecutorService()
-
serialExecute
public <V> V serialExecute(Callable<V> callable) throws Exception
Description copied from interface:MediaLibrary
Execute the callable withMediaLibrary.getTunesExecutor()
, but not beforeMediaLibrary.getAudioMetaDataExecutor()
has run through.- Specified by:
serialExecute
in interfaceMediaLibrary
- Type Parameters:
V
- return type- Parameters:
callable
- callable- Returns:
- return value, may be null
- Throws:
Exception
-
serialExecute
public void serialExecute(Runnable runnable)
Description copied from interface:MediaLibrary
Execute the runnable withMediaLibrary.getTunesExecutor()
, but not beforeMediaLibrary.getAudioMetaDataExecutor()
has run through.- Specified by:
serialExecute
in interfaceMediaLibrary
- Parameters:
runnable
- runnable
-
smuggle
public <V> V smuggle(Callable<V> callable) throws Exception
Description copied from interface:MediaLibrary
Smuggles read-only calls to theMediaLibrary.getTunesExecutor()
even when it's blocked.- Specified by:
smuggle
in interfaceMediaLibrary
- Type Parameters:
V
- return type- Parameters:
callable
- callable- Returns:
- return value, may be null
- Throws:
Exception
-
isNewDatabase
public boolean isNewDatabase()
- Specified by:
isNewDatabase
in interfaceMediaLibrary
-
setNewDatabase
public void setNewDatabase(boolean newDatabase)
- Specified by:
setNewDatabase
in interfaceMediaLibrary
-
getSongs
public Iterable<AudioSong> getSongs()
Description copied from interface:MediaLibrary
Returns anIterable
that can be used to iterate over all songs. Shortcut forPlayList.getSongs()
called on the library playlist (MediaLibrary.getLibrary()
). Note, that theIterable
may be aList
, which would expose other, non-sequential means of accessing the content.- Specified by:
getSongs
in interfaceMediaLibrary
- Returns:
- an object from which one can get an iterator
-
getSongsOrderedBy
public Iterable<AudioSong> getSongsOrderedBy(String sortProperty, PlayList.SortDirection direction)
Description copied from interface:MediaLibrary
Returns anIterable
that can be used to iterate over all songs. Shortcut forPlayList.getSongsOrderedBy(String, PlayList.SortDirection)
called on the library playlist (MediaLibrary.getLibrary()
).- Specified by:
getSongsOrderedBy
in interfaceMediaLibrary
- Parameters:
sortProperty
- property name to order bydirection
- direction- Returns:
- an object from which one can get an iterator
-
getSongsOrderedBy
public Iterable<AudioSong> getSongsOrderedBy(String sortProperty, PlayList.SortDirection direction, int limit)
Description copied from interface:MediaLibrary
Returns anIterable
that can be used to iterate over all songs. Shortcut forPlayList.getSongsOrderedBy(String, PlayList.SortDirection)
called on the library playlist (MediaLibrary.getLibrary()
).- Specified by:
getSongsOrderedBy
in interfaceMediaLibrary
- Parameters:
sortProperty
- property name to order bydirection
- directionlimit
- max number of songs to return- Returns:
- an object from which one can get an iterator
-
getSongIds
public Set<Long> getSongIds(PlayList.Kind... kinds)
Description copied from interface:MediaLibrary
Returns all ids that are in the given set ofPlayList.Kind
s.- Specified by:
getSongIds
in interfaceMediaLibrary
- Parameters:
kinds
- kind- Returns:
- set of ids
-
isRebuildPlayLists
public boolean isRebuildPlayLists()
-
setRebuildPlayLists
public void setRebuildPlayLists(boolean rebuildPlayLists)
If set to true, the library will attempt to re-build all playlists on nextload(boolean, boolean, boolean)
. This makes primarily sense for iTunes based libraries. The load/sync itself is not triggered automatically.- Parameters:
rebuildPlayLists
- true, if you want to trigger a rebuild.
-
getPlayList
public PlayList getPlayList(long id)
Description copied from interface:MediaLibrary
Get aPlayList
for an id.- Specified by:
getPlayList
in interfaceMediaLibrary
- Parameters:
id
- persistent id- Returns:
- the playlist corresponding to the id or null, if it does not exist
-
getLibraryLoader
protected abstract LibraryLoader getLibraryLoader()
-
getLastSynchronizationTimestamp
public long getLastSynchronizationTimestamp()
Description copied from interface:MediaLibrary
Timestamp of last synchronization of the current library.- Specified by:
getLastSynchronizationTimestamp
in interfaceMediaLibrary
- Returns:
- timestamp or
0
, if unknown
-
getPreviousToLastSynchronizationTimestamp
public long getPreviousToLastSynchronizationTimestamp()
Description copied from interface:MediaLibrary
Timestamp of the previous to last synchronization of the current library.- Specified by:
getPreviousToLastSynchronizationTimestamp
in interfaceMediaLibrary
- Returns:
- timestamp or
0
, if unknown
-
setLibraryDescriptor
public void setLibraryDescriptor(LibraryDescriptor libraryDescriptor)
Description copied from interface:MediaLibrary
Sets the library descriptor.- Specified by:
setLibraryDescriptor
in interfaceMediaLibrary
- Parameters:
libraryDescriptor
- library descriptor
-
getLibraryDescriptor
public LibraryDescriptor getLibraryDescriptor()
Description copied from interface:MediaLibrary
Returns the library descriptor. Use this method to find out, what kind of library you are dealing with.- Specified by:
getLibraryDescriptor
in interfaceMediaLibrary
- Returns:
- library descriptor
- See Also:
ITunesLibraryDescriptor
,FileSystemLibraryDescriptor
-
refresh
public void refresh() throws IOException, ParserConfigurationException, SAXException
Description copied from interface:MediaLibrary
Reloads all objects that are connected to the music library. If this is the first time we are loading the library, it will be done synchronously. After that it will be done asynchronously.- Specified by:
refresh
in interfaceMediaLibrary
- Throws:
IOException
ParserConfigurationException
SAXException
-
refresh
public void refresh(boolean blockingCall, boolean manuallyInitiated, boolean full) throws IOException, ParserConfigurationException, SAXException
Description copied from interface:MediaLibrary
Reloads all objects that are connected to the music library.- Specified by:
refresh
in interfaceMediaLibrary
- Parameters:
blockingCall
- flag to indicate whether this call should return right away or not.manuallyInitiated
- indicates whether this refresh was directly triggered by some user actionfull
- flag indicating we should attempt a full synchronization (no shortcuts)- Throws:
IOException
ParserConfigurationException
SAXException
-
refreshOnNextUpdate
public void refreshOnNextUpdate()
-
cancelSynchronization
public void cancelSynchronization()
Description copied from interface:MediaLibrary
Cancels any ongoing synchronization.- Specified by:
cancelSynchronization
in interfaceMediaLibrary
- See Also:
MediaLibrary.refresh()
,MediaLibrary.isSynchronizing()
-
needsRefresh
public boolean needsRefresh() throws IOException
- Specified by:
needsRefresh
in interfaceMediaLibrary
- Returns:
- true, if the library is based on an xml files and was changed. Or if we cannot determine, if a refresh is really necessary
- Throws:
IOException
-
isOneWeekOld
public boolean isOneWeekOld() throws IOException
- Specified by:
isOneWeekOld
in interfaceMediaLibrary
- Returns:
- true if the
iTunes (Music) Library.xml
file is older than one week. - Throws:
IOException
- See Also:
MediaLibrary.getLibraryDescriptor()
-
isProgressDialogVisible
protected abstract boolean isProgressDialogVisible(boolean firstTime, boolean manuallyInitiated)
-
isSynchronizing
public boolean isSynchronizing()
Description copied from interface:MediaLibrary
Indicates, whether we are currently synchronizing.- Specified by:
isSynchronizing
in interfaceMediaLibrary
- Returns:
true
orfalse
- See Also:
MediaLibrary.cancelSynchronization()
-
addMediaLibraryListener
public void addMediaLibraryListener(MediaLibraryListener listener)
- Specified by:
addMediaLibraryListener
in interfaceMediaLibrary
-
removeMediaLibraryListener
public boolean removeMediaLibraryListener(MediaLibraryListener listener)
- Specified by:
removeMediaLibraryListener
in interfaceMediaLibrary
-
fireLibrarySynchronizedEvent
protected void fireLibrarySynchronizedEvent(MediaLibraryEvent event)
-
fireSynchronousSynchronizationEvent
protected void fireSynchronousSynchronizationEvent()
-
fireAsynchronousSynchronizationEvent
protected void fireAsynchronousSynchronizationEvent()
-
setDatabaseDir
public void setDatabaseDir(File databaseDir)
- Specified by:
setDatabaseDir
in interfaceMediaLibrary
-
isSupportedPlayList
public boolean isSupportedPlayList(PlayList.Kind kind)
Description copied from interface:MediaLibrary
Indicates whether a distinguished kind ofPlayList
is supported.- Specified by:
isSupportedPlayList
in interfaceMediaLibrary
- Parameters:
kind
- kind- Returns:
- true or false
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListener
in interfaceMediaLibrary
-
addPropertyChangeListener
public void addPropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListener
in interfaceMediaLibrary
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListener
in interfaceMediaLibrary
-
removePropertyChangeListener
public void removePropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListener
in interfaceMediaLibrary
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()
- Specified by:
getPropertyChangeListeners
in interfaceMediaLibrary
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners(String property)
- Specified by:
getPropertyChangeListeners
in interfaceMediaLibrary
-
store
public void store(AudioSong song)
Description copied from interface:MediaLibrary
Stores a song in the beaTunes database.
The write-process is asynchronous, i.e. this method may return before the songs has actually been written.
- Specified by:
store
in interfaceMediaLibrary
- Parameters:
song
- song to save
-
-