01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: 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.internal.replication;
22:
23: import com.db4o.foundation.Hashtable4;
24: import com.db4o.internal.*;
25:
26: /**
27: * @exclude
28: */
29: public class MigrationConnection {
30:
31: public final ObjectContainerBase _peerA;
32: public final ObjectContainerBase _peerB;
33:
34: private final Hashtable4 _referenceMap;
35: private final Hashtable4 _identityMap;
36:
37: public MigrationConnection(ObjectContainerBase peerA,
38: ObjectContainerBase peerB) {
39: _referenceMap = new Hashtable4();
40: _identityMap = new Hashtable4();
41: _peerA = peerA;
42: _peerB = peerB;
43: }
44:
45: public void mapReference(Object obj, ObjectReference ref) {
46:
47: // FIXME: Identityhashcode is not unique
48:
49: // ignored for now, since it is on most VMs.
50:
51: // This should be fixed by adding
52: // putIdentity and getIdentity methods to Hashtable4,
53: // using the actual object as the parameter and
54: // checking for object identity in addition to the
55: // hashcode
56:
57: _referenceMap.put(System.identityHashCode(obj), ref);
58: }
59:
60: public void mapIdentity(Object obj, Object otherObj) {
61: _identityMap.put(System.identityHashCode(obj), otherObj);
62: }
63:
64: public ObjectReference referenceFor(Object obj) {
65: int hcode = System.identityHashCode(obj);
66: ObjectReference ref = (ObjectReference) _referenceMap
67: .get(hcode);
68: _referenceMap.remove(hcode);
69: return ref;
70: }
71:
72: public Object identityFor(Object obj) {
73: int hcode = System.identityHashCode(obj);
74: return _identityMap.get(hcode);
75: }
76:
77: public void terminate() {
78: _peerA.migrateFrom(null);
79: _peerB.migrateFrom(null);
80: }
81:
82: public ObjectContainerBase peer(ObjectContainerBase stream) {
83: if (_peerA == stream) {
84: return _peerB;
85: }
86: return _peerA;
87: }
88:
89: }
|