FileDocCategorySizeDatePackage
BackgroundProcess.javaAPI DocExample4154Mon Jul 23 13:26:52 BST 2007org.apache.struts2.interceptor

BackgroundProcess

public class BackgroundProcess extends Object implements Serializable
Background thread to be executed by the ExecuteAndWaitInterceptor.

Fields Summary
private static final long
serialVersionUID
protected Object
action
protected com.opensymphony.xwork2.ActionInvocation
invocation
protected String
result
protected Exception
exception
protected boolean
done
Constructors Summary
public BackgroundProcess(String threadName, com.opensymphony.xwork2.ActionInvocation invocation, int threadPriority)
Constructs a background process

param
threadName The thread name
param
invocation The action invocation
param
threadPriority The thread priority


                            
            
        this.invocation = invocation;
        this.action = invocation.getAction();
        try {
            final Thread t = new Thread(new Runnable() {
                public void run() {
                    try {
                        beforeInvocation();
                        result = invocation.invokeActionOnly();
                        afterInvocation();
                    } catch (Exception e) {
                        exception = e;
                    }

                    done = true;
                }
            });
            t.setName(threadName);
            t.setPriority(threadPriority);
            t.start();
        } catch (Exception e) {
            exception = e;
        }
    
Methods Summary
protected voidafterInvocation()
Called after the background thread determines the result code from the ActionInvocation, but before the background thread is marked as done.

throws
Exception any exception thrown will be thrown, in turn, by the ExecuteAndWaitInterceptor

    
protected voidbeforeInvocation()
Called before the background thread determines the result code from the ActionInvocation.

throws
Exception any exception thrown will be thrown, in turn, by the ExecuteAndWaitInterceptor

    
public java.lang.ObjectgetAction()
Retrieves the action.

return
the action.

        return action;
    
public java.lang.ExceptiongetException()
Gets the exception if any was thrown during the execution of the background process.

return
the exception or null if no exception was thrown.

        return exception;
    
public com.opensymphony.xwork2.ActionInvocationgetInvocation()
Retrieves the action invocation.

return
the action invocation

        return invocation;
    
public java.lang.StringgetResult()
Gets the result of the background process.

return
the result; null if not done.

        return result;
    
public booleanisDone()
Returns the status of the background process.

return
true if finished, false otherwise

        return done;