|
SalesPoint v3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sale.SaleProcess
public abstract class SaleProcess
A process. Processes are used to manipulate data in DataBaskets
, Stocks
,
Catalogs
, and any other data structures you might want to use.
Processes are viewed as finite deterministic automata, internally represented by a directed graph. The
nodes of this graph are called Gates
, the edges are Transitions
.
Processes are persistent, i.e. they are automatically restored when the system comes up again after having been down for some time.
A process can be suspended whenever it is at a gate. When a process is asked to
suspend()
while it is in a transition, it will get suspended only at the next gate. For
this to be feasible, transitions must be rather short, and, in particular, must not comprise any user
interaction.
Nested Class Summary | |
---|---|
static class |
SaleProcess.ProcessLogEntry
A log entry describing a process that was executed. |
Field Summary | |
---|---|
static LogEntryFilter |
LOGENTRYFILTER_PROCESSES_ONLY
A LogEntryFilter that will accept only such LogEntries that stem from a process. |
protected Gate |
m_gCurGate
The current gate, if any. |
protected Transition |
m_tCurTransition
The current transition, if any. |
Fields inherited from interface sale.ProcessErrorCodes |
---|
DATABASKET_CONFLICT_ERROR, DUPLICATE_KEY_EXCEPTION, ERR_INTERNAL, ERR_LOWERBOUND, ERR_NOERROR, ERR_UPPERBOUND, NOT_ENOUGH_ELEMENTS_ERROR, REMOVE_VETO_EXCEPTION |
Constructor Summary | |
---|---|
SaleProcess(String sName)
Create a new SaleProcess with a given name. |
Method Summary | |
---|---|
DataBasket |
attach(DataBasket dbNew)
Attach the DataBaskte that is going to be used to implement transactional behavior for this Process. |
ProcessContext |
attach(ProcessContext pcNew)
Attach a ProcessContext to this process. |
boolean |
canQuit(boolean fContextDestroy)
Return true if this Process can be stopped with a subsequent quit()
command. |
DataBasket |
detachBasket()
Detach and return the current DataBasket. |
ProcessContext |
detachContext()
Detach and return the current process context. |
void |
error(int nErrorCode)
Raise an error in this process. |
void |
error(int nErrorCode,
Object oExtraInfo)
Raise an error in this process. |
void |
error(int nErrorCode,
Throwable tExtraInfo)
Raise an error in this process. |
DataBasket |
getBasket()
Get the currently attached DataBasket. |
Gate |
getCommitGate()
Return the gate to jump to when performing a commit. |
ProcessContext |
getContext()
Return the process context attached to this process. |
Gate |
getCurrentGate()
Return the gate at which the process currently stands or which it just left. |
protected Gate |
getErrorGate(int nErrorNesting)
Return the gate to jump to when an error occurs. |
String |
getErrorMsg(int nErrorCode)
Return a readable version of the error message. |
protected abstract Gate |
getInitialGate()
Return the initial gate for this process. |
LogEntry |
getLogData()
Return information that describes the process for logging purposes. |
Gate |
getLogGate()
Return the gate that the process must jump to if it wishes to be logged before finishing. |
String |
getName()
Return the name of this process. |
Gate |
getQuitGate()
Return the gate to jump to when quitting the process. |
Gate |
getRollbackGate()
Return the gate to jump to when performing a rollback. |
Gate |
getStopGate()
Return the last gate that this process should be at. |
boolean |
isAlive()
Return true if this process has been started, but has not yet died. |
boolean |
isResumed()
Return true if this process has been resumed from a previous suspended state. |
boolean |
isRunning()
Return true if this process is currently running. |
boolean |
isSuspended()
Return true if this process is currently suspended. |
void |
log(Loggable la)
Logs the given data to a log file. |
protected void |
onFinished()
Hook method called whenever the process was finished, independently of whether the process was really finished or just suspended. |
protected void |
onResumeOrStart(boolean fIsResume)
Hook method called on every start or resume of the process. |
protected void |
onSuspended()
Hook method called whenever the process was suspended. |
protected void |
printErrorInfo(int nErrorCode,
Object oExtraInfo)
Print error information to inform the user of an error condition. |
void |
quit(boolean fWaitQuit)
Quit the process at the nearest gate. |
void |
resume()
Resume a previously suspended process. |
void |
start()
Start the process. |
void |
suspend()
Suspend the process. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Gate m_gCurGate
protected Transition m_tCurTransition
public static final LogEntryFilter LOGENTRYFILTER_PROCESSES_ONLY
LogEntries
that stem from a process.
Constructor Detail |
---|
public SaleProcess(String sName)
sName
- the name of this process.Method Detail |
---|
public String getName()
public ProcessContext attach(ProcessContext pcNew)
pcNew
- the process context to be attached.
public ProcessContext detachContext()
public ProcessContext getContext()
public DataBasket attach(DataBasket dbNew)
dbNew
- the DataBasket to be attached.
public DataBasket detachBasket()
public DataBasket getBasket()
public boolean canQuit(boolean fContextDestroy)
quit()
command.
fContextDestroy
- true, if the quit request was issued due to a destroyal of
the process' context. If false you can assume that it will be possible to restore
and resume the Process after it had been quit
ted.
!fContextDestroy
, so that the process can
only be quitted, if it will be possible to resume it afterwards.!fContextDestroy
, so that the
process can only be quitted, if it will be possible to resume it afterwards.public void error(int nErrorCode)
First calls printErrorInfo(int, java.lang.Object)
to inform the user of the error condition,
then cancels the process by jumping to the "error" gate.
Attention:This method must only be called from within a gate or a transition of this process. If called from any other environment, unpredictable behavior will result.
nErrorCode
- the error code.public void error(int nErrorCode, Object oExtraInfo)
First calls printErrorInfo(int, java.lang.Object)
to inform the user of the error condition,
then cancels the process by jumping to the "error" gate.
Attention:This method must only be called from within a gate or a transition of this process. If called from any other environment, unpredictable behavior will result.
nErrorCode
- the error code.oExtraInfo
- additional information that explains the cause of the error.public void error(int nErrorCode, Throwable tExtraInfo)
First calls printErrorInfo(int, java.lang.Object)
to inform the user of the error condition,
then cancels the process by jumping to the "error" gate.
Attention:This method must only be called from within a gate or a transition of this process. If called from any other environment, unpredictable behavior will result.
nErrorCode
- the error code.tExtraInfo
- the exception that caused the error.protected void printErrorInfo(int nErrorCode, Object oExtraInfo)
Calls getErrorMsg(int)
to resolve the error code into an error message.
All occurences of "%o" in the error message are then replaced by the
extra information's string representation.
If the context has a useable display
a MsgForm
is displayed containing the error message.
Otherwise, the error message is printed to the standard error stream.
This method is never called directly, but rather called by the Framework as appropriate. Thus, it is assured, that user communication takes place at a gate only, even in the case of an error.
nErrorCode
- the error code.oExtraInfo
- additional information concerning the cause of the error.public String getErrorMsg(int nErrorCode)
nErrorCode
- the error code.
public void suspend() throws InterruptedException
This method will suspend the process at the nearest gate. The method will block until the process was suspended.
InterruptedException
- if an interrupt occurs in the calling thread while
waiting for the process to suspend.public final boolean isSuspended()
Attention:This method is not synchronized. This allows you to
call it from within a gate or transition without fear for deadlocks, but there
might be certain rare circumstances where the several isXXX()
methods' return values give an seemingly inconsistent picture.
public void resume()
This method will resume the process at the gate at which it was suspended.
public final boolean isResumed()
Attention:This method is not synchronized. This allows you to
call it from within a gate or transition without fear for deadlocks, but there
might be certain rare circumstances where the several isXXX()
methods' return values give an seemingly inconsistent picture.
public void start()
public final boolean isAlive()
In contrast to isRunning()
isAlive()
will also
return true for a process that has been suspended.
Attention:This method is not synchronized. This allows you to
call it from within a gate or transition without fear for deadlocks, but there
might be certain rare circumstances where the several isXXX()
methods' return values give an seemingly inconsistent picture.
public final boolean isRunning()
Attention:This method is not synchronized. This allows you to
call it from within a gate or transition without fear for deadlocks, but there
might be certain rare circumstances where the several isXXX()
methods' return values give an seemingly inconsistent picture.
protected void onResumeOrStart(boolean fIsResume)
This method is called in the process' main thread and any uncaught exception raised in this method will lead to the process being stopped.
fIsResume
- true if the process has not been started afresh, but rather has
been resumed.protected void onSuspended()
This method is called in the process' main thread and any uncaught exception raised in this method will lead to the process being stopped.
protected void onFinished()
You can find out whether the process was just suspended by calling
isSuspended()
.
This method is called in the process' main thread and any uncaught exception
raised in this method will be reported in this thread. This method must
not call error()
, however.
public void quit(boolean fWaitQuit) throws InterruptedException
quit()
first calls suspend()
then sets the current
gate to be the "quit" gate and finally resume()
-s the
process.
fWaitQuit
- if true, quit will block until the process ended.
InterruptedException
- if an interrupt occured in the calling thread
while waiting for the process to quit.getQuitGate()
public LogEntry getLogData()
getLogData
in interface Loggable
SaleProcess.ProcessLogEntry
public void log(Loggable la) throws LogNoOutputStreamException, IOException
log
in interface LogContext
la
- the event to be logged.
LogNoOutputStreamException
- if no OutputStream has been
specified for the log file.
IOException
- if an IOException occurs when writing to the
log file.public Gate getCurrentGate()
protected abstract Gate getInitialGate()
By the time this method gets called, you can assume that the working basket
and the
process context
have been properly initialized.
public Gate getQuitGate()
Transitions starting at this gate will usually perform a rollback and will then jump to the "stop" gate.
getStopGate()
,
getRollbackGate()
protected Gate getErrorGate(int nErrorNesting)
error
occurs.
Transition starting at this gate can perform any specific error handling and should then arrive at the "rollback" gate.
When this method is called, getCurrentGate()
will still deliver the
last valid gate.
nErrorNesting
- a value that indicates nested errors. This value increases with
every new error, so that values greater than 1 indicate errors that occured while
other errors where handled.
null
is returned to indicate the end of
the process.null
is returned to indicate the end of the process.public Gate getRollbackGate()
Transitions starting from this gate must roll back any data structures the process used.
getStopGate()
"log" gate
.public Gate getCommitGate()
Transitions starting from this gate must commit any data structures the process used.
getStopGate()
"log" gate
.public Gate getLogGate()
Transitions from this gate should log
the process into a log file of their choice and
then proceed to the "stop" gate
.
log()
method.public Gate getStopGate()
Transitions from this gate must return null
instead of a next gate.
null
, indicating no further processing is to be
performed.
|
SalesPoint v3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |