HowTos - Application Architecture: Processes

Implement a SalesProcess

Description:
SalesProcesses are the implementation of a deterministic finite automat. It shall be deemed to be a vectored graph with nodes called Gates and edges called Transitions. Make sure that user interaction only takes place in Gates while Transitions should be rather short without any user interaction. The reason is that a Process could only be suspended at a Gate and so the Shop is only able to persistify the Process at a Gate.
Often the display of a Gate is to be influenced by the user interaction before. In this case, Gates should be prepared with a Transition leading to this Gate. SaleProcesses could be startet in the Shop itself, but in most cases Processes take place in a SalesPointFrame and are startet from the SalesPoint.

Used classes:

Related topics:

ToDo:

  1. Create a subclass of SalesProcess.
  2. Add the constructor and therein call the super method to inherit from the Superclass, the SaleProcess.
    You can add any attribute to the constructor, most common is the Process' name.
  3. Every Process needs a starting Gate, the getInitialGate(). Add this method to the SaleProcess.
    Define the UIGate itself and add the necessary FormSheet etc. (see related topics).
    A basic implementation of SaleProcess is now done.
  4. To start the SaleProcess you can add a button to your SalesPoint's FormSheet and therewith lead to an action that runs the Process on your SalesPoint.
    Therefore an action was defined that runs any SalesProcess on a SalesPoint by passing the relevant process and a possible necessary DataBasket.
    (This structure was for example used in the "Videoautomat" tutorial).

Example Source Code:

SaleProcess class:

1
public class ArchitectureProcess extends SaleProcess
{
    2
    public ArchitectureProcess(String sName) {
        super(sName);
			
        // your (initializing) code here
    
    }
			
    3
    protected Gate getInitialGate()
    {
        UIGate uig_initial = new UIGate(null, null);
			
        // set FormSheet and other necessary things
    
        return uig_initial;
    }
}
		

SalesPoint class and relevant:

4
// SalesPoint class:
// set the FormSheet and call FormSheetContentCreator
    protected FormSheet getDefaultFormSheet()
    {
        FormSheet fs = new FormSheet("TutorialFormSheet",
                new ArchitectureSPointFormSheetCC(), false);
        return fs;
    }
			
// FormSheetContentCreator class:
public class ArchitectureSPointFormSheetCC extends FormSheetContentCreator
{

    protected void createFormSheetContent(FormSheet fs)
    {
        fs.removeAllButtons();
			
        // add a button that calls the TutorialRunProcessAction for running the TutorialProcess
        fs.addButton(
                "Start Tutorial Process",
                2, 
                new ArchitectureRunProcessAction(new ArchitectureProcess("TutorialProcess"), null));
			
    }
}
			
// TutorialRunProcessAction:
public class ArchitectureRunProcessAction implements Action
{

    private SaleProcess process;
    private DataBasket basket;

    public ArchitectureRunProcessAction(SaleProcess process, DataBasket basket)
    {
        this.process = process;
        this.basket = basket;
    }

    public void doAction(SaleProcess p, SalesPoint spoint) throws Throwable
    {
        if(basket != null)
            spoint.runProcess(process, basket);
        else
            spoint.runProcess(process);
    }

}
		
		

Back to:


Change quit behaviour

Description:
If a Process should have a certain task before finishing, you have to change its quit behaviour.
Therefore overwrite the method onFinished().

Used classes:

Related topics:

ToDo:

  1. Choose the SaleProcess you want to modify.
  2. implement the method protected void onFinished().
  3. add the code that should be run on quiting the process to the newly created method.

Example Source Code:

1
// SaleProcess class
public class ArchitectureProcess extends SaleProcess
{
    2
    // method to be overwritten
    protected void onFinished()
    {
	3
	// your code here			 
    }
			 
}
		

Back to:


Change start behaviour

Description:
If a Process should have a certain task after being resumed or started, you have to change its start behaviour.
Therefore overwrite the method onResumeOrStart().

Used classes:

Related topics:

ToDo:

  1. Choose the SaleProcess you want to modify.
  2. Implement the method protected void onResumeOrStart(boolean fIsResume).
  3. Add the code that should be run on starting/resuming the process to the newly created method.

Example Source Code:

1
// SaleProcess class
public class ArchitectureProcess extends SaleProcess
{
    2
    // method to be overwritten
    protected void onStartOrFinish(boolean fIsResume)
    {
	3
	// your code here			 
    }
			 
}
		

Back to:


Define a UIGate

Description:
Gates are a part of SalesProcesses. In contrast to normal Gates, UIGates are made for user interaction and can display FormSheets and MenuSheets. If you need to display something, use UIGates. Use JOptionPanes or JDialogs only to display short user interaction and information, because after serialisation they won´t be restored.
If you want to incorporate a UIGate not as StartGate, it may be mandatory to affect the view of the UIGate during Process. In this case, you have to use a Transition.

Used classes:

Related topics:

ToDo:

  1. Select the SaleProcess where you want to define your UIGate.
  2. Implement a method that returns a Gate as the class UIGate implements Gate.
  3. Create an instance of UIGate. Set the attributes to null as they will be set later.
  4. Define a FormSheet for the UIGate and add a FormSheetContentCreator that modifies the FormSheet.
    Use any FormSheet-Class and modify the FormSheetContentCreator and possible data accordingly.
    Available FormSheet-Classes are: LogOnForm, LogTableForm, MsgForm, SingleTableFormSheet, TextInputForm, TwoTableFormSheet, UserTableFormSheet.
  5. Assign the recently instantiated FormSheet to the UIGate.
  6. Return the instance of UIGate.

Example Source Code:

1
public class ArchitectureProcess extends SaleProcess
{
    2
    protected Gate getTutorialInteractionGate()
    {
        3
        UIGate uig_tutorial = new UIGate(null, null);
        4
        FormSheet fs_tutorial = new FormSheet("Tutorial", new ArchitectureSProcessFormSheetCC(), false);
        5
        uig_tutorial.setFormSheet(fs_tutorial);
        6
        return uig_tutorial;
    }
			
}
		

Back to:


Define a Gate

Description:
Gates are a part of SalesProcesses. If you want to implement user interaction, use UIGates. Normal Gates are preferably used to decide at which UIGate the Process continues. They are also very suitable for the implementation of background Processes. If you need data to prepared before the Gate goes into action, implement a Transition to the Gate.

Used classes:

Related topics:

ToDo:

  1. Select the SaleProcess where you want to define your Gate.
  2. Implement a method that returns a Gate.
  3. Instantiate the Gate and add the needed public Transition getNextTransition(SaleProcess process, User user) throws InterruptedException method.
  4. Add your code that selects the next GateChangeTransition.
  5. Return the Gate.

Example Source Code:

1
public class ArchitectureProcess extends SaleProcess
{
    2
    protected Gate getTutorialNoInteractionGate()
    {
        3
        Gate decisionGate = new Gate()
        {

            public Transition getNextTransition(SaleProcess process, User user)
                throws InterruptedException
            {
                4
                if(myCatalog.size(myDataBasket) == 0)
                {
                    return GateChangeTransition.CHANGE_TO_QUIT_GATE;
                }
                else
                {
                    return new GateChangeTransition(targetGate);
                }
            }
        };
        5
        return decisionGate;
    }
			
}
		

Back to:


Define a Transition

Description:
Transitions main task is to prepare Gates while the application is running. The idea is to manipulate the view of a Gate in order to react to user interaction or collected data of the past. It is possible to prepare normal Gates and UIGates as well.

Used classes:

Related topics:

ToDo:

  1. Create a class that implements Transition.
  2. In this class add the public Gate perform(SaleProcess process, User user) method. It's the place where the actions between two gates will be defined.
  3. Add your code to this method and return the Gate that will be the next target.
    Therefore you should cast the SaleProcess in the perform method to your Process class that currently calls the Transition. Then simply return the needed Gate from there.

Example Source Code:

Transition class:

1
public class ArchitectureTransition implements Transition
{
			
    2
    public Gate perform(SaleProcess process, User user)
    {
			
        3
        ArchitectureProcess processTutorial = (ArchitectureProcess) process;
			
        // your code here

        return processTutorial.getReturnGate();
    }
			
}
		

SalesProcess class:

    public Gate getReturnGate()
    {
        UIGate uig_return = new UIGate(null, null);
			
        // some other code
    
        return uig_return;
    }
		

Back to:


Define Transition that just changes to a Gate

Description:
During a running Process it may be volitional to change just to a Gate. This could be a not user interactive Gate, which has no Transition leading to it. It could be also an already prepared UIGate, to which you want to change after a "Back"-Button, when it should be not refreshed by the Transition. This might be the case, when the user interaction should be not erased.

Used classes:

Related topics:

ToDo:

  1. Use constructor of class GateChangeTransition: Transition t = new GateChangeTransition(Gate gTarget);.

Example Source Code:

// ...
    Gate tmpGate0 = new Gate()
        {
            public Transition getNextTransition(SaleProcess process, User user)
                throws InterruptedException
            {
                return new GateChangeTransition(targetGate);
            }
        };
// ...
		

Back to:


Define Transition that changes to a special Gate

Description:
There are six predefined Process Gates. All of them except the ErrorGate have a predefined Transition, leading to it.

Used classes:

Related topics:

ToDo:

  1. If you need the singelton instance of a special Process Gate, use the get-method of class SaleProcess:
    getCommitGate()
    getErrorGate(int nErrorNesting)
    getLogGate()
    getRollbackGate()
    getStopGate()
    getQuitGate()
  2. If you need a Transition, leading to a special Process Gate, use the static attributes of class GateChangeTransition:
    GateChangeTransition.CHANGE_TO_COMMIT_GATE
    GateChangeTransition.CHANGE_TO_LOG_GATE
    GateChangeTransition.CHANGE_TO_ROLLBACK_GATE
    GateChangeTransition.CHANGE_TO_STOP_GATE
    GateChangeTransition.CHANGE_TO_QUIT_GATE

Example Source Code:

// ...
    Gate tmpGate1 = new Gate()
        {
            public Transition getNextTransition(SaleProcess process, User user)
                throws InterruptedException
            {
                return GateChangeTransition.CHANGE_TO_QUIT_GATE;
            }
        };
// ...
		

Back to:


previous Application Architecture: SalesPointApplication Architecture: Time Management next



by Thomas Ryssel