Fields Summary |
---|
public static final String | TXN_REQUIREDStart a new transaction or use an existing one (like J2EE REQUIRED) |
public static final String | TXN_REQUIRES_NEWStart a new transaction, aborting any existing one (like J2EE REQUIRES_NEW) |
public static final String | TXN_MANDATORYRequire an existing transaction, erroring if there isn't one (like J2EE MANDATORY) |
public static final String | TXN_NONEHandle without a transaction, ignoring any existing one (like J2EE NOT_SUPPORTED) |
private String | txnType |
private Map | txnStatesByOp |
Methods Summary |
---|
protected Transaction | cancelTransaction()Cancels the current transaction if there is one for this listener.
return context.cancelTransaction(txnType);
|
protected java.lang.String | getOperationTxnState(java.lang.String operationId)Returns the transaction state (attribute)
return (String) txnStatesByOp.get(operationId);
|
protected Transaction | getTransaction()Returns the current transaction for this listener.
return context.getTransaction(txnType);
|
public java.lang.String | getTransactionType()Returns the transaction type used by this listener.
return txnType;
|
public void | handleMessage(com.aelitis.azureus.ui.swt.browser.msg.BrowserMessage message)Ensures the correct transaction state before handling the message.
String state = getOperationTxnState(message.getOperationId());
if ( state == null ) {
context.debug("Ignoring message without transactional state: " + message);
return;
}
Transaction txn = getTransaction();
if ( state.equals(TXN_REQUIRED) ) {
// start new if none exists
if ( txn == null ) {
txn = startTransaction();
}
}
else if ( state.equals(TXN_REQUIRES_NEW) ) {
// cancel current and start new
cancelTransaction();
txn = startTransaction();
}
else if ( state.equals(TXN_MANDATORY) ) {
// use existing or error
if ( txn == null ) {
transactionStateViolated(message, state, null);
return;
}
}
else if ( state.equals(TXN_NONE) ) {
// ignore existing
if ( txn != null ) {
txn = null;
}
}
else {
context.debug("Ignoring message with invalid transactional state (" + state + "): " + message);
return;
}
if ( txn != null ) {
handleTxnlMessage(message, txn);
}
else {
handleNonTxnlMessage(message);
}
|
protected void | handleNonTxnlMessage(com.aelitis.azureus.ui.swt.browser.msg.BrowserMessage message)Handle a browser message that doesn't require a transaction.
Subclasses must override if they have any non-transactional operations.
|
protected abstract void | handleTxnlMessage(com.aelitis.azureus.ui.swt.browser.msg.BrowserMessage message, Transaction txn)Handle a browser message that require a transaction. Subclasses must
implement this method, otherwise they should extend {@link AbstractMessageListener}.
|
private void | registerOperation(java.lang.String operationId, java.lang.String txnState)
txnStatesByOp.put(operationId, txnState);
|
protected void | registerOperationTxnMandatory(java.lang.String operationId)
registerOperation(operationId, TXN_MANDATORY);
|
protected void | registerOperationTxnNone(java.lang.String operationId)
registerOperation(operationId, TXN_NONE);
|
protected void | registerOperationTxnRequired(java.lang.String operationId)
registerOperation(operationId, TXN_REQUIRED);
|
protected void | registerOperationTxnRequiresNew(java.lang.String operationId)
registerOperation(operationId, TXN_REQUIRES_NEW);
|
protected Transaction | startTransaction()Starts a new transaction for this listener.
return context.startTransaction(txnType);
|
protected void | transactionStateViolated(com.aelitis.azureus.ui.swt.browser.msg.BrowserMessage message, java.lang.String state, Transaction txn)Called when the necessary transactional state is not correct
for the given message. Override to handle the error more gracefully.
throw new IllegalStateException("Transaction state violated - state: " + state + ", txn: " + txn);
|