KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > replication > MigrationConnection


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.inside.replication;
22
23 import com.db4o.*;
24 import com.db4o.foundation.Hashtable4;
25
26 /**
27  * @exclude
28  */

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 JavaDoc obj, YapObject ref) {
45         
46         // FIXME: Identityhashcode is not unique
47

48         // ignored for now, since it is on most VMs.
49

50         // This should be fixed by adding
51
// putIdentity and getIdentity methods to Hashtable4,
52
// using the actual object as the parameter and
53
// checking for object identity in addition to the
54
// hashcode
55

56         _referenceMap.put(System.identityHashCode(obj), ref);
57     }
58     
59     public void mapIdentity(Object JavaDoc obj, Object JavaDoc otherObj) {
60         _identityMap.put(System.identityHashCode(obj), otherObj);
61     }
62
63
64     public YapObject referenceFor(Object JavaDoc 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 JavaDoc identityFor(Object JavaDoc 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