import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.catalina.util.Enumerator;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
+import org.apache.catalina.ha.session.DeltaSession;
/**
* @author Filip Hanik
* @version 1.0
*/
-public class ReplicatedContext extends StandardContext implements LifecycleListener {
+public class ReplicatedContext extends StandardContext implements LifecycleListener,MapOwner {
private int mapSendOptions = Channel.SEND_OPTIONS_DEFAULT;
public static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog( ReplicatedContext.class );
protected boolean startComplete = false;
}
}
+
+ public void objectMadePrimay(Object key, Object value) {
+ //noop
+ }
+
}
\ No newline at end of file
import org.apache.catalina.tribes.Channel;
import org.apache.catalina.tribes.io.ReplicationStream;
import org.apache.catalina.tribes.tipis.LazyReplicatedMap;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap;
/**
*@author Filip Hanik
*@version 1.0
*/
-public class BackupManager extends StandardManager implements ClusterManager
+public class BackupManager extends StandardManager implements ClusterManager, MapOwner
{
public static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog( BackupManager.class );
//=========================================================================
// OVERRIDE THESE METHODS TO IMPLEMENT THE REPLICATION
//=========================================================================
+ public void objectMadePrimay(Object key, Object value) {
+ if (value!=null && value instanceof DeltaSession) {
+ DeltaSession session = (DeltaSession)value;
+ synchronized (session) {
+ session.access();
+ session.endAccess();
+ }
+ }
+ }
public Session createEmptySession() {
return new DeltaSession(this);
/**
* The owner of this map, ala a SessionManager for example
*/
- protected transient Object mapOwner;
+ protected transient MapOwner mapOwner;
/**
* External class loaders if serialization and deserialization is to be performed successfully.
*/
* Readable string of the mapContextName value
*/
protected transient String mapname = "";
+
+//------------------------------------------------------------------------------
+// map owner interface
+//------------------------------------------------------------------------------
+ public static interface MapOwner {
+ public void objectMadePrimay(Object key, Object value);
+ }
//------------------------------------------------------------------------------
// CONSTRUCTORS
* @param loadFactor float - load factor, see HashMap
* @param cls - a list of classloaders to be used for deserialization of objects.
*/
- public AbstractReplicatedMap(Object owner,
+ public AbstractReplicatedMap(MapOwner owner,
Channel channel,
long timeout,
String mapContextName,
* @param channelSendOptions int
* @param cls ClassLoader[]
*/
- protected void init(Object owner, Channel channel, String mapContextName, long timeout, int channelSendOptions,ClassLoader[] cls) {
+ protected void init(MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions,ClassLoader[] cls) {
log.info("Initializing AbstractReplicatedMap with context name:"+mapContextName);
this.mapOwner = owner;
this.externalLoaders = cls;
entry.setProxy(false);
Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
entry.setBackupNodes(backup);
+ mapOwner.objectMadePrimay(entry.getKey(),entry.getValue());
+
} catch (ChannelException x) {
log.error("Unable to relocate[" + entry.getKey() + "] to a new backup node", x);
}
return stateTransferred;
}
- public Object getMapOwner() {
+ public MapOwner getMapOwner() {
return mapOwner;
}
return accessTimeout;
}
- public void setMapOwner(Object mapOwner) {
+ public void setMapOwner(MapOwner mapOwner) {
this.mapOwner = mapOwner;
}
import org.apache.catalina.tribes.group.RpcCallback;
import org.apache.catalina.tribes.util.Arrays;
import org.apache.catalina.tribes.UniqueId;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
/**
* A smart implementation of a stateful replicated map. uses primary/secondary backup strategy.
implements RpcCallback, ChannelListener, MembershipListener {
protected static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog(LazyReplicatedMap.class);
-
+
//------------------------------------------------------------------------------
// CONSTRUCTORS / DESTRUCTORS
* @param initialCapacity int - the size of this map, see HashMap
* @param loadFactor float - load factor, see HashMap
*/
- public LazyReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, ClassLoader[] cls) {
+ public LazyReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, float loadFactor, ClassLoader[] cls) {
super(owner,channel,timeout,mapContextName,initialCapacity,loadFactor, Channel.SEND_OPTIONS_DEFAULT,cls);
}
* @param mapContextName String - unique name for this map, to allow multiple maps per channel
* @param initialCapacity int - the size of this map, see HashMap
*/
- public LazyReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
+ public LazyReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
super(owner, channel,timeout,mapContextName,initialCapacity, LazyReplicatedMap.DEFAULT_LOAD_FACTOR, Channel.SEND_OPTIONS_DEFAULT, cls);
}
* @param timeout long - timeout for RPC messags
* @param mapContextName String - unique name for this map, to allow multiple maps per channel
*/
- public LazyReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
+ public LazyReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
super(owner, channel,timeout,mapContextName, LazyReplicatedMap.DEFAULT_INITIAL_CAPACITY,LazyReplicatedMap.DEFAULT_LOAD_FACTOR,Channel.SEND_OPTIONS_DEFAULT, cls);
}
import org.apache.catalina.tribes.Member;
import org.apache.catalina.tribes.MembershipListener;
import org.apache.catalina.tribes.group.RpcCallback;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner;
/**
* All-to-all replication for a hash map implementation. Each node in the cluster will carry an identical
* @param initialCapacity int - the size of this map, see HashMap
* @param loadFactor float - load factor, see HashMap
*/
- public ReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity,float loadFactor, ClassLoader[] cls) {
+ public ReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity,float loadFactor, ClassLoader[] cls) {
super(owner,channel, timeout, mapContextName, initialCapacity, loadFactor, Channel.SEND_OPTIONS_DEFAULT, cls);
}
* @param mapContextName String - unique name for this map, to allow multiple maps per channel
* @param initialCapacity int - the size of this map, see HashMap
*/
- public ReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
+ public ReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, int initialCapacity, ClassLoader[] cls) {
super(owner,channel, timeout, mapContextName, initialCapacity, AbstractReplicatedMap.DEFAULT_LOAD_FACTOR,Channel.SEND_OPTIONS_DEFAULT, cls);
}
* @param timeout long - timeout for RPC messags
* @param mapContextName String - unique name for this map, to allow multiple maps per channel
*/
- public ReplicatedMap(Object owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
+ public ReplicatedMap(MapOwner owner, Channel channel, long timeout, String mapContextName, ClassLoader[] cls) {
super(owner, channel, timeout, mapContextName,AbstractReplicatedMap.DEFAULT_INITIAL_CAPACITY, AbstractReplicatedMap.DEFAULT_LOAD_FACTOR, Channel.SEND_OPTIONS_DEFAULT, cls);
}