Shark Workflow Research 3-START process process

Source: Internet
Author: User
Tags wrapper

The shark workflow engine startup process is a more complex process, based on the Processstart method of the Jspclientutilities class, code analysis is as follows:

public static void Processstart (Sharkconnection SC, String mgrname) throws Exception {
if (Debug)
System.err.println ("#_processStartName_ #");
try {
if (!isprocessrunning (SC, mgrname)) {
Wfprocessmgr mgr = Sc.getprocessmgr (mgrname);//Get Process Definition Manager
Mgr.create_process (NULL). Start ();//create process and start
}
catch (Exception e) {
E.printstacktrace ();
Throw e;
}
}

The MGR is returned from the Org.enhydra.shark.SharkObjectFactory.createProcessMgrWrapper () method based on the reflection mechanism and in the Factory mode. Org.enhydra.shark.WfProcessMgrWrapper class. The Wfprocessmgrwrapper.create_process () method is as follows:

/**
* Create a Wfprocess object
*/
Public wfprocess create_process (Wfrequester requester) throws Exception, notenabled, Invalidrequester,
requesterrequired {
Long Tstamp = Sharkutilities.methodstart (Shandle, "wfprocessmgrwrapper.create_process");
try {
CheckSecurity ("create_process", null);/check Permissions
Wfprocessmgrinternal mgr = Getprocessmgrimpl (name);//Get internal process Definition Manager
Check if this process was allowed to be created only internally
if (Mgr.category (Shandle). Equalsignorecase (Xpdlconstants.access_level_private)) {//Check the access rights of the internal process definition Manager
throw new Notenabled ("The process definition defines only PRIVATE access!");
}
Wfrequesterinternal req = Sharkenginemanager.getinstance (). Getobjectfactory (). Createdefaultrequester (
Shandle, Sharkenginemanager.getinstance (). Getcallbackutilities (). GetUserID (Shandle), requester);//Create internal requestor
Wfprocessinternal procinternal = mgr.create_process (Shandle, req);//Create an internal process instance
wfprocess proc = sharkenginemanager.getinstance (). Getobjectfactory (). Createprocesswrapper (Shandle,
Procinternal.manager_name (Shandle), Procinternal.key (Shandle))//wrapper for creating internal process
return proc;
finally {
Sharkutilities.methodend (Shandle, Tstamp, "wfprocessmgrwrapper.create_process", this);
}
}

Shark creates a wrapper for the internal process Definition manager and process instance for external program access, and handles security checks, data preprocessing, and so on. Mgr actually creates the process instance, which is the Org.enhydra.shark.WfProcessMgrImpl class, which implements the Org.enhydra.shark.api.internal.working.WfProcessMgrInternal interface, the Create_process () method of the Wfprocessmgrimpl class is as follows:

/**
* Create a Wfprocess object
*/
Public wfprocessinternal create_process (Wmsessionhandle shandle, wfrequesterinternal requester) throws Exception,
Notenabled, Invalidrequester, requesterrequired {
if (state.value () = = process_mgr_statetype._disabled) {
throw new Notenabled ("Can" t create process based on wfprocessmgr ' "+ This +" '-it is disabled! ");
}
This can is changed-we can allow that some processes does not have to have
Requester
if (requester = = null) {
throw new Requesterrequired ("Can" t create process based on wfprocessmgr ' "+ This
+ "'-the requester is required!");
}
String procid = Getnextprocesskey (shandle);//Get Process instance ID
Wfprocessinternal process = Sharkenginemanager.getinstance (). Getobjectfactory (). CreateProcess (Shandle, this,
Requester, procid);//Through factory methods from Org.enhydra.shark.SharkObjectFactory.createProcess (Shandle, This,requester, ProcID) method to create an internal process instance
return process;
}

The shark creation process can be summed up in the following steps: Obtain the Process Definition Manager-> Obtain the internal Process Definition Manager-> Create an internal process instance-> create an internal process instance wrapper. At this point, the mgr.create_process (null) in the Jspclientutilities.processstart () method is just completed. This method returns a Org.enhydra.shark.WfProcessWrapper instance that implements the Org.enhydra.shark.api.client.wfmodel.WfProcess interface. The start () method for this class is as follows:

/**
* Starts the process-creates a separate thread.
*
* @exception exception
* @exception Cannotstart
* @exception alreadyrunning
*/
public void Start () throws Exception, Cannotstart, alreadyrunning {
Long Tstamp = Sharkutilities.methodstart (Shandle, "Wfprocesswrapper.start");
try {
CheckSecurity ("Start", null);
Wfprocessinternal procinternal = Getprocessimpl (ProcessID, Sharkutilities.write_mode);
Procinternal.start (Shandle);
finally {
Sharkutilities.methodend (Shandle, Tstamp, "Wfprocesswrapper.start", this);
}
}

is actually invoking the start () method of the internal process instance class Org.enhydra.shark.WfProcessImpl class. This class implements the Org.enhydra.shark.api.internal.working.WfProcessInternal interface, which is as follows:

/**
* Starts the process.
*
* @exception exception
* @exception Cannotstart
* @exception alreadyrunning
*/
public void Start (Wmsessionhandle shandle) throws Exception, Cannotstart, alreadyrunning, toolagentgeneralexception {
Checkreadonly ()//check read-only
if (State (Shandle). Equals (sharkconstants.state_open_running)) {//Check if it is started
throw new Alreadyrunning ("process" + toString () + "-the process is already Running-can ' t start again!");
}
if (State (Shandle). StartsWith (sharkconstants.stateprefix_closed)) {//check has stopped
throw new Cannotstart ("process" + toString () + "-The process is Closed-can ' t start it!");
}
if (Getprocessdefinition (Shandle). Getstartingactivities (). Size () = 0) {//check whether to define startup activity
throw new Cannotstart ("Process" + toString ()
+ "-there are no starting activities in the Process-can ' t start it!");
}
if (StartTime < Sharkconstants.undefined_time) {//Check if it is started
throw new Cannotstart ("Process" + toString () + "have been started already!");
}
try {
Startingthread = Thread.CurrentThread ();
Initialtransaction = null;
Change_state (Shandle, sharkconstants.state_open_running)//modify current state to run
Sharkenginemanager.getinstance (). Getcallbackutilities (). info (shandle, "Process" + This + "is starting ...");
Run (shandle, null);/START process
catch (Toolagentgeneralexception Tage) {
Change_state (Shandle, sharkconstants.state_closed_terminated);//If error, modify status to abort
throw Tage;
finally {
Actrequester = null;
Startingthread = null;
}
}

Perform a series of checks before you start, then modify the status and invoke the run operation, the running () method code:

protected void Run (Wmsessionhandle shandle, wfactivityinternal lastfinishedactivity) throws Exception,
toolagentgeneralexception {
IsRunning = true;//Modified status is running
try {
if (lastfinishedactivity = = null) {//Check whether there is a last run activity, if the new process, this situation is true
List starts = getprocessdefinition (shandle). Getstartingactivities ()//Get Started activity
for (Iterator it = Starts.iterator (); It.hasnext ();) {
Activity Actdef = (activity) it.next ();
StartActivity (Shandle, actdef, null);/start activity
}
Return
}
while (Lastfinishedactivities.size () > 0) {//The runtime in the START process will have this condition, that is, the activity will be placed at the end of the current activity lastfinishedactivities
if (!state.equals (sharkconstants.state_open_not_running_suspended)) {
System.out.println ("QN for Lfa" +lastfinishedactivities.get (0));
if (!state.startswith (sharkconstants.stateprefix_closed)) {
Queuenext (Shandle, (wfactivityinternal) lastfinishedactivities.get (0))//Get the next activity for the activity
System.out.println ("QN for Lfa" +lastfinishedactivities.get (0) + "
Finished ");
}
Lastfinishedactivities.remove (0);
} else {
System.out.println ("ELSE");
Return
}
}
if (State.startswith (sharkconstants.stateprefix_closed)) {
/*

* try {delete (t);} catch (TransactionException tme) {throw new

* Exception (TME); }

*/
Return
}
finally {
isrunning = false;//Recovery State is not running
}
}

The run () method is responsible for running each activity in the process, if the new process starts from the startup activity, and if the already running process finds the next activity from the last activity. Here's a look at the StartActivity () method:

Activates an Activity object
Protected wfactivityinternal startactivity (Wmsessionhandle shandle, activity activity, wfactivityinternal BA)
Throws Exception, Toolagentgeneralexception {
If is already activated (the case when XOR Join is reached twice or
More times, before the activity is executed), doing nothing
if (isactivitydefinitionactive (shandle, Activity, BA)) {//Check that the activity has started
Sharkenginemanager.getinstance (). Getcallbackutilities (). Warn (Shandle,
"Process" + this + "-> activity" + activity + "is already Started-can ' t start it twice");
return null;
}
Wfactivityinternal act = sharkenginemanager.getinstance (). Getobjectfactory (). Createactivity (Shandle, this,
Getnextworkitemid (Shandle, Activity.getid ()), Activity.getid (), BA);//Create an Activity instance
Sharkenginemanager.getinstance (). Getcallbackutilities (). info (Shandle,
"Process" + toString () + "-Activity" + act.tostring () + ' is created ');
Activitycache.add (Act.key (shandle), act);
SYSTEM.OUT.PRINTLN ("Activating act" +act);
Act.activate (Shandle)//Activate this activity
SYSTEM.OUT.PRINTLN ("Finished activation of Act" +act);
String causeclassname = null;
Handling block activity start and exc handling
if (activity.getactivitytype () = = Xpdlconstants.activity_type_block) {//Check for empty activity
try {
System.out.println ("Running block ...");
Runblock (shandle, Activity, act);/Handling Empty activities
System.out.println ("Finished running block");
catch (Toolagentgeneralexception ex) {
Causeclassname = Sharkutilities.extractexceptionname (ex);
Act.setexceptionname (Shandle, causeclassname);
Act.setexception (Shandle, ex);
}
else {//If it is not an empty activity, check the activation activity procedure for any exceptions
Causeclassname = Act.getexceptionname (Shandle);
}
if (causeclassname!= null) {//If an exception is thrown
if (Getexceptiontransfrom (shandle, Act, activity, causeclassname). Size () = 0) {
Exception Tage = act.getexception (Shandle);
if (Tage!= null) {
throw Tage;
}
throw new Exception ("Process" + toString ()
+ "-Unexpected exception from wfprocessimpl.startactivity ()");
}
}
Return Act;
}

At this point, the process initiation process has been completed, and the process of activating the activity and completing the activity should be elaborated in a separate chapter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.