Transactional Queue
Jean Morissette <[email protected]> Sat, 04 Dec 2004 15:03:22 -0500
| Newsgroups | gmane.comp.java.seda.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Actually, SinkIF provide methods for transactional purpose. Fine! But,
the enqueue_prepare specification say:
"Note that this method does not protect "dangling prepares" -- that is,
a prepare without an associated commit or abort operation."
I think that we can and should protect "dangling prepares". Method
enqueue_prepare return an object corresponding to a key. Without this
key, the user cannot commit or abort the transaction.
Thus, it could be possible to protect "dangling prepares" just by
overloading the finalize() method of the object corresponding to a key:
public QueueImpl implements QueueIF {
Map transactionalMap;
public Object enqueue_prepare(Object x) {
Object key = new Key();
...
transactionalMap.put(key, x);
return key;
}
static class Key {
public void finalize() {
transactionalMap.remove(this);
}
}
}
Another possibility is to use WeakReference.
Also, I don't like that the user need to call many time
QueueIF.commit()/abort if he has enqueued elements in many queues. It's
error-prone and very ugly:
QueueElementIF x = ...
Object key1 = queue1.enqueue_prepare(x);
try {
Object key2 = queue2.enqueue_prepare(x);
} catch (SinkException e) {
queue1.enqueue_abort(key1);
throw e;
} try {
Object key3 = queue3.enqueue_prepare(x);
} catch (SinkException e) {
queue1.enqueue_abort(key1);
queue2.enqueue_abort(key2);
throw e;
}
queue1.enqueue_commit(key1);
queue2.enqueue_commit(key2);
queue3.enqueue_commit(key3);
I think this should be something like:
QueueElementIF x = ...
Transaction txn = ...
queue1.enqueue_prepare(txn, x);
try {
queue2.enqueue_prepare(txn, x);
queue3.enqueue_prepare(txn, x);
}
catch (SinkException e) {
txn.abort();
throw e;
}
txn.commit();
So, the user just need to call 1 time commit() or, if an exception
occur, 1 time abort(). But, who should create the Transaction object?
Jean M
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/