Re: processes running not in parallel
Monique Maker <[email protected]> Wed, 17 Aug 2005 12:47:09 +0300
| Newsgroups | gmane.comp.java.enhydra.shark |
|---|---|
| Message-ID | <[email protected]> |
Hello He Wei,
Here is the modified JavaClassAgentTool:
package ourPackage;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.logging.Logger;
import org.enhydra.shark.Shark;
import org.enhydra.shark.api.SharkTransaction;
import org.enhydra.shark.api.client.wfservice.AdminMisc;
import org.enhydra.shark.api.internal.toolagent.AppParameter;
import org.enhydra.shark.api.internal.toolagent.ApplicationBusy;
import org.enhydra.shark.api.internal.toolagent.ApplicationNotDefined;
import org.enhydra.shark.api.internal.toolagent.ApplicationNotStarted;
import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException;
import org.enhydra.shark.toolagent.AbstractToolAgent;
/**
* Tool agent that executes special kind of java class.
*/
public class JavaClassToolAgent extends AbstractToolAgent {
public static final String TA_PARAM_RESOURCE_ID = "ResourceId";
public static final String TA_PARAM_ACTIVITY_ID = "ActivityId";
public static final String TA_PARAM_PROCESS_INSTANCE_ID = "ProcessInstanceId";
// standard java logging API will be used
private static String LOG_CLASSNAME = JavaClassToolAgent.class.getName();
private static Logger LOGGER = Logger.getLogger( LOG_CLASSNAME );
private static final String EXECUTION_METHOD_NAME = "execute";
/**
* @param t
* @param handle
* @param applicationName
* @param procInstId
* @param assId
* @param parameters
* @param appMode
*
* @throws ApplicationNotStarted
* @throws ApplicationNotDefined
* @throws ApplicationBusy
* @throws ToolAgentGeneralException
* @see org.enhydra.shark.api.internal.toolagent.ToolAgent#invokeApplication(org.enhydra.shark.api.SharkTransaction, long, java.lang.String, java.lang.String, java.lang.String, org.enhydra.shark.api.internal.toolagent.AppParameter[], java.lang.Integer)
*/
public void invokeApplication (SharkTransaction t,
long handle,
String applicationName,
String procInstId,
String assId,
AppParameter[] parameters,
Integer appMode)
throws ApplicationNotStarted, ApplicationNotDefined,
ApplicationBusy, ToolAgentGeneralException {
super.invokeApplication(t,handle,applicationName,procInstId,assId,parameters,appMode);
final String THIS_METHOD_NAME = "invokeApplication";
LOGGER.finest("Entering " + THIS_METHOD_NAME);
try {
status=APP_STATUS_RUNNING;
if (appName==null || appName.trim().length()==0) {
readParamsFromExtAttributes((String)parameters[0].the_value);
}
ClassLoader cl=getClass().getClassLoader();
Class c = cl.loadClass(appName);
AdminMisc adminMisc;
String activityId;
String resourceId;
HashMap toolAgentParams = new HashMap(7); //Storage for the this method parameters to pass to the tool
adminMisc = Shark.getInstance().getAdminInterface().getAdminMisc();
adminMisc.connect( LOG_CLASSNAME ); //The user name is not interesting - use the class name
activityId = adminMisc.getAssignmentActivityId(t, procInstId, assId);
resourceId = adminMisc.getAssignmentResourceUsername(t, procInstId, assId);
LOGGER.finer("Executing ToolAgent " + c.getName() + ": "
+ "Application name = " + applicationName
+ "Process instance ID = " + procInstId
+ "Activity ID = " + activityId
+ "Resource ID = " + resourceId);
//VK: Pack this method parameters data to pass to the tool.
//VK: Use String constants for the parameters names. The same constants will be used by the tool to unpack the data.
toolAgentParams.put(TA_PARAM_PROCESS_INSTANCE_ID, procInstId);
toolAgentParams.put(TA_PARAM_ACTIVITY_ID, activityId);
toolAgentParams.put(TA_PARAM_RESOURCE_ID, resourceId);
// Get parameter types - ignore 1. param, these are ext.attribs
Class[] parameterTypes=null;
//VK: Copy all method parameter types and later replace the first one
// if (parameters!=null) {
// parameterTypes=new Class[parameters.length-1];
// for (int i=1; i<parameters.length; i++) {
// parameterTypes[i-1]=AppParameter.class;
// }
// }
if (parameters!=null) {
parameterTypes=new Class[parameters.length];
for (int i = 0; i < parameters.length; i++) {
parameterTypes[i] = AppParameter.class;
}
}
Method m = c.getMethod(EXECUTION_METHOD_NAME,parameterTypes);
// invoke the method
// AppParameter[] aps=new AppParameter[parameters.length-1];
// System.arraycopy(parameters,1,aps,0,aps.length);
AppParameter[] aps = parameters;
//VK: Replace the first item in the tool parameters with the data collected in this method
//
//The most important values in this constructor are:
// - mode ("IN")
// - parameter value
// - parameter type (class)
//The actual name and formal name are insignificant.
aps[0] = new AppParameter("TAParams", "none", "IN", toolAgentParams, HashMap.class);
m.invoke(null,aps);
status=APP_STATUS_FINISHED;
} catch (ClassNotFoundException cnf) {
cus.error(LOG_CLASSNAME + " - application "+appName+" terminated incorrectly, can't find class: "+cnf);
throw new ApplicationNotDefined("Can't find class "+appName,cnf);
} catch (NoSuchMethodException nsm) {
cus.error(LOG_CLASSNAME + " - application "+appName+" terminated incorrectly, can't find method "+EXECUTION_METHOD_NAME+" : "+nsm);
throw new ApplicationNotDefined("Class "+appName+" doesn't have method "+EXECUTION_METHOD_NAME,nsm);
} catch (NoClassDefFoundError ncdfe) {
cus.error(LOG_CLASSNAME + " - application "+appName+" terminated incorrectly, can't find class definition: "+ncdfe);
throw new ApplicationNotDefined("Class "+appName+" can't be executed",ncdfe);
} catch (Throwable ex) {
cus.error(LOG_CLASSNAME + " - application "+appName+" terminated incorrectly: "+ex);
status=APP_STATUS_INVALID;
throw new ToolAgentGeneralException(ex);
} finally {
LOGGER.finest("Exiting " + THIS_METHOD_NAME);
}
}
public String getInfo (SharkTransaction t) throws ToolAgentGeneralException {
String i="This tool agent executes Java classes, by calling its static method called \"execute\"."+
"\nWhen calling this tool agent's invokeApplication() method, the application "+
"\nname parameter should be the full name of the class that should be executed "+
"\nby this tool agent (the classes had to be in the class path) "+
"\n"+
"\nThis tool agent is able to understand the extended attribute with the following name:"+
"\n * AppName - value of this attribute should represent the class name to be executed"+
"\n"+
"\n NOTE: Tool agent will read extended attributes only if they are called through"+
"\n Default tool agent (not by shark directly) and this is the case when information "+
"\n on which tool agent to start for XPDL application definition is not contained in mappings";
return i;
}
}
Note, that _all_ your tools now will need an extra (hidden) parameter to receive the data from the JavaClassToolAgent. This extra parameter need _not_ to be defined in the workflow application XPDL definition (it is hidden for the XPDL definition).
We are trying to use Shark in several threads inside an application server. So far we have some success. Unfortunately, Shark sets implicitly some restrictions to the number of threads it can simultaneously run in.
Best Regards,
Monique
He Wei wrote:
> Hello Monique,
>
> Yes, please share with me your modified JavaClassToolAgent.
> Thank you for your info, I will look through them.
> Did you ever test to let your application start a new Thread for each of you
> instances as just suggested by Vladimir Puskas? Sample code is as following:
> //final SharkConnection sc;
> //final Map workflowRelevantData;
> for (int i = 0; i < 5; i++) {
> new Thread() {
> public void run() {
> try {
> WfProcess theProcess = sc.createProcess("pkg","pdef");
> theProcess.set_process_context(workflowRelevantData);
> theProcess.start();
> } catch (RootException e) {
> e.printStackTrace();
> }
> }
> }.start();
> }
> These process instances should run in parallel. I am testing on it.
> Best Regards,
> He Wei
>
> -----Original Message-----
> From: Monique Maker [mailto:[email protected]]
> Sent: Wednesday, August 17, 2005 4:15 PM
> To: [email protected]
> Subject: Re: [shark] processes running not in parallel
>
> Hello He Wei,
>
> According the Shark documentation all workflow applications (respectively
> ToolAgents) in an activity are executed when the activity finishes. Probably
> the tool can execute activity.complete, but we are afraid that this could
> cause an infinite loop. Unfortunately we had no resources to check the
> behaviour of Shark in similar situation and asked a question to the Shark
> team on 18.07.2005 but we still have no answer. If you are interested, the
> mail-list thread should be "Shark transactions question".
>
> Even if Shark will not loop infinitely, there is another problem - the
> credentials of a user to complete the activity. This is one of the problems
> we rise in the mail-list thread "Logging Shark internal information in
> external application" as of 21.07.2005.
>
> We already modified the original JavaClassToolAgent to supply some of the
> ToolAget parameters (such as processID and activityID) to our tools and I
> can share it if you need it, though the change is easy to implement.
>
> Best Regards,
> Monique
>
>
> He Wei wrote:
>
>>Hello Monique,
>>
>>Thank you very much for your answer.
>>This behavior for a workflow engine should not be acceptable, and should
>
> be
>
>>considered as a bug.
>>Did you mean that without the solution of "how a TolAgent can finish an
>>activity", the problem cannot be solved, is it?
>>Best Regards,
>>He Wei
>>
>>-----Original Message-----
>>From: Monique Maker [mailto:[email protected]]
>>Sent: Tuesday, August 16, 2005 6:24 PM
>>To: [email protected]
>>Subject: Re: [shark] processes running not in parallel
>>
>>Hello He Wei,
>>
>>When we asked similar question to the Shark team they explained us that
>>Shark processes activities "greedy", i.e. it executes as many activities
>
> as
>
>>it can. In the case of all automatic activities the Shark engine runs all
>
> of
>
>>them before to proceed anything else. That is the reason you observe a
>>sequential processes execution.
>>
>>You cannot change this Shark behavior with some settings. Intead you will
>>need to change your process definitions. Shark team advised us to change
>
> the
>
>>activities to automatic start and manual end, but we still have no answer
>>how a TolAgent can finish an activity (if this is your case too).
>>
>>Regards,
>>Monique
>>
>>He Wei wrote:
>>
>>
>>>In my testing, I started several process instances for the same process
>>>definition by the following java codes. "allProcesses" is array, whose
>>>length determines how many process instance to initiate. The process
>>>contains only automatic activities, which means each activity
>>>automatically start and complete by the engine. It supposes that those
>>>initiated processes should run in parallel, is it? However the results
>>>show that these processes start running in sequence, in other words, the
>>>second process starts to run only after the first process instance
>>>completes, and the third one start running only after the second
>>>completes, then the 4^th , 5^th and so on. It is quite strange. Could
>>>you please advice why this happens? Any settings need to be considered
>>>in shark? Thank you very much.
>>>
>>>
>>>
>>> for(i=0;i<allProcesses.length;i++)
>>>
>>> {
>>>
>>>
>>>
>>> Map m1 = new HashMap();
>>>
>>> m1.put("TotalTimeTaken",TotalTimeTaken);
>>>
>>> m1.put("ProcessStartTime",ProcessStartTime);
>>>
>>> m1.put("MovingDecision",MovingDecision);
>>>
>>>
>>>
>>> WfProcess proc1 = sConn.createProcess(pkgId,pDefId);
>>>
>>> proc1.set_process_context(m1);
>>>
>>>
>>>
>>>
>>>
>>> proc1.start();
>>>
>>>
>>>
>>> }
>>>
>>> }
>>>
>>>
>>>
>>>Best Regards,
>>>
>>>He Wei
>>>
>>
>>
>>
>>
>>
>
>
>
>
message-footer.txt
(text/plain, 271 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws