FileDocCategorySizeDatePackage
Transaction.javaAPI DocAzureus 3.0.3.47349Mon Jun 04 17:50:20 BST 2007com.aelitis.azureus.ui.swt.browser.txn

Transaction

public abstract class Transaction extends Object
Encapsulates a single transaction that interacts with a single SWT {@link Browser}, possibly across multiple pages. Transactions are started after being created and cannot be restarted. They can be marked as cancelled or completed while running. Once stopped, they are left as either completed or cancelled. Subclasses may override starting, canceling, and stopping to perform their own specific actions and return false to abort.
author
dharkness
created
Jul 19, 2006

Fields Summary
private int
id
private String
type
private com.aelitis.azureus.core.messenger.ClientMessageContext
context
private boolean
running
private boolean
cancelled
private boolean
completed
Constructors Summary
public Transaction(int id, String type, com.aelitis.azureus.core.messenger.ClientMessageContext context)



                
        this.id = id;
        this.type = type;
        this.context = context;
    
Methods Summary
public booleancancel()
Marks this transaction as cancelled if it is running and not complete. A transaction may be cancelled only once. After that, false is returned.

        debug("cancel");
        if ( ! running || completed || cancelled ) {
            return false;
        }
        
        debug("canceling");
        if ( ! canceling() ) {
            return false;
        }
        
        debug("cancelled");
        cancelled = true;
        context.getTransactionManager().removeTransaction(this);
        
        return true;
    
protected booleancanceling()
Performs subclass-specific initialization to cancel the transaction. Return false to abort the cancellation.

return
whether or not the transaction can be cancelled

        return true;
    
protected voiddebug(java.lang.String message)
Displays a debug message tagged with the context ID.

param
message sent to the debug log

        context.debug("[" + this + "] " + message);
    
protected voiddebug(java.lang.String message, java.lang.Throwable t)
Displays a debug message and exception tagged with the context ID.

param
message sent to the debug log
param
t exception to log with message

        context.debug("[" + this + "] " + message, t);
    
protected voidexecuteInBrowser(java.lang.String javascript)
Executes the given Javascript code in the browser.

param
javascript the code to execute

        if ( context.getTransaction(type) == this ) {
            context.executeInBrowser(javascript);
        }
        else {
            debug("Non-current transaction cannot execute: " + javascript);
        }
    
public intgetId()

        return id;
    
public java.lang.StringgetType()

        return type;
    
public booleanisCancelled()
Returns true if this transaction has been cancelled.

        return cancelled;
    
public booleanisCompleted()
Returns true if this transaction has started and is still running.

        return completed;
    
public booleanisRunning()
Returns true if this transaction has started and is still running.

        return running;
    
protected voidsendBrowserMessage(java.lang.String key, java.lang.String op)
Sends a message to the JavaScript in the page.

param
key identifies the listener to receive the message
param
op identifies the operation to perform

        sendBrowserMessage(key, op, null);
    
protected voidsendBrowserMessage(java.lang.String key, java.lang.String op, java.util.Map params)
Sends a message to the JavaScript in the page.

param
key identifies the listener to receive the message
param
op identifies the operation to perform
param
params optional message parameters

        if ( context.getTransaction(type) == this ) {
            context.sendBrowserMessage(key, op, params);
        }
        else {
            debug("Non-current transaction cannot send: " + key + "." + op);
        }
    
public booleanstart()
Starts the transaction if it is not yet running, completed or cancelled. A transaction may be started only once. After that, false is returned.

        debug("start");
        if ( running || completed || cancelled ) {
            return false;
        }
        
        debug("starting");
        if ( ! starting() ) {
            return false;
        }
        
        debug("started");
        running = true;
        return true;
    
protected booleanstarting()
Performs subclass-specific initialization to start the transaction. Return false to abort the start.

return
whether or not the transaction can start

        return true;
    
protected booleanstop()
Marks this transaction as completed if it is running and not cancelled. If it is running and cancelled, it is simply marked as not running. A transaction may be stopped only once. After that, false is returned.

        debug("stop");
        if ( ! running ) {
            return false;
        }
        
        debug("stopping");
        if ( ! stopping() ) {
            return false;
        }
        
        debug("stopped");
        running = false;
        completed = ! cancelled;
        context.getTransactionManager().removeTransaction(this);
        
        return true;
    
protected booleanstopping()
Performs subclass-specific initialization to stop the transaction. Return false to abort the stop.

return
whether or not the transaction can be stopped

        return true;
    
public java.lang.StringtoString()

        return type + "-" + id
                + (running ? "-running" : "")
                + (cancelled ? "-cancelled" : "")
                + (completed ? "-completed" : "");