Methods Summary |
---|
public synchronized Transaction | cancelTransaction(java.lang.String type)Cancels the current transaction if there is one for this listener
and the browser in the given message.
Transaction txn = getTransaction(type);
if ( txn != null ) {
txn.cancel();
}
return txn;
|
protected Transaction | createTransaction(java.lang.String type)Creates a new transaction for this listener and the browser
in the given message. If no transaction class was specified
in the constructor, subclasses must override this method.
Constructor ctor = (Constructor) txnCtors.get(type);
if ( ctor == null ) {
throw new IllegalStateException("Unregistered transaction type: " + type);
}
try {
Object[] params =
new Object[] {
new Integer(getNextTransactionId()),
type,
context
};
return (Transaction) ctor.newInstance(params);
}
catch ( Exception e ) {
throw new RuntimeException("Exception creating transaction for type " + type, e);
}
|
private int | getNextTransactionId()Increments the last transaction ID and returns the new value.
return ++lastTxnId;
|
public synchronized Transaction | getTransaction(java.lang.String type)Returns the current transaction of the given type.
return (Transaction) txns.get(type);
|
public void | registerTransactionType(java.lang.String type, java.lang.Class clazz)Registers the given transaction subclass as that to be created
for the given type identifier.
if ( clazz == null ) {
throw new IllegalArgumentException("Transaction class must be non-null");
}
if ( ! Transaction.class.isAssignableFrom(clazz) ) {
throw new IllegalArgumentException("Transaction class " + clazz.getName()
+ " must be a subclass of Transaction");
}
try {
Class[] ctorParams =
new Class[] {
Integer.TYPE,
String.class,
ClientMessageContext.class
};
Constructor ctor = clazz.getConstructor(ctorParams);
txnCtors.put(type, ctor);
}
catch ( Exception e ) {
throw new IllegalArgumentException(
"Cannot access appropriate constructor for "
+ clazz.getName());
}
|
synchronized boolean | removeTransaction(Transaction txn)Removes the given transaction from current status if it's current.
if ( txn != getTransaction(txn.getType()) ) {
return false;
}
return txns.remove(txn.getType()) == txn;
|
public synchronized Transaction | startTransaction(java.lang.String type)Starts a new transaction of the given type after canceling
the current transaction if any.
cancelTransaction(type);
Transaction txn = createTransaction(type);
if ( txn != null ) {
if ( ! txn.start() ) {
return null;
}
txns.put(type, txn);
}
return txn;
|