Class SyncMap

  • All Implemented Interfaces:
    java.util.Map
    Direct Known Subclasses:
    SyncSortedMap

    public class SyncMap
    extends java.lang.Object
    implements java.util.Map
    SyncMaps wrap Sync-based control around java.util.Maps. They operate in the same way as SyncCollection.

    Reader operations are

    • size
    • isEmpty
    • get
    • containsKey
    • containsValue
    • keySet
    • entrySet
    • values
    Writer operations are:
    • put
    • putAll
    • remove
    • clear

    [ Introduction to this package. ]

    See Also:
    SyncCollection
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      SyncMap​(java.util.Map map, ReadWriteLock rwl)
      Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods.
      SyncMap​(java.util.Map map, Sync sync)
      Create a new SyncMap protecting the given map, and using the given sync to control both reader and writer methods.
      SyncMap​(java.util.Map map, Sync readLock, Sync writeLock)
      Create a new SyncMap protecting the given map, and using the given pair of locks to control reader and writer methods.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void afterRead​(boolean wasInterrupted)
      Clean up after a reader operation
      protected boolean beforeRead()
      Try to acquire sync before a reader operation; record failure
      void clear()  
      boolean containsKey​(java.lang.Object o)  
      boolean containsValue​(java.lang.Object o)  
      java.util.Set entrySet()  
      boolean equals​(java.lang.Object o)  
      java.lang.Object get​(java.lang.Object key)  
      int hashCode()  
      boolean isEmpty()  
      java.util.Set keySet()  
      java.lang.Object put​(java.lang.Object key, java.lang.Object value)  
      void putAll​(java.util.Map coll)  
      Sync readerSync()
      Return the Sync object managing read-only operations
      java.lang.Object remove​(java.lang.Object key)  
      int size()  
      long syncFailures()
      Return the number of synchronization failures for read-only operations
      java.util.Collection values()  
      Sync writerSync()
      Return the Sync object managing mutative operations
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • c_

        protected final java.util.Map c_
      • rd_

        protected final Sync rd_
      • wr_

        protected final Sync wr_
    • Constructor Detail

      • SyncMap

        public SyncMap​(java.util.Map map,
                       Sync sync)
        Create a new SyncMap protecting the given map, and using the given sync to control both reader and writer methods. Common, reasonable choices for the sync argument include Mutex, ReentrantLock, and Semaphores initialized to 1.
      • SyncMap

        public SyncMap​(java.util.Map map,
                       ReadWriteLock rwl)
        Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods.
      • SyncMap

        public SyncMap​(java.util.Map map,
                       Sync readLock,
                       Sync writeLock)
        Create a new SyncMap protecting the given map, and using the given pair of locks to control reader and writer methods.
    • Method Detail

      • readerSync

        public Sync readerSync()
        Return the Sync object managing read-only operations
      • writerSync

        public Sync writerSync()
        Return the Sync object managing mutative operations
      • syncFailures

        public long syncFailures()
        Return the number of synchronization failures for read-only operations
      • beforeRead

        protected boolean beforeRead()
        Try to acquire sync before a reader operation; record failure
      • afterRead

        protected void afterRead​(boolean wasInterrupted)
        Clean up after a reader operation
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map
        Overrides:
        equals in class java.lang.Object
      • size

        public int size()
        Specified by:
        size in interface java.util.Map
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map
      • containsKey

        public boolean containsKey​(java.lang.Object o)
        Specified by:
        containsKey in interface java.util.Map
      • containsValue

        public boolean containsValue​(java.lang.Object o)
        Specified by:
        containsValue in interface java.util.Map
      • get

        public java.lang.Object get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map
      • put

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value)
        Specified by:
        put in interface java.util.Map
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map
      • putAll

        public void putAll​(java.util.Map coll)
        Specified by:
        putAll in interface java.util.Map
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map
      • keySet

        public java.util.Set keySet()
        Specified by:
        keySet in interface java.util.Map
      • entrySet

        public java.util.Set entrySet()
        Specified by:
        entrySet in interface java.util.Map
      • values

        public java.util.Collection values()
        Specified by:
        values in interface java.util.Map