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 booleanAUTO_DETECT_ITUNESLIBRARYprotected FiledatabaseDirprotected PropertyChangeSupportpropertyChangeSupportprotected static longTEN_MINUTESprotected static intTOTALTIME_DEVIATIONprotected MediaLibrarywrappingProxy
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMediaLibrary(T application)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddMediaLibraryListener(MediaLibraryListener listener)voidaddPropertyChangeListener(PropertyChangeListener propertyChangeListener)voidaddPropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)voidcancelSynchronization()Cancels any ongoing synchronization.protected voidfireAsynchronousSynchronizationEvent()protected voidfireLibrarySynchronizedEvent(MediaLibraryEvent event)protected voidfireSynchronousSynchronizationEvent()TgetApplication()Returns the main application component.ExecutorServicegetAudioMetaDataExecutor()Returns en executor service that should be used for any write access toAudioMetaDatarelated tasks.GenreIRILookupServicegetGenreIRILookupService()Returns current genre IRI lookup service.<T> TgetImplementation(Class<T> klass)longgetLastSynchronizationTimestamp()Timestamp of last synchronization of the current library.LibraryDescriptorgetLibraryDescriptor()Returns the library descriptor.protected abstract LibraryLoadergetLibraryLoader()ReentrantLockgetLock(Long songId)Provides a lock object for a song id.PlayListgetPlayList(long id)Get aPlayListfor an id.longgetPreviousToLastSynchronizationTimestamp()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.Kinds.Iterable<AudioSong>getSongs()Returns anIterablethat can be used to iterate over all songs.Iterable<AudioSong>getSongsOrderedBy(String sortProperty, PlayList.SortDirection direction)Returns anIterablethat can be used to iterate over all songs.Iterable<AudioSong>getSongsOrderedBy(String sortProperty, PlayList.SortDirection direction, int limit)Returns anIterablethat can be used to iterate over all songs.ITunesgetTunes()Returns the currently associated audio player, probably iTunes.MultiQueueExecutorgetTunesExecutor()Returns en executor service that should be used for any write access toITunesrelated tasks.MediaLibraryUIDelegategetUIDelegate()MediaLibrarygetWrappingProxy()WrappingProxyFactorygetWrappingProxyFactory()booleanisEmbedAudioMetaData()Shall all data be embedded into the audio files, when writing?booleanisForceAudioMetaDataWrites()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.booleanisForceRecovery()Is the recovery flag set?booleanisNewDatabase()booleanisOneWeekOld()protected abstract booleanisProgressDialogVisible(boolean firstTime, boolean manuallyInitiated)booleanisRebuildPlayLists()booleanisSupportedPlayList(PlayList.Kind kind)Indicates whether a distinguished kind ofPlayListis supported.booleanisSynchronizing()Indicates, whether we are currently synchronizing.Locklock(Long songId)Provides a locked lock for a song id.booleanneedsRefresh()voidrefresh()Reloads all objects that are connected to the music library.voidrefresh(boolean blockingCall, boolean manuallyInitiated, boolean full)Reloads all objects that are connected to the music library.voidrefreshOnNextUpdate()booleanremoveMediaLibraryListener(MediaLibraryListener listener)voidremovePropertyChangeListener(PropertyChangeListener propertyChangeListener)voidremovePropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)voidserialExecute(Runnable runnable)Execute the runnable withMediaLibrary.getTunesExecutor(), but not beforeMediaLibrary.getAudioMetaDataExecutor()has run through.<V> VserialExecute(Callable<V> callable)Execute the callable withMediaLibrary.getTunesExecutor(), but not beforeMediaLibrary.getAudioMetaDataExecutor()has run through.voidsetApplication(T application)Sets the main application component.voidsetDatabaseDir(File databaseDir)voidsetEmbedAudioMetaData(boolean embedAudioMetaData)Shall all data be embedded into audio files or just those fields that are supported by iTunes.voidsetForceAudioMetaDataWrites(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.voidsetGenreIRILookupService(GenreIRILookupService service)Lets you set theGenreIRILookupService.voidsetLibraryDescriptor(LibraryDescriptor libraryDescriptor)Sets the library descriptor.voidsetNewDatabase(boolean newDatabase)voidsetRebuildPlayLists(boolean rebuildPlayLists)If set to true, the library will attempt to re-build all playlists on nextload(boolean, boolean, boolean).voidsetRecoveryFlag()Call this method beforeMediaLibrary.init()in order to force recovery of the database that will be opened upon callingMediaLibrary.init().voidsetRecoveryFlag(boolean forceRecovery)voidsetUIDelegate(MediaLibraryUIDelegate uiDelegate)<V> Vsmuggle(Callable<V> callable)Smuggles read-only calls to theMediaLibrary.getTunesExecutor()even when it's blocked.voidstore(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:
setUIDelegatein interfaceMediaLibrary
-
isEmbedAudioMetaData
public boolean isEmbedAudioMetaData()
Description copied from interface:MediaLibraryShall all data be embedded into the audio files, when writing?- Specified by:
isEmbedAudioMetaDatain interfaceMediaLibrary- Returns:
- true or false
-
setEmbedAudioMetaData
public void setEmbedAudioMetaData(boolean embedAudioMetaData)
Description copied from interface:MediaLibraryShall all data be embedded into audio files or just those fields that are supported by iTunes.- Specified by:
setEmbedAudioMetaDatain interfaceMediaLibrary- Parameters:
embedAudioMetaData- embed
-
isForceAudioMetaDataWrites
public boolean isForceAudioMetaDataWrites()
Description copied from interface:MediaLibraryShall 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:
isForceAudioMetaDataWritesin interfaceMediaLibrary- Returns:
- true or false
-
setForceAudioMetaDataWrites
public void setForceAudioMetaDataWrites(boolean forceAudioMetaDataWrites)
Description copied from interface:MediaLibraryShall 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:
setForceAudioMetaDataWritesin interfaceMediaLibrary- Parameters:
forceAudioMetaDataWrites- force writing
-
getTunes
public ITunes getTunes()
Description copied from interface:MediaLibraryReturns the currently associated audio player, probably iTunes.- Specified by:
getTunesin interfaceMediaLibrary- Returns:
- audio player
-
getApplication
public T getApplication()
Description copied from interface:ApplicationComponentReturns the main application component.- Specified by:
getApplicationin interfaceApplicationComponent<T extends ApplicationComponent>- Returns:
- application object
-
getImplementation
public <T> T getImplementation(Class<T> klass)
- Specified by:
getImplementationin interfaceMediaLibrary
-
setRecoveryFlag
public void setRecoveryFlag()
Description copied from interface:MediaLibraryCall 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:
setRecoveryFlagin interfaceMediaLibrary
-
isForceRecovery
public boolean isForceRecovery()
Description copied from interface:MediaLibraryIs the recovery flag set?- Specified by:
isForceRecoveryin interfaceMediaLibrary- Returns:
- true or false
-
setRecoveryFlag
public void setRecoveryFlag(boolean forceRecovery)
-
getGenreIRILookupService
public GenreIRILookupService getGenreIRILookupService()
Description copied from interface:MediaLibraryReturns current genre IRI lookup service.- Specified by:
getGenreIRILookupServicein interfaceMediaLibrary- Returns:
- service
-
setGenreIRILookupService
public void setGenreIRILookupService(GenreIRILookupService service)
Description copied from interface:MediaLibraryLets you set theGenreIRILookupService.- Specified by:
setGenreIRILookupServicein interfaceMediaLibrary- Parameters:
service- service
-
setApplication
public void setApplication(T application)
Description copied from interface:ApplicationComponentSets the main application component.- Specified by:
setApplicationin interfaceApplicationComponent<T extends ApplicationComponent>- Parameters:
application- main application component
-
getLock
public ReentrantLock getLock(Long songId)
Description copied from interface:MediaLibraryProvides a lock object for a song id.- Specified by:
getLockin interfaceMediaLibrary- Parameters:
songId- song id- Returns:
- exclusive, reentrant lock
-
lock
public Lock lock(Long songId)
Description copied from interface:MediaLibraryProvides a locked lock for a song id.- Specified by:
lockin interfaceMediaLibrary- Parameters:
songId- song id- Returns:
- exclusive, reentrant lock
-
getTunesExecutor
public MultiQueueExecutor getTunesExecutor()
Description copied from interface:MediaLibraryReturns en executor service that should be used for any write access toITunesrelated tasks. This takes care of synchronizing your access as well as using the correct thread.Typically when working with
AudioSongobjects, 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 aTrackdirectly. 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:
getTunesExecutorin interfaceMediaLibrary- Returns:
- executor service
- See Also:
TunesUtilities.getExecutorService()
-
getAudioMetaDataExecutor
public ExecutorService getAudioMetaDataExecutor()
Description copied from interface:MediaLibraryReturns en executor service that should be used for any write access toAudioMetaDatarelated tasks. This takes care of synchronizing your access as well as using the correct thread.Typically when working with
AudioSongobjects, 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 aAudioMetaDatadirectly. 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:
getAudioMetaDataExecutorin interfaceMediaLibrary- Returns:
- executor service
- See Also:
AudioMetaData.getExecutorService()
-
serialExecute
public <V> V serialExecute(Callable<V> callable) throws Exception
Description copied from interface:MediaLibraryExecute the callable withMediaLibrary.getTunesExecutor(), but not beforeMediaLibrary.getAudioMetaDataExecutor()has run through.- Specified by:
serialExecutein 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:MediaLibraryExecute the runnable withMediaLibrary.getTunesExecutor(), but not beforeMediaLibrary.getAudioMetaDataExecutor()has run through.- Specified by:
serialExecutein interfaceMediaLibrary- Parameters:
runnable- runnable
-
smuggle
public <V> V smuggle(Callable<V> callable) throws Exception
Description copied from interface:MediaLibrarySmuggles read-only calls to theMediaLibrary.getTunesExecutor()even when it's blocked.- Specified by:
smugglein interfaceMediaLibrary- Type Parameters:
V- return type- Parameters:
callable- callable- Returns:
- return value, may be null
- Throws:
Exception
-
isNewDatabase
public boolean isNewDatabase()
- Specified by:
isNewDatabasein interfaceMediaLibrary
-
setNewDatabase
public void setNewDatabase(boolean newDatabase)
- Specified by:
setNewDatabasein interfaceMediaLibrary
-
getSongs
public Iterable<AudioSong> getSongs()
Description copied from interface:MediaLibraryReturns anIterablethat can be used to iterate over all songs. Shortcut forPlayList.getSongs()called on the library playlist (MediaLibrary.getLibrary()). Note, that theIterablemay be aList, which would expose other, non-sequential means of accessing the content.- Specified by:
getSongsin 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:MediaLibraryReturns anIterablethat can be used to iterate over all songs. Shortcut forPlayList.getSongsOrderedBy(String, PlayList.SortDirection)called on the library playlist (MediaLibrary.getLibrary()).- Specified by:
getSongsOrderedByin 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:MediaLibraryReturns anIterablethat can be used to iterate over all songs. Shortcut forPlayList.getSongsOrderedBy(String, PlayList.SortDirection)called on the library playlist (MediaLibrary.getLibrary()).- Specified by:
getSongsOrderedByin 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:MediaLibraryReturns all ids that are in the given set ofPlayList.Kinds.- Specified by:
getSongIdsin 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:MediaLibraryGet aPlayListfor an id.- Specified by:
getPlayListin 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:MediaLibraryTimestamp of last synchronization of the current library.- Specified by:
getLastSynchronizationTimestampin interfaceMediaLibrary- Returns:
- timestamp or
0, if unknown
-
getPreviousToLastSynchronizationTimestamp
public long getPreviousToLastSynchronizationTimestamp()
Description copied from interface:MediaLibraryTimestamp of the previous to last synchronization of the current library.- Specified by:
getPreviousToLastSynchronizationTimestampin interfaceMediaLibrary- Returns:
- timestamp or
0, if unknown
-
setLibraryDescriptor
public void setLibraryDescriptor(LibraryDescriptor libraryDescriptor)
Description copied from interface:MediaLibrarySets the library descriptor.- Specified by:
setLibraryDescriptorin interfaceMediaLibrary- Parameters:
libraryDescriptor- library descriptor
-
getLibraryDescriptor
public LibraryDescriptor getLibraryDescriptor()
Description copied from interface:MediaLibraryReturns the library descriptor. Use this method to find out, what kind of library you are dealing with.- Specified by:
getLibraryDescriptorin interfaceMediaLibrary- Returns:
- library descriptor
- See Also:
ITunesLibraryDescriptor,FileSystemLibraryDescriptor
-
refresh
public void refresh() throws IOException, ParserConfigurationException, SAXExceptionDescription copied from interface:MediaLibraryReloads 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:
refreshin interfaceMediaLibrary- Throws:
IOExceptionParserConfigurationExceptionSAXException
-
refresh
public void refresh(boolean blockingCall, boolean manuallyInitiated, boolean full) throws IOException, ParserConfigurationException, SAXExceptionDescription copied from interface:MediaLibraryReloads all objects that are connected to the music library.- Specified by:
refreshin 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:
IOExceptionParserConfigurationExceptionSAXException
-
refreshOnNextUpdate
public void refreshOnNextUpdate()
-
cancelSynchronization
public void cancelSynchronization()
Description copied from interface:MediaLibraryCancels any ongoing synchronization.- Specified by:
cancelSynchronizationin interfaceMediaLibrary- See Also:
MediaLibrary.refresh(),MediaLibrary.isSynchronizing()
-
needsRefresh
public boolean needsRefresh() throws IOException- Specified by:
needsRefreshin 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:
isOneWeekOldin interfaceMediaLibrary- Returns:
- true if the
iTunes (Music) Library.xmlfile 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:MediaLibraryIndicates, whether we are currently synchronizing.- Specified by:
isSynchronizingin interfaceMediaLibrary- Returns:
trueorfalse- See Also:
MediaLibrary.cancelSynchronization()
-
addMediaLibraryListener
public void addMediaLibraryListener(MediaLibraryListener listener)
- Specified by:
addMediaLibraryListenerin interfaceMediaLibrary
-
removeMediaLibraryListener
public boolean removeMediaLibraryListener(MediaLibraryListener listener)
- Specified by:
removeMediaLibraryListenerin interfaceMediaLibrary
-
fireLibrarySynchronizedEvent
protected void fireLibrarySynchronizedEvent(MediaLibraryEvent event)
-
fireSynchronousSynchronizationEvent
protected void fireSynchronousSynchronizationEvent()
-
fireAsynchronousSynchronizationEvent
protected void fireAsynchronousSynchronizationEvent()
-
setDatabaseDir
public void setDatabaseDir(File databaseDir)
- Specified by:
setDatabaseDirin interfaceMediaLibrary
-
isSupportedPlayList
public boolean isSupportedPlayList(PlayList.Kind kind)
Description copied from interface:MediaLibraryIndicates whether a distinguished kind ofPlayListis supported.- Specified by:
isSupportedPlayListin interfaceMediaLibrary- Parameters:
kind- kind- Returns:
- true or false
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListenerin interfaceMediaLibrary
-
addPropertyChangeListener
public void addPropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
- Specified by:
addPropertyChangeListenerin interfaceMediaLibrary
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListenerin interfaceMediaLibrary
-
removePropertyChangeListener
public void removePropertyChangeListener(String property, PropertyChangeListener propertyChangeListener)
- Specified by:
removePropertyChangeListenerin interfaceMediaLibrary
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()
- Specified by:
getPropertyChangeListenersin interfaceMediaLibrary
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners(String property)
- Specified by:
getPropertyChangeListenersin interfaceMediaLibrary
-
store
public void store(AudioSong song)
Description copied from interface:MediaLibraryStores 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:
storein interfaceMediaLibrary- Parameters:
song- song to save
-
-