2. About me
Founding Partner @ Axemblr.com
Apache Whirr PMC Member
jclouds committer
Connect with me on LinkedIn
3. @ Axemblr
Building a tool and a platform for managing
Apache Hadoop clusters on cloud infrastructure
Axemblr Tool for Cloudera CDH3
http://axemblr.com/tool
Axemblr Service for Apache Hadoop
http://axemblr.com/service
6. What is Guava?
Open-source version of Google's core Java
libraries
[...] carefully designed, tested, optimized and
used in production at Google
You don't need to write them, test them, or
optimize them: you can just use them.
7. What is Guava? (cont)
Battle-tested in production at Google
Staggering numbers of unit tests. >110.000 as
of January 2012 (generated)
Lives near the bottom of the stack, right on top
of the JDK itself
9. Caches - When to use?
When a value is either
● expensive to compute
● expensive to retrieve
More or less similar to ConcurrentMap +
automatic eviction
10. Caches - When to use? (cont)
● spend memory to improve speed
● keys are queried multiple times
● your application would work if every value
was evicted immediately
● you have less data than RAM
13. Caches - Example #3
cache.put(key, value)
A Cache can be accessed as a Map:
Cache.asMap() returns a ConcurrentMap
14. Caches - Eviction #1
By size
CacheBuilder.maximumSize(long)
By custom weight
CacheBuilder.weigher(Weigher)
CacheBuilder.maximumWeight(long)
15. Caches - Eviction #2
By time
expireAfterAccess(long, TimeUnit)
expireAfterWrite(long, TimeUnit)
16. Caches - Eviction #3
Reference-based eviction
CacheBuilder.weakKeys()
CacheBuilder.weakValues()
CacheBuilder.softValues()
Note: all of them are using == for equality and
*not* equals()
18. Caches - Removal Listeners
CacheBuilder
.removalListener(RemovalListener)
Be aware of long running listeners. They are
blocking the queue.
RemovalListeners
.asynchronous(RemovalListener, Executor)
19. Caches - Cleanup
Automatic eviction happens on writes
Explicit Cache.cleanup()
(you can put this in a thread)
23. What is this?
Object with operational state
Start and stop methods
E.g. web servers, RPC servers, timers etc.
Non-trivial if multiple threads are involved.
24. Lifecycle
● Service.State.NEW to
● Service.State.STARTING to
● Service.State.RUNNING to
● Service.State.STOPPING to
● Service.State.TERMINATED
On failure:
● Service.State.FAILED
A stopped service may not be restarted.