Class AbstractReplicatedMap<K,​V>

    • Field Detail


        public static final int DEFAULT_INITIAL_CAPACITY
        The default initial capacity - MUST be a power of two.
        See Also:
        Constant Field Values

        public static final float DEFAULT_LOAD_FACTOR
        The load factor used when none specified in constructor.
        See Also:
        Constant Field Values
      • rpcTimeout

        protected transient long rpcTimeout
        Timeout for RPC messages, how long we will wait for a reply
      • channel

        protected transient Channel channel
        Reference to the channel for sending messages
      • rpcChannel

        protected transient RpcChannel rpcChannel
        The RpcChannel to send RPC messages through
      • mapContextName

        protected transient byte[] mapContextName
        The Map context name makes this map unique, this allows us to have more than one map shared through one channel
      • stateTransferred

        protected transient boolean stateTransferred
        Has the state been transferred
      • stateMutex

        protected final transient Object stateMutex
        Simple lock object for transfers
      • mapMembers

        protected final transient HashMap<Member,​Long> mapMembers
        A list of members in our map
      • channelSendOptions

        protected transient int channelSendOptions
        Our default send options
      • externalLoaders

        protected transient ClassLoader[] externalLoaders
        External class loaders if serialization and deserialization is to be performed successfully.
      • currentNode

        protected transient int currentNode
        The node we are currently backing up data to, this index will rotate on a round robin basis
      • accessTimeout

        protected transient long accessTimeout
        Since the map keeps internal membership this is the timeout for a ping message to be responded to If a remote map doesn't respond within this timeframe, its considered dead.
      • mapname

        protected transient String mapname
        Readable string of the mapContextName value
    • Constructor Detail

      • AbstractReplicatedMap

        public AbstractReplicatedMap​(AbstractReplicatedMap.MapOwner owner,
                                     Channel channel,
                                     long timeout,
                                     String mapContextName,
                                     int initialCapacity,
                                     float loadFactor,
                                     int channelSendOptions,
                                     ClassLoader[] cls,
                                     boolean terminate)
        Creates a new map.
        owner - The map owner
        channel - The channel to use for communication
        timeout - long - timeout for RPC messages
        mapContextName - String - unique name for this map, to allow multiple maps per channel
        initialCapacity - int - the size of this map, see HashMap
        loadFactor - float - load factor, see HashMap
        channelSendOptions - Send options
        cls - - a list of classloaders to be used for deserialization of objects.
        terminate - - Flag for whether to terminate this map that failed to start.
    • Method Detail

      • getStateMessageType

        protected abstract int getStateMessageType()
      • getReplicateMessageType

        protected abstract int getReplicateMessageType()
      • wrap

        protected Member[] wrap​(Member m)
        Helper methods, wraps a single member in an array
        m - Member
      • init

        protected void init​(AbstractReplicatedMap.MapOwner owner,
                            Channel channel,
                            String mapContextName,
                            long timeout,
                            int channelSendOptions,
                            ClassLoader[] cls,
                            boolean terminate)
        Initializes the map by creating the RPC channel, registering itself as a channel listener This method is also responsible for initiating the state transfer
        owner - Object
        channel - Channel
        mapContextName - String
        timeout - long
        channelSendOptions - int
        cls - ClassLoader[]
        terminate - - Flag for whether to terminate this map that failed to start.
      • ping

        protected void ping​(long timeout)
                     throws ChannelException
        Sends a ping out to all the members in the cluster, not just map members that this map is alive.
        timeout - long
        ChannelException - Send error
      • memberAlive

        protected void memberAlive​(Member member)
        We have received a member alive notification
        member - Member
      • broadcast

        protected void broadcast​(int msgtype,
                                 boolean rpc)
                          throws ChannelException
        Helper method to broadcast a message to all members in a channel
        msgtype - int
        rpc - boolean
        ChannelException - Send error
      • breakdown

        public void breakdown()
      • getMapMembers

        public Member[] getMapMembers()
      • getMapMembersExcl

        public Member[] getMapMembersExcl​(Member[] exclude)
      • replicate

        public void replicate​(Object key,
                              boolean complete)
        Replicates any changes to the object since the last time The object has to be primary, ie, if the object is a proxy or a backup, it will not be replicated
        key - The object to replicate
        complete - - if set to true, the object is replicated to its backup if set to false, only objects that implement ReplicatedMapEntry and the isDirty() returns true will be replicated
      • replicate

        public void replicate​(boolean complete)
        This can be invoked by a periodic thread to replicate out any changes. For maps that don't store objects that implement ReplicatedMapEntry, this method should be used infrequently to avoid large amounts of data transfer
        complete - boolean
      • transferState

        public void transferState()
      • replyRequest

        public Serializable replyRequest​(Serializable msg,
                                         Member sender)
        Description copied from interface: RpcCallback
        Allows sending a response to a received message.
        Specified by:
        replyRequest in interface RpcCallback
        msg - Serializable
        sender - Member
        Serializable - null if no reply should be sent
      • leftOver

        public void leftOver​(Serializable msg,
                             Member sender)
        If the reply has already been sent to the requesting thread, the rpc callback can handle any data that comes in after the fact.
        Specified by:
        leftOver in interface RpcCallback
        msg - Serializable
        sender - Member
      • accept

        public boolean accept​(Serializable msg,
                              Member sender)
        Description copied from interface: ChannelListener
        Invoked by the channel to determine if the listener will process this message or not.
        Specified by:
        accept in interface ChannelListener
        msg - Serializable
        sender - Member
      • mapMemberAdded

        public void mapMemberAdded​(Member member)
      • getNextBackupIndex

        public int getNextBackupIndex()
      • getNextBackupNode

        public Member getNextBackupNode()
      • heartbeat

        public void heartbeat()
        Description copied from interface: Heartbeat
        Heartbeat invocation for resources cleanup etc
        Specified by:
        heartbeat in interface Heartbeat
      • remove

        public V remove​(Object key)
        Removes an object from this map, it will also remove it from
        Specified by:
        remove in interface Map<K,​V>
        key - Object
      • remove

        public V remove​(Object key,
                        boolean notify)
      • get

        public V get​(Object key)
        Specified by:
        get in interface Map<K,​V>
      • printMap

        protected void printMap​(String header)
      • containsKey

        public boolean containsKey​(Object key)
        Returns true if the key has an entry in the map. The entry can be a proxy or a backup entry, invoking get(key) will make this entry primary for the group
        Specified by:
        containsKey in interface Map<K,​V>
        key - Object
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface Map<K,​V>
      • put

        public V put​(K key,
                     V value,
                     boolean notify)
      • putAll

        public void putAll​(Map<? extends K,​? extends V> m)
        Copies all values from one map to this instance
        Specified by:
        putAll in interface Map<K,​V>
        m - Map
      • clear

        public void clear()
        Specified by:
        clear in interface Map<K,​V>
      • clear

        public void clear​(boolean notify)
      • entrySetFull

        public Set<Map.Entry<K,​AbstractReplicatedMap.MapEntry<K,​V>>> entrySetFull()
        Returns the entire contents of the map Map.Entry.getValue() will return a LazyReplicatedMap.MapEntry object containing all the information about the object.
      • keySetFull

        public Set<K> keySetFull()
      • sizeFull

        public int sizeFull()
      • keySet

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<K,​V>
      • size

        public int size()
        Specified by:
        size in interface Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Map<K,​V>
      • getChannel

        public Channel getChannel()
      • getMapContextName

        public byte[] getMapContextName()
      • getRpcChannel

        public RpcChannel getRpcChannel()
      • getRpcTimeout

        public long getRpcTimeout()
      • getStateMutex

        public Object getStateMutex()
      • isStateTransferred

        public boolean isStateTransferred()
      • getExternalLoaders

        public ClassLoader[] getExternalLoaders()
      • getChannelSendOptions

        public int getChannelSendOptions()
      • getAccessTimeout

        public long getAccessTimeout()
      • setExternalLoaders

        public void setExternalLoaders​(ClassLoader[] externalLoaders)
      • setChannelSendOptions

        public void setChannelSendOptions​(int channelSendOptions)
      • setAccessTimeout

        public void setAccessTimeout​(long accessTimeout)