001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.object.tx;
005:
006: import com.tc.net.protocol.tcm.ChannelIDProvider;
007: import com.tc.object.ObjectID;
008: import com.tc.object.TCObject;
009: import com.tc.object.dmi.DmiDescriptor;
010: import com.tc.object.session.SessionID;
011:
012: import java.util.Collection;
013: import java.util.List;
014: import java.util.Map;
015: import java.util.Set;
016:
017: /**
018: * Threadlocal based transaction manager interface. Changes go through here to the transaction for the current thread.
019: *
020: * @author steve
021: */
022: public interface ClientTransactionManager {
023:
024: /**
025: * Begin a thread local transaction
026: * @param lock Lock name
027: * @param lockLevel Lock level
028: * @return If begun
029: */
030: public boolean begin(String lock, int lockLevel);
031:
032: /**
033: * Try with wait() to begin a thread local transaction.
034: * @param lock Lock name
035: * @param timeout Specification of wait()
036: * @param lockLevel Lock level
037: * @return If begun
038: */
039: public boolean tryBegin(String lock, WaitInvocation timeout,
040: int lockLevel);
041:
042: /**
043: * Commit a thread local current transaction
044: * @param lockName Lock name
045: * @throws UnlockedSharedObjectException If a shared object is being accessed from outside a shared transaction
046: */
047: public void commit(String lockName)
048: throws UnlockedSharedObjectException;
049:
050: /**
051: * When transactions come in from the L2 we use this method to apply them. We will have to get a bit fancier because
052: * we can't apply any changes while we are in any transaction. The first version will not allow apply to happen while
053: * ANY tx is in progress. This is probably not exceptable. We will probably figure something out with the lock manager
054: * where we can accuire a read lock if a field is accessed in a transaction
055: * @param txType Transaction type
056: * @param lockIDs Locks involved in the transaction
057: * @param objectChanges Collection of DNA indicating changes
058: * @param lookupObjectIDs ObjectIDs
059: * @param newRoots Map of new roots, Root name -> ObjectID
060: */
061: public void apply(TxnType txType, List lockIDs,
062: Collection objectChanges, Set lookupObjectIDs, Map newRoots);
063:
064: /**
065: * Add new managed object to current transaction
066: * @param source TCObject
067: */
068: public void createObject(TCObject source);
069:
070: /**
071: * Add new root to current transaction
072: * @param name Root name
073: * @param id Object identifier
074: */
075: public void createRoot(String name, ObjectID id);
076:
077: /**
078: * Record change in literal value in current transaction
079: * @param source TCObject for literal value
080: * @param newValue New value
081: * @param oldValue Old value
082: */
083: public void literalValueChanged(TCObject source, Object newValue,
084: Object oldValue);
085:
086: /**
087: * Record field change in current transaction
088: * @param source TCObject for field
089: * @param classname Class name
090: * @param fieldname Field name
091: * @param newValue New object
092: * @param index Into array if field is an array
093: */
094: public void fieldChanged(TCObject source, String classname,
095: String fieldname, Object newValue, int index);
096:
097: /**
098: * Record a logical method invocation
099: * @param source TCObject for object
100: * @param method Method constant from SerializationUtil
101: * @param methodName Method name
102: * @param parameters Parameter values in call
103: */
104: public void logicalInvoke(TCObject source, int method,
105: String methodName, Object[] parameters);
106:
107: /**
108: * Record wait() call on object in current transaction
109: * @param lockName Lock name
110: * @param call wait() call information
111: * @param object Object being locked
112: * @throws UnlockedSharedObjectException If shared object accessed outside lock
113: * @throws InterruptedException If thread interrupted
114: */
115: public void wait(String lockName, WaitInvocation call, Object object)
116: throws UnlockedSharedObjectException, InterruptedException;
117:
118: /**
119: * Record notify() or notifyAll() call on object in current transaction
120: * @param lockName Lock name
121: * @param all True if notifyAll()
122: * @param object Object notify called on
123: * @throws UnlockedSharedObjectException If shared object accessed outside lock
124: */
125: public void notify(String lockName, boolean all, Object object)
126: throws UnlockedSharedObjectException;
127:
128: /**
129: * For optimistic stuff
130: * @return Transaction
131: */
132: public ClientTransaction getTransaction()
133: throws UnlockedSharedObjectException;
134:
135: /**
136: * Record acknowledgement
137: * @param sessionID Session identifier
138: * @param requestID Transaction identifier
139: */
140: public void receivedAcknowledgement(SessionID sessionID,
141: TransactionID requestID);
142:
143: /**
144: * Record batch acknowledgement
145: * @param batchID Transaction batch identifier
146: */
147: public void receivedBatchAcknowledgement(TxnBatchID batchID);
148:
149: /**
150: * Check whether current transaction has write access
151: * @param context The object context
152: * @throws com.tc.object.util.ReadOnlyException If in read-only transaction
153: */
154: public void checkWriteAccess(Object context);
155:
156: /**
157: * Add reference to tco in current transaction
158: * @param tco TCObject
159: */
160: public void addReference(TCObject tco);
161:
162: /**
163: * Get channel provider for this txn manager
164: * @return Provider
165: */
166: public ChannelIDProvider getChannelIDProvider();
167:
168: /**
169: * Check whether the lock wih this name in this thread is holding the lock at this level
170: * @param lockName Lock name
171: * @param lockLevel Lock level
172: * @return True if this lock is held by this thread at lockLevel
173: */
174: public boolean isLocked(String lockName, int lockLevel);
175:
176: /**
177: * Lock this lock at this level
178: * @param lockName Lock name
179: * @param lockLevel Lock level
180: */
181: public void lock(String lockName, int lockLevel);
182:
183: /**
184: * Unlock the lock
185: * @param Lock name
186: */
187: public void unlock(String lockName);
188:
189: /**
190: * Get number of threads holding this lock
191: * @param lockName Lock name
192: * @param lockLevel Lock level
193: * @return Count
194: */
195: public int localHeldCount(String lockName, int lockLevel);
196:
197: /**
198: * Check whether the current thread holds this lock
199: * @param lockName Lock name
200: * @param lockLevel Lock level
201: */
202: public boolean isHeldByCurrentThread(String lockName, int lockLevel);
203:
204: /**
205: * Get current queue length on this lock
206: * @param lockName Lock name
207: */
208: public int queueLength(String lockName);
209:
210: /**
211: * Get wait() length on this lock
212: * @param lockName Lock name
213: * @return Wait length
214: */
215: public int waitLength(String lockName);
216:
217: /**
218: * Enable transaction logging
219: */
220: public void enableTransactionLogging();
221:
222: /**
223: * Disable transaction logging
224: */
225: public void disableTransactionLogging();
226:
227: /**
228: * Check whether transaction logging is disabled
229: * @return True if disabled, false if enabled
230: */
231: public boolean isTransactionLoggingDisabled();
232:
233: /**
234: * Record an array change in the current transaction
235: * @param src The TCObject for the array
236: * @param startPos Start index in the array
237: * @param array The new partial array or value
238: * @param length Partial array length
239: */
240: public void arrayChanged(TCObject src, int startPos, Object array,
241: int length);
242:
243: /**
244: * Add distributed method call descriptor to current transaction
245: * @param d Descriptor
246: */
247: public void addDmiDescriptor(DmiDescriptor d);
248:
249: /**
250: * Check if lockID is on top of the transaction stack
251: * @param lockName
252: */
253: public boolean isLockOnTopStack(String lockName);
254:
255: }
|