This program can create several work items for a logged-in user. In order to use this example program, you will have to create a valid process flow in EPX’s Design Console that the logged-in user can create work items for. You should set the work item name to editable on the Details tab of the starting point activity. This example program is actually quite useful to stress test your process flows for tuning. In addition to the default program parameters specified in the LoginExample program, the WorkItemExample program has the following arguments:
-activityName — the name of the starting point activity to create work items for. If not supplied, the program will create work items for all starting points defined for the user.
-workItemName — the name to give for each work item created by the program. If not provided, the work item name will default to the activity name and the date and time when the work item is created.
-propertyFile — the name of a Java .properties file to populate each work item’s work item properties with. This parameter defaults to the file workitem.properties that is installed with the examples.
-threads — the number of threads that should concurrently create work items. This parameter can be used to simulate concurrent users in an automated fashion. It defaults to one (1).
-repeat — the number of work items to create for each thread, which defaults to one (1).
-delay — the number of seconds to wait in between each thread before creating and sending the work item
For example:
C:\Enterworks\EPX\examples\api\run.bat WorkItemExample
-server EPX_somehost -user system -password system
-activityName Order -workItemName PurchaseOrder
public static void main(String args[]) throws Exception
{
try
{
String serverUID = null;
String user = "system";
String password = "system";
String propertyFile = "workitem";
String activityName = null ;
String workItemName = null;
String threadCountParam = null;
String repeatCountParam = null;
String delayParam = null;
for ( int i=0 ; i < args.length; i++)
{
String arg = args[i];
if (arg.startsWith("-"))
{
if (arg.substring(1).equals("server"))
serverUID = args[++i];
else if (arg.substring(1).equals("user"))
user = args[++i];
else if (arg.substring(1).equals("password"))
password = args[++i];
else if (arg.substring(1).equals("activityName"))
activityName = args[++i];
else if (arg.substring(1).equals("workItemName"))
workItemName = args[++i];
else if (arg.substring(1).equals("propertyFile"))
propertyFile = args[++i];
else if (arg.substring(1).equals("threads"))
threadCountParam = args[++i];
else if (arg.substring(1).equals("repeat"))
repeatCountParam = args[++i];
else if (arg.substring(1).equals("delay"))
delayParam = args[++i];
}
}
HashMap propertyMap = null;
if ( propertyFile != null )
{
propertyMap = new HashMap();
ResourceBundle propertyBundle =
ResourceBundle.getBundle(
propertyFile,Locale.getDefault());
Enumeration propertyEnum = propertyBundle.getKeys();
while ( propertyEnum.hasMoreElements() )
{
String key = (String) propertyEnum.nextElement();
String value = propertyBundle.getString(key);
propertyMap.put(key,value);
}
}
int threadCount = 1;
if (threadCountParam != null )
threadCount = Integer.parseInt(threadCountParam);
int repeatCount = 1;
if (repeatCountParam != null )
repeatCount = Integer.parseInt(repeatCountParam);
int delay = 5000;
if (delayParam != null )
delay = Integer.parseInt(delayParam);
Thread[] workThreads;
workThreads = new Thread[threadCount];
WorkItemExample[] workExamples;
workExamples = new WorkItemExample[threadCount];
boolean initializeOkay = true;
for ( int i = 0; i < threadCount; i++ )
{
workExamples[i] = new WorkItemExample
(serverUID,user,password);
String vargs[] = { String.valueOf(i)};
System.out.println (
workExamples[i].getMessage(
"workitem.thread.init", vargs) );
if ( activityName != null )
workExamples[i].setStartingPointActivityName(
activityName);
if ( workItemName != null )
workExamples[i].setWorkItemName(workItemName);
if ( propertyMap != null )
workExamples[i].setWorkItemProperties(
propertyMap);
workExamples[i].login();
if ( !workExamples[i].initializeExample() )
{
initializeOkay = false;
break;
}
}
if ( initializeOkay )
{
ThreadGroup threadGroup = new ThreadGroup("WorkItemExample");
for ( int j = 0; j < repeatCount; j++ )
{
String vargsLoop[] = { String.valueOf(j) };
System.out.println (
workExamples[0].getMessage(
"workitem.thread.loop", vargsLoop) );
for ( int i = 0; i < threadCount; i++ )
{
String vargsThread[] = {
String.valueOf(i), String.valueOf(j) };
System.out.println (
workExamples[i].getMessage(
"workitem.thread.start",
vargsThread) );
workThreads[i] = new Thread(
threadGroup,
workExamples[i], "WorkItemExample:Thread:"+i);
workThreads[i].setDaemon(true);
workThreads[i].start();
Thread.sleep(delay);
Thread.yield();
}
while ( true )
{
int active = threadGroup.activeCount();
String vargsActive[] = {
String.valueOf(active),
String.valueOf(j) };
System.out.println (
workExamples[0].getMessage(
"workitem.thread.active",
vargsActive) );
if ( active == 0 )
break;
Thread.sleep(3000);
Thread.yield();
}
}
}
else
{
String vargsFail[] = {};
System.err.println (
workExamples[0].getMessage(
"workitem.init.failed", vargsFail));
}
for ( int i = 0; i < threadCount; i++ )
workExamples[i].logout();
}
catch( Exception e )
{
System.err.println (
"WorkItemExample.main(exception):" + e );
e.printStackTrace();
}
}
}