Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/remote/txn/TransactionManagerImpl.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.txn; | |
2 | |
3 import java.rmi.RemoteException; | |
4 import java.io.IOException; | |
5 | |
6 import net.jini.core.transaction.server.TransactionManager; | |
7 import net.jini.core.transaction.server.TransactionParticipant; | |
8 import net.jini.core.transaction.server.CrashCountException; | |
9 import net.jini.core.transaction.*; | |
10 import net.jini.core.lease.LeaseDeniedException; | |
11 import net.jini.core.lease.Lease; | |
12 import net.jini.core.entry.Entry; | |
13 import net.jini.core.lookup.ServiceID; | |
14 import net.jini.core.discovery.LookupLocator; | |
15 import net.jini.config.ConfigurationException; | |
16 import net.jini.config.NoSuchEntryException; | |
17 import net.jini.export.Exporter; | |
18 import net.jini.lookup.JoinManager; | |
19 import net.jini.lookup.ServiceIDListener; | |
20 import net.jini.lookup.entry.ServiceInfo; | |
21 import net.jini.lookup.entry.Name; | |
22 import net.jini.discovery.LookupDiscoveryManager; | |
23 import net.jini.id.Uuid; | |
24 | |
25 import com.sun.jini.lookup.entry.BasicServiceType; | |
26 | |
27 import org.dancres.blitz.config.ConfigurationFactory; | |
28 import org.dancres.blitz.VersionInfo; | |
29 import org.dancres.blitz.remote.BlitzServer; | |
30 import org.dancres.blitz.remote.ProxyFactory; | |
31 | |
32 /** | |
33 */ | |
34 public class TransactionManagerImpl implements TransactionManager, | |
35 ServiceIDListener { | |
36 | |
37 private JoinManager theJoinManager; | |
38 private Exporter theExporter; | |
39 private TransactionManager theStub; | |
40 private TransactionManager theProxy; | |
41 | |
42 private String[] theGroups; | |
43 private Entry[] theAttributes; | |
44 private LookupLocator[] theLocators; | |
45 | |
46 private BlitzServer theLandlord; | |
47 private Uuid theLandlordUuid; | |
48 | |
49 public TransactionManagerImpl(BlitzServer aLandlord, Uuid aLandlordUuid) | |
50 throws ConfigurationException, IOException { | |
51 theExporter = | |
52 ((Exporter) ConfigurationFactory.getEntry("loopbackTxnExporter", | |
53 Exporter.class, | |
54 null)); | |
55 | |
56 theGroups = (String[]) | |
57 ConfigurationFactory.getEntry("initialGroups", String[].class, | |
58 null); | |
59 | |
60 theLocators = | |
61 (LookupLocator[]) | |
62 ConfigurationFactory.getEntry("initialLocators", | |
63 LookupLocator[].class, | |
64 new LookupLocator[0]); | |
65 | |
66 String myName = null; | |
67 | |
68 try { | |
69 myName = | |
70 (String) | |
71 ConfigurationFactory.getEntry("name", String.class); | |
72 } catch (NoSuchEntryException aNSEE) { | |
73 // Doesn't matter | |
74 } | |
75 | |
76 theAttributes = getDefaultAttrs(myName); | |
77 | |
78 if (theExporter == null) { | |
79 // No exporter means we're not active | |
80 // | |
81 return; | |
82 } | |
83 | |
84 theStub = (TransactionManager) theExporter.export(this); | |
85 | |
86 LookupDiscoveryManager myLDM = | |
87 new LookupDiscoveryManager(theGroups, theLocators, null); | |
88 | |
89 theLandlord = aLandlord; | |
90 theLandlordUuid = aLandlordUuid; | |
91 | |
92 theProxy = new TxnMgrProxy(theStub, theLandlordUuid); | |
93 | |
94 LoopBackMgr.init(theProxy); | |
95 | |
96 theJoinManager = new JoinManager(theProxy, theAttributes, this, | |
97 myLDM, null, ConfigurationFactory.getConfig()); | |
98 } | |
99 | |
100 public void terminate() { | |
101 if (theJoinManager != null) { | |
102 theJoinManager.terminate(); | |
103 theExporter.unexport(true); | |
104 } | |
105 } | |
106 | |
107 public Created create(long leaseTime) throws LeaseDeniedException, | |
108 RemoteException { | |
109 | |
110 TxnTicket myTicket = LoopBackMgr.get().create(leaseTime); | |
111 | |
112 Lease myLease = | |
113 ProxyFactory.newLeaseImpl(theLandlord, theLandlordUuid, | |
114 myTicket.getUID(), myTicket.getLeaseTime()); | |
115 | |
116 return new TransactionManager.Created(myTicket.getUID().getId(), myLease); | |
117 } | |
118 | |
119 public void join(long id, TransactionParticipant transactionParticipant, long l1) | |
120 throws UnknownTransactionException, CannotJoinException, | |
121 CrashCountException, RemoteException { | |
122 throw new RemoteException("Remote participants are not supported - use Mahalo"); | |
123 } | |
124 | |
125 public int getState(long id) throws UnknownTransactionException, RemoteException { | |
126 throw new RemoteException("Remote participants are not supported - use Mahalo"); | |
127 } | |
128 | |
129 public void commit(long id) throws UnknownTransactionException, | |
130 CannotCommitException, RemoteException { | |
131 LoopBackMgr.get().commit(id); | |
132 } | |
133 | |
134 public void commit(long id, long timeout) throws UnknownTransactionException, | |
135 CannotCommitException, TimeoutExpiredException, RemoteException { | |
136 LoopBackMgr.get().commit(id, timeout); | |
137 } | |
138 | |
139 public void abort(long id) throws UnknownTransactionException, | |
140 CannotAbortException, RemoteException { | |
141 LoopBackMgr.get().abort(id); | |
142 } | |
143 | |
144 public void abort(long id, long timeout) throws UnknownTransactionException, | |
145 CannotAbortException, TimeoutExpiredException, RemoteException { | |
146 LoopBackMgr.get().abort(id, timeout); | |
147 } | |
148 | |
149 public void serviceIDNotify(ServiceID serviceID) { | |
150 // Don't care | |
151 } | |
152 | |
153 static Entry[] getDefaultAttrs(String aName) { | |
154 Entry myInfo = | |
155 new ServiceInfo("Blitz JavaSpaces Loopback TxnMgr", | |
156 VersionInfo.EMAIL_CONTACT, | |
157 VersionInfo.SUPPLIER_NAME, | |
158 VersionInfo.VERSION, "", ""); | |
159 | |
160 Entry myType = new BasicServiceType("TransactionManager"); | |
161 | |
162 if (aName != null) { | |
163 return new Entry[]{myInfo, myType, new Name(aName)}; | |
164 } else { | |
165 return new Entry[]{myInfo, myType}; | |
166 } | |
167 } | |
168 } |