1 21 package com.db4o.inside.replication; 22 23 import com.db4o.*; 24 import com.db4o.foundation.Hashtable4; 25 26 29 public class MigrationConnection { 30 31 public final YapStream _peerA; 32 public final YapStream _peerB; 33 34 private final Hashtable4 _referenceMap; 35 private final Hashtable4 _identityMap; 36 37 public MigrationConnection(YapStream peerA, YapStream peerB) { 38 _referenceMap = new Hashtable4(); 39 _identityMap = new Hashtable4(); 40 _peerA = peerA; 41 _peerB = peerB; 42 } 43 44 public void mapReference(Object obj, YapObject ref) { 45 46 48 50 56 _referenceMap.put(System.identityHashCode(obj), ref); 57 } 58 59 public void mapIdentity(Object obj, Object otherObj) { 60 _identityMap.put(System.identityHashCode(obj), otherObj); 61 } 62 63 64 public YapObject referenceFor(Object obj) { 65 int hcode = System.identityHashCode(obj); 66 YapObject ref = (YapObject) _referenceMap.get(hcode); 67 _referenceMap.remove(hcode); 68 return ref; 69 } 70 71 public Object identityFor(Object obj) { 72 int hcode = System.identityHashCode(obj); 73 return _identityMap.get(hcode); 74 } 75 76 77 public void terminate(){ 78 _peerA.migrateFrom(null); 79 _peerB.migrateFrom(null); 80 } 81 82 public YapStream peer(YapStream stream){ 83 if(_peerA == stream){ 84 return _peerB; 85 } 86 return _peerA; 87 } 88 89 90 91 } 92
| Popular Tags
|