Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.catalina.tribes.tipis;
 
 
All-to-all replication for a hash map implementation. Each node in the cluster will carry an identical copy of the map.

This map implementation doesn't have a background thread running to replicate changes. If you do have changes without invoking put/remove then you need to invoke one of the following methods:
  • replicate(Object,boolean) - replicates only the object that belongs to the key
  • replicate(boolean) - Scans the entire map for changes and replicates data
the boolean value in the replicate method used to decide whether to only replicate objects that implement the ReplicatedMapEntry interface or to replicate all objects. If an object doesn't implement the ReplicatedMapEntry interface each time the object gets replicated the entire object gets serialized, hence a call to replicate(true) will replicate all objects in this map that are using this node as primary.

REMEMBER TO CALL breakdown() or finalize() when you are done with the map to avoid memory leaks.

TODO implement periodic sync/transfer thread
TODO memberDisappeared, should do nothing except change map membership by default it relocates the primary objects

Version:
1.0
 
 public class ReplicatedMap<K,V> extends AbstractReplicatedMap<K,V> {
 
     private static final long serialVersionUID = 1L;
 
     //--------------------------------------------------------------------------
     //              CONSTRUCTORS / DESTRUCTORS
     //--------------------------------------------------------------------------
     
Creates a new map

Parameters:
channel The channel to use for communication
timeout long - timeout for RPC messags
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
 
     public ReplicatedMap(MapOwner ownerChannel channellong timeoutString mapContextNameint initialCapacity,float loadFactorClassLoader[] cls) {
         super(owner,channeltimeoutmapContextNameinitialCapacityloadFactor.clstrue);
     }

    
Creates a new map

Parameters:
channel The channel to use for communication
timeout long - timeout for RPC messags
mapContextName String - unique name for this map, to allow multiple maps per channel
initialCapacity int - the size of this map, see HashMap
 
     public ReplicatedMap(MapOwner ownerChannel channellong timeoutString mapContextNameint initialCapacityClassLoader[] cls) {
         super(owner,channeltimeoutmapContextNameinitialCapacity.,.clstrue);
     }

    
Creates a new map

Parameters:
channel The channel to use for communication
timeout long - timeout for RPC messags
mapContextName String - unique name for this map, to allow multiple maps per channel
 
     public ReplicatedMap(MapOwner ownerChannel channellong timeoutString mapContextNameClassLoader[] cls) {
         super(ownerchanneltimeoutmapContextName,...clstrue);
     }

    
Creates a new map

Parameters:
channel The channel to use for communication
timeout long - timeout for RPC messags
mapContextName String - unique name for this map, to allow multiple maps per channel
terminate boolean - Flag for whether to terminate this map that failed to start.
 
     public ReplicatedMap(MapOwner ownerChannel channellong timeoutString mapContextNameClassLoader[] clsboolean terminate) {
         super(ownerchanneltimeoutmapContextName,.,
                 ..clsterminate);
     }
 
//------------------------------------------------------------------------------
//              METHODS TO OVERRIDE
//------------------------------------------------------------------------------
    @Override
    protected int getStateMessageType() {
    }

    
publish info about a map pair (key/value) to other nodes in the cluster

Parameters:
key Object
value Object
Returns:
Member - the backup node
Throws:
org.apache.catalina.tribes.ChannelException
    @Override
    protected Member[] publishEntryInfo(Object keyObject valuethrows ChannelException {
        if  (! (key instanceof Serializable && value instanceof Serializable)  ) return new Member[0];
        //select a backup node
        Member[] backup = getMapMembers();
        if (backup == null || backup.length == 0) return null;
        //publish the data out to all nodes
        MapMessage msg = new MapMessage(getMapContextName(), .false,
                                        (Serializablekey, (Serializablevaluenull,.getLocalMember(false), backup);
        getChannel().send(getMapMembers(), msggetChannelSendOptions());
        return backup;
    }
New to GrepCode? Check out our FAQ X