Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/remote/TxnParticipantProxy.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.remote; | |
2 | |
3 import java.rmi.RemoteException; | |
4 | |
5 import java.io.Serializable; | |
6 import java.io.IOException; | |
7 | |
8 import net.jini.core.transaction.server.TransactionParticipant; | |
9 import net.jini.core.transaction.server.TransactionManager; | |
10 | |
11 import net.jini.core.transaction.UnknownTransactionException; | |
12 | |
13 import net.jini.id.Uuid; | |
14 import net.jini.id.ReferentUuid; | |
15 import net.jini.id.ReferentUuids; | |
16 | |
17 import org.dancres.blitz.remote.nio.FastSpace; | |
18 | |
19 public class TxnParticipantProxy implements Serializable, ReferentUuid, | |
20 TransactionParticipant { | |
21 | |
22 FastSpace theFast; | |
23 TransactionParticipant theStub; | |
24 Uuid theUuid; | |
25 | |
26 TxnParticipantProxy(TransactionParticipant aStub, Uuid aUuid) { | |
27 theStub = aStub; | |
28 theUuid = aUuid; | |
29 } | |
30 | |
31 void enableFastIO(FastSpace aSpace) { | |
32 theFast = aSpace; | |
33 } | |
34 | |
35 synchronized FastSpace getFastChannel() { | |
36 if (theFast != null) { | |
37 if (! theFast.isInited()) { | |
38 try { | |
39 theFast.init(); | |
40 } catch (IOException anIOE) { | |
41 throw new Error("Panic: fast io didn't init", anIOE); | |
42 } | |
43 } | |
44 } | |
45 | |
46 return theFast; | |
47 } | |
48 | |
49 public Uuid getReferentUuid() { | |
50 return theUuid; | |
51 } | |
52 | |
53 public int prepare(TransactionManager aMgr, long anId) | |
54 throws UnknownTransactionException, RemoteException { | |
55 | |
56 if (getFastChannel() != null) | |
57 return getFastChannel().prepare(aMgr, anId); | |
58 else | |
59 return theStub.prepare(aMgr, anId); | |
60 } | |
61 | |
62 public void commit(TransactionManager aMgr, long anId) | |
63 throws UnknownTransactionException, RemoteException { | |
64 | |
65 if (getFastChannel() != null) | |
66 getFastChannel().commit(aMgr, anId); | |
67 else | |
68 theStub.commit(aMgr, anId); | |
69 } | |
70 | |
71 public void abort(TransactionManager aMgr, long anId) | |
72 throws UnknownTransactionException, RemoteException { | |
73 | |
74 if (getFastChannel() != null) | |
75 getFastChannel().abort(aMgr, anId); | |
76 else | |
77 theStub.abort(aMgr, anId); | |
78 } | |
79 | |
80 public int prepareAndCommit(TransactionManager aMgr, long anId) | |
81 throws UnknownTransactionException, RemoteException { | |
82 | |
83 if (getFastChannel() != null) | |
84 return getFastChannel().prepareAndCommit(aMgr, anId); | |
85 else | |
86 return theStub.prepareAndCommit(aMgr, anId); | |
87 } | |
88 | |
89 public boolean equals(Object anObject) { | |
90 return ReferentUuids.compare(this, anObject); | |
91 } | |
92 | |
93 public int hashCode() { | |
94 return theUuid.hashCode(); | |
95 } | |
96 } |