01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.test.transactions;
05:
06: import com.tc.util.TCAssertionError;
07:
08: /**
09: * Implementations of this class represent a transactional object: something you can write and read transactionally. If
10: * you:
11: * </p>
12: * <ul>
13: * <li>Call {@link startWrite(Object)} just before you begin a transaction that writes to the object (or do the write,
14: * if transactions are automatic);</li>
15: * <li>Call {@link endWrite(Context)} just after you commit the transaction containing the write (or the write itself,
16: * if transactions are automatic), and pass in the {@link Context} that {@link startWrite(Object)} gave you;</li>
17: * <li>Call {@link startRead()} just before you begin a transaction that reads from the object (or do the read, if
18: * transactions are automatic); and</li>
19: * <li>Call {@link endRead(Context, Object)} just after you complete the transaction containing the read (or the read
20: * itself, if transactions are automatic), and pass in the {@link Context} that {@link startRead()} gave you;</li>
21: * </ul>
22: * <p>
23: * then, automatically, this class will check the consistency of your application. In other words, it will tell you if
24: * the value you read is something that couldn't <em>possibly</em> have been there, were the underlying store behaving
25: * truly transactionally.
26: * </p>
27: * <p>
28: * Implementations fail by throwing a {@link TCAssertionError}; that should be sufficient for its current uses in
29: * tests. If you need to improve it, by all means, go right ahead — but be careful, because the logic in the
30: * standard implementation is really quite tricky.
31: */
32: public interface TransactionalObject {
33:
34: public static interface Context {
35: // Nothing here.
36: }
37:
38: Context startWrite(Object value);
39:
40: Context startWrite(Object value, long now);
41:
42: void endWrite(Context rawWrite);
43:
44: void endWrite(Context rawWrite, long now);
45:
46: Context startRead();
47:
48: Context startRead(long now);
49:
50: void endRead(Context rawRead, Object result);
51:
52: void endRead(Context rawRead, Object result, long now);
53:
54: }
|