Skip to content
This repository

Updated coverer plugins #101

Closed
wants to merge 16 commits into from

2 participants

Nathan rodnaph
Nathan
Collaborator

Please ignore the latest commit, it's just whitespace fixes.

The commit of interest is the penultimate one:

nperrier@7155863

nperrier added some commits
Nathan nperrier Fixed unit tests that were failing when run on windoze 7307b56
Nathan nperrier Revert "Fixed unit tests that were failing when run on windoze"
This reverts commit 7307b5695020c5858b3554d19847925815ce3028.
08352fb
Nathan nperrier Fixed tests to be platform independent 0b13ec1
Nathan nperrier Add the ability to extract and cache album/track cover art from tags …
…on scan. Must be enabled from GUI (default is disabled) Also added a few constants for application folders and moved common utilities for cover art to single class
94e4311
Nathan nperrier Split CoverArtUtils into CoverArt and CoverArtCache. Created CoverArt…
…Indexer and move some of the logic from DBCollectionManager to there.
4b1039f
Nathan nperrier Merge branch 'master' of git://github.com/rodnaph/sockso a6393b3
Nathan nperrier Added tests for CoverArt and CoverArtCache 9baa9de
Nathan nperrier Merge git://github.com/rodnaph/sockso
Conflicts:
	src/com/pugh/sockso/music/Collection.java
	src/com/pugh/sockso/music/DBCollectionManager.java
	src/com/pugh/sockso/web/action/FileServer.java
	test/com/pugh/sockso/music/CoverArtCacheTest.java
	test/com/pugh/sockso/music/CoverArtTest.java
b62b76a
Nathan nperrier Fixing bad merge made by newbie. Fine: 10 lashes f7d0bbe
Nathan nperrier Merge https://github.com/rodnaph/sockso be4f870
Nathan nperrier Merge https://github.com/rodnaph/sockso
Conflicts:
	src/com/pugh/sockso/web/action/FileServer.java
64d9808
Nathan nperrier Coverer plugin refactoring
Added more tests for RemoteCoverer plugin
Created ImageCache inteface for CoverArtCache
Bound CoverSearch interface to AmazonCoverSearch class
Refactored DefaultCoverer a bit
7155863
Nathan nperrier Fixing whitespace (s/tabs/spaces/g) ce2aef9
rodnaph
Owner
rodnaph commented

Oh and lots of whitespace changes... :-/

rodnaph
Owner
rodnaph commented

Further to using the Cache interface - you could extend this new TimedCache class...

18fee9b

With a FileCache implementation, and use that for the cover cache.

Nathan
Collaborator

Have you looked into using a WeakHashMap instead of HashMap for the ObjectCache?

See http://stackoverflow.com/questions/154724/when-would-you-use-a-weakhashmap-or-a-weakreference

Nathan
Collaborator

I'm trying to understand what your thinking is here for the refactor:

Rename CoverArtCache -> FileCache and extend TimedCache instead of implementing ImageCache?

So the TimedCache is an "in memory" cache, in that, the image data should not be cached on the file system anymore? Or do you mean to leave the file system cache alone and supplement it with a faster in memory cache that has an expiration?

Nathan
Collaborator

I see the point of putting the images in memory, as reading from disk is expensive and it might make the cover art quite a bit snappier on the client side. Just trying to figure out how to separate file system caching and in memory caching...

rodnaph
Owner
rodnaph commented

No, sorry I should have explained a bit more. The TimedCache is an abstract class that just requires implementing readRaw() and writeRaw() for data storage. This is then extended by ObjectCache that uses a simple HashMap to provide an in-memory cache.

What you can do is create a another class called CoverArtCache that extends TimedCache, and just implements readRaw() and writeRaw() and what you can do here is read/write the images to/from the file system. So you get all the benefits of TimedCache, and the same interface via Cache. (i said FileCache to be more generic, but it might make sense for now to call it CoverArtCache)

Does that make sense?

I haven't heard of the WeakHashMap no - I'll take a look thanks!

Nathan
Collaborator

OK, I thought you were trying to create a hybrid cache class for the coverart that read/writes to the file system and also keeps the images in memory...I was a bit confused how that would work :)

Nathan
Collaborator

I would assume I need to extend CoverArt from CachedObject now? If I move the code from getCoverArt() to readRaw(), then call readRaw() from the body of getCoverArt(), since getCoverArt() returns a CoverArt, I can't covert a CachedObject (which readRaw() returns) to a CoverArt object, correct?

Trying to imagine what your idea was for implementing this correctly...

Nathan
Collaborator

Nevermind, I just realized CachedObject.getValue() is for that very purpose.

Nathan
Collaborator

Should TimedCache.readRaw()/writeRaw() throw IOException's? The problem I'm running into is that the CoverArtCache needs to do IO to read/write images, but doing that could cause an IOException to be raised. If I implement this in the read/writeRaw ops, I can't re-throw it up the stack - the only option I see is returning a null CachedObject or an empty one. (see TODO's)

Thoughts?

rodnaph
Owner
rodnaph commented

Ah yes I didn't think of Exception's - yes please just alter the interface so those methods throw Exceptions (because it might not just be IOExceptions that implementors need to throw).

Nathan
Collaborator

Is that a good idea? Now methods of ObjectCache throw Exceptions unnecessarily (since it extends TimedCached which implements Cache interface) and require client code to catch them. I think maybe the Cache interface is a bit too generic for both the CoverArtCache (which throws IOExceptions) and an ObjectCache (which throws nothing).

rodnaph
Owner
rodnaph commented

Yeah don't worry about it, throwing exceptions is fine! :)

Nathan
Collaborator

I decided a CacheException class would be best rather than throw Exception everywhere. Let me know what you think.

Nathan
Collaborator

What do you think about adding auth token functionality for mobile apps to the api (see soundcloud doc for example: http://developers.soundcloud.com/docs/api/authentication#authorization-code-flow)

Currently, the only way to do this is via a cookie, which is kinda awkward to program on android :\

rodnaph
Owner
rodnaph commented

Hmm... Not sure about token auth, maybe... but we can deal with that in a separate pull request.

Is this cache feature complete now then? I'll check it out later and pull it to master if it's done.

Nathan
Collaborator

Yes, it's completed and all tests passed.

rodnaph rodnaph closed this in 0ae383a
rodnaph
Owner
rodnaph commented

Ok I've merged this to master now, thanks!

Few things I noticed when merging though, firstly all the whitespace changes - I think these were introduced ages ago so maybe not to worry about now. But I had to manually unstage them all before commit (git reset -p). If your IDE keeps doing this then you can use interactive add to make sure they don't get committed (git add -i).

Also, I always make variables final (unless impossible), this just keeps me on top of reducing mutation as much as possible, and usually results in cleaner less buggy code I find.

Looking forward to your token auth pull request ;)

Nathan
Collaborator

Arrrgh, I thought I fixed the whitespace issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 16 unique commits by 1 author.

Oct 03, 2011
Nathan nperrier Fixed unit tests that were failing when run on windoze 7307b56
Oct 06, 2011
Nathan nperrier Revert "Fixed unit tests that were failing when run on windoze"
This reverts commit 7307b5695020c5858b3554d19847925815ce3028.
08352fb
Nathan nperrier Fixed tests to be platform independent 0b13ec1
Oct 26, 2011
Nathan nperrier Add the ability to extract and cache album/track cover art from tags …
…on scan. Must be enabled from GUI (default is disabled) Also added a few constants for application folders and moved common utilities for cover art to single class
94e4311
Nov 11, 2011
Nathan nperrier Split CoverArtUtils into CoverArt and CoverArtCache. Created CoverArt…
…Indexer and move some of the logic from DBCollectionManager to there.
4b1039f
Jan 16, 2012
Nathan nperrier Merge branch 'master' of git://github.com/rodnaph/sockso a6393b3
Jan 22, 2012
Nathan nperrier Added tests for CoverArt and CoverArtCache 9baa9de
Apr 01, 2012
Nathan nperrier Merge git://github.com/rodnaph/sockso
Conflicts:
	src/com/pugh/sockso/music/Collection.java
	src/com/pugh/sockso/music/DBCollectionManager.java
	src/com/pugh/sockso/web/action/FileServer.java
	test/com/pugh/sockso/music/CoverArtCacheTest.java
	test/com/pugh/sockso/music/CoverArtTest.java
b62b76a
Nathan nperrier Fixing bad merge made by newbie. Fine: 10 lashes f7d0bbe
Apr 22, 2012
Nathan nperrier Merge https://github.com/rodnaph/sockso be4f870
Apr 29, 2012
Nathan nperrier Merge https://github.com/rodnaph/sockso
Conflicts:
	src/com/pugh/sockso/web/action/FileServer.java
64d9808
May 08, 2012
Nathan nperrier Coverer plugin refactoring
Added more tests for RemoteCoverer plugin
Created ImageCache inteface for CoverArtCache
Bound CoverSearch interface to AmazonCoverSearch class
Refactored DefaultCoverer a bit
7155863
Nathan nperrier Fixing whitespace (s/tabs/spaces/g) ce2aef9
May 10, 2012
Nathan nperrier Merge github.com:rodnaph/sockso 6cbfaa3
May 15, 2012
Nathan nperrier Change CoverArtCache to extend from TimedCache beea91b
May 21, 2012
Nathan nperrier Added CacheException for Cache interface 5d30702
Something went wrong with that request. Please try again.