Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/disk/RetryingUpdate.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.disk; | |
2 | |
3 import java.io.IOException; | |
4 | |
5 import java.util.logging.Logger; | |
6 import java.util.logging.Level; | |
7 | |
8 import com.sleepycat.je.DatabaseException; | |
9 import com.sleepycat.je.DeadlockException; | |
10 import com.sleepycat.je.LockNotGrantedException; | |
11 | |
12 import org.dancres.blitz.Logging; | |
13 | |
14 public class RetryingUpdate { | |
15 static Logger theLogger = | |
16 Logging.newLogger("org.dancres.blitz.disk.RetryingUpdate"); | |
17 | |
18 private RetryableOperation theOp; | |
19 | |
20 public RetryingUpdate(RetryableOperation anOp) { | |
21 theOp = anOp; | |
22 } | |
23 | |
24 public Object commit() throws IOException { | |
25 int myRetryCount = 0; | |
26 | |
27 do { | |
28 DiskTxn myTxn = DiskTxn.newNonBlockingStandalone(); | |
29 | |
30 try { | |
31 Object myResult = theOp.perform(myTxn); | |
32 | |
33 myTxn.commit(); | |
34 | |
35 if (myRetryCount != 0) { | |
36 if (theLogger.isLoggable(Level.FINE)) | |
37 theLogger.log(Level.FINE, | |
38 "Total retries: " + myRetryCount); | |
39 } | |
40 | |
41 return myResult; | |
42 } catch (DatabaseException aDbe) { | |
43 if ((aDbe instanceof DeadlockException) || | |
44 (aDbe instanceof LockNotGrantedException)) { | |
45 | |
46 if (theLogger.isLoggable(Level.FINEST)) | |
47 theLogger.log(Level.FINEST, "Got lock exception", aDbe); | |
48 | |
49 myTxn.abort(); | |
50 | |
51 | |
52 // System.err.println("Aborting" + theOp + " retry: " + | |
53 // myRetryCount); | |
54 | |
55 ++myRetryCount; | |
56 | |
57 BackoffGenerator.pause(); | |
58 | |
59 } else { | |
60 theLogger.log(Level.SEVERE, "Got Dbe", aDbe); | |
61 throw new IOException("Dbe"); | |
62 } | |
63 } | |
64 } while (true); | |
65 } | |
66 } |