Class SyncMap

  • All Implemented Interfaces:
    Map
    Direct Known Subclasses:
    SyncSortedMap

    public class SyncMap
    extends Object
    implements 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
    • Field Detail

      • c_

        protected final Map c_
      • rd_

        protected final Sync rd_
      • wr_

        protected final Sync wr_
    • Constructor Detail

      • SyncMap

        public SyncMap​(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​(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​(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
      • size

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

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

        public boolean containsKey​(Object o)
        Specified by:
        containsKey in interface Map
      • putAll

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

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

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

        public Set entrySet()
        Specified by:
        entrySet in interface Map