com.jstatcom.engine
Class PCall
- java.lang.Object
-
- java.lang.Thread
-
- com.jstatcom.engine.PCall
-
- All Implemented Interfaces:
- java.lang.Runnable
public abstract class PCall extends java.lang.ThreadThis class encapsulates procedure calls to carry out computational tasks in an extra thread. It can optionally be executed in a single worker thread by invoking the thread withexecute. Concrete subclasses must implementrunCodewith the respective algorithm for the computation. Subclasses can also overwritefinalCodefor output formatting or other tasks that should be carried out ifrunCodefinished successfully. All relevant data should be given as arguments in the constructor.A procedure call object can be invoked with the respective arguments from a GUI or a non GUI object. It helps to separate the program logic from the user interface part.
All events that are fired are synchronized with the Swing
EvenDispatchingThreadifisGui()==true.
-
-
Constructor Summary
Constructors Constructor and Description PCall()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description voidadd(PCall pCall)Adds another call object that will be executed if this call finished successfully.voidaddPCallListener(PCallListener l)Registers listener l such that it will receive notifications.voidcall(java.lang.String procName, JSCData[] args, JSCData[] retData)Adapter toEngine.callthat usesengine().voidcancel()Interrupts this call and calls thestopmethod of the engine.abstract Engineengine()Gets theEngineinstance that is used by this call for the convenience implementations of the adapter methods to the engine interface.booleanequals(java.lang.Object o)Overwrite protection method calls super method.voidexecute()Puts this call object in the worker thread queue.EDU.oswego.cs.dl.util.concurrent.ExecutorgetExecutor()Gets the executor that is used by theexecutemethod.OutHoldergetOutHolder()Gets the output holder component.longgetStartTime()Gets the system time at thread start.SymbolTablegetSymbolTable()Gets the currently used symbol table.inthashCode()Overwrite protection method calls super method.booleanisGui()Gets whether GUI mode is set.booleanisPrintDate()Gets whether date is printed in output.booleanisSuccess()Gets whether the call finished successfully.voidload(java.lang.String module, LoadTypes loadType, JSCData[] args)Adapter toEngine.loadthat usesengine().voidremove(PCall pCall)Removes an element from the list of calls that are executed if this call finishes ok.voidremovePCallListener(PCallListener l)Unregisters listener l so that it will no longer be notified.voidrun()Template method that callspreCode,runCodeandfinalCodein this order.voidsetGui(boolean gui)Sets GUI mode, iftrue/falsethe following features are enabled/disabled: event synchronization with Swing Swing dialogs are used to display error messages Default istrue.voidsetOutHolder(OutHolder outputHolder)Sets the output component that the results and other output should be written to.voidsetPrintDate(boolean b)Sets whether date is printed in output, the default istrue.voidsetSymbolTable(SymbolTable newSymbolTable)Sets the symbol table to access data objects.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Method Detail
-
addPCallListener
public final void addPCallListener(PCallListener l)
Registers listener l such that it will receive notifications.- Parameters:
l- listener to be added
-
getOutHolder
public OutHolder getOutHolder()
Gets the output holder component. The default isSystemOutHolder.- Returns:
- a component used to assemble output from this call
-
getStartTime
public long getStartTime()
Gets the system time at thread start.- Returns:
System.currentTimeMillis()when the call was started
-
getSymbolTable
public SymbolTable getSymbolTable()
Gets the currently used symbol table.- Returns:
- a symbol table
-
isSuccess
public boolean isSuccess()
Gets whether the call finished successfully.- Returns:
trueifrunCodewas successful
-
removePCallListener
public void removePCallListener(PCallListener l)
Unregisters listener l so that it will no longer be notified.- Parameters:
l- listener to be removed
-
run
public final void run()
Template method that callspreCode,runCodeandfinalCodein this order. It handles any exceptions that occur in these methods. The method has the following structure:- calls
startedof all registeredPCallListenerobjects - clears
getOutputbuffer - calls
runCode - calls
finalCodeif no exception was thrown and no interruption occured - output buffer is appended to
outHolderif no error occured (optional) - if an error occured, messages are written to a log4j logger and
outHolderand a dialog is shown (optional) - if interrupted, messages are written to a logger and
outHolder - if successfull and not interrupted, then
successandfinishedmethods ofPCallListenerobjects are called, otherwise onlyfinished
runCodeandfinalCodeas well as by setting:- setShowMessage
- setPrintDate
- setOutHolder
finalCodemethod of subclasses by using thegetOutputbuffer.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
- calls
-
setOutHolder
public void setOutHolder(OutHolder outputHolder)
Sets the output component that the results and other output should be written to. The default isSystemOutHolder.- Parameters:
outputHolder- write output to
-
setSymbolTable
public void setSymbolTable(SymbolTable newSymbolTable)
Sets the symbol table to access data objects. Subclasses must implement and document themselves which variables should be written or read to and from the symbol table. It is not used in the abstract implementation.- Parameters:
newSymbolTable- a new symbol table- Throws:
java.lang.IllegalArgumentException-if (newSymbolTable == null)
-
execute
public void execute()
Puts this call object in the worker thread queue. The call will be executed after every other call that has been queued before has finished. The queuing strategy can be changed by overwritinggetExecutor.Implementation
Callsexecute(Runnable command)fromutil.concurrent.QueuedExecutor.
-
cancel
public void cancel()
Interrupts this call and calls thestopmethod of the engine.
-
add
public void add(PCall pCall)
Adds another call object that will be executed if this call finished successfully. All added objects are stored in a list that keeps the original order. All calls are executed in the same thread as this call. If one of the added calls produces an error, the remaining calls are executed nevertheless.The event notification is done whenever a call was finished, meaning that
successandfinishedare called before the other elements of the list are started.- Parameters:
pCall- call object that is exectued conditional on this call to finish without error
-
remove
public void remove(PCall pCall)
Removes an element from the list of calls that are executed if this call finishes ok. Nothing happens ifpCallwas not added before.- Parameters:
pCall- the call object to remove
-
isPrintDate
public boolean isPrintDate()
Gets whether date is printed in output.- Returns:
trueif printed
-
setPrintDate
public void setPrintDate(boolean b)
Sets whether date is printed in output, the default istrue.- Parameters:
b-trueif printed
-
hashCode
public final int hashCode()
Overwrite protection method calls super method.- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
Overwrite protection method calls super method.- Overrides:
equalsin classjava.lang.Object
-
engine
public abstract Engine engine()
Gets theEngineinstance that is used by this call for the convenience implementations of the adapter methods to the engine interface.- Returns:
- a instance of
Engine
-
call
public void call(java.lang.String procName, JSCData[] args, JSCData[] retData)Adapter toEngine.callthat usesengine().- Parameters:
procName- procedure to be executed by this engineargs- the data to be used as inputretData- the return types- See Also:
Engine
-
load
public void load(java.lang.String module, LoadTypes loadType, JSCData[] args)Adapter toEngine.loadthat usesengine().- Parameters:
module- the name of the module to loadloadType- the type of module to loadargs- module load arguments if needed
-
getExecutor
public EDU.oswego.cs.dl.util.concurrent.Executor getExecutor()
Gets the executor that is used by theexecutemethod. The default implementation usesutil.concurrent.QueuedExecutor. Subclasses might overwrite this method to define a different execution policy.- Returns:
- instance of
Executorto be used byexecute
-
isGui
public boolean isGui()
Gets whether GUI mode is set.- Returns:
trueif in GUI mode,falseotherwise
-
setGui
public void setGui(boolean gui)
Sets GUI mode, iftrue/falsethe following features are enabled/disabled:- event synchronization with Swing
- Swing dialogs are used to display error messages
true.- Parameters:
gui-
-
-
DMelt 3.0 © DataMelt by jWork.ORG