Class WeakKeySet


  • final class WeakKeySet
    extends java.lang.Object
    Minimal set that doesn't hold strong references to the contained keys.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  WeakKeySet.KeyAndSource  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<Key<?>,​com.google.common.collect.Multiset<java.lang.Object>> backingMap  
      private com.google.common.cache.Cache<State,​java.util.Set<WeakKeySet.KeyAndSource>> evictionCache
      Tracks child injector lifetimes and evicts blacklisted keys/sources after the child injector is garbage collected.
      private java.lang.Object lock
      This is already locked externally on add and getSources but we need it to handle clean up in the evictionCache's RemovalListener.
    • Constructor Summary

      Constructors 
      Constructor Description
      WeakKeySet​(java.lang.Object lock)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Key<?> key, State state, java.lang.Object source)  
      private void cleanUpForCollectedState​(java.util.Set<WeakKeySet.KeyAndSource> keysAndSources)
      There may be multiple child injectors blacklisting a certain key so only remove the source that's relevant.
      boolean contains​(Key<?> key)  
      java.util.Set<java.lang.Object> getSources​(Key<?> key)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • backingMap

        private java.util.Map<Key<?>,​com.google.common.collect.Multiset<java.lang.Object>> backingMap
      • lock

        private final java.lang.Object lock
        This is already locked externally on add and getSources but we need it to handle clean up in the evictionCache's RemovalListener.
      • evictionCache

        private final com.google.common.cache.Cache<State,​java.util.Set<WeakKeySet.KeyAndSource>> evictionCache
        Tracks child injector lifetimes and evicts blacklisted keys/sources after the child injector is garbage collected.
    • Constructor Detail

      • WeakKeySet

        WeakKeySet​(java.lang.Object lock)
    • Method Detail

      • cleanUpForCollectedState

        private void cleanUpForCollectedState​(java.util.Set<WeakKeySet.KeyAndSource> keysAndSources)
        There may be multiple child injectors blacklisting a certain key so only remove the source that's relevant.
      • add

        public void add​(Key<?> key,
                        State state,
                        java.lang.Object source)
      • contains

        public boolean contains​(Key<?> key)
      • getSources

        public java.util.Set<java.lang.Object> getSources​(Key<?> key)