int howManyCASesPerRunningThread, int howManyRunningThreads, int timeout,
int aGetMetaTimeout, boolean failOnTimeout ) throws Exception {
// Instantiate Uima EE Client
isStopped = false;
isStopping = false;
final BaseUIMAAsynchronousEngine_impl eeUimaEngine = new BaseUIMAAsynchronousEngine_impl();
// Deploy Uima EE Primitive Service
final String containerId = deployService(eeUimaEngine, serviceDeplyDescriptor);
engine = eeUimaEngine;
Thread t1 = null;
Thread t2 = null;
Map appCtx = buildContext(String.valueOf(broker.getMasterConnectorURI()), queueName, timeout);
// Set an explicit getMeta (Ping)timeout
appCtx.put(UimaAsynchronousEngine.GetMetaTimeout, aGetMetaTimeout);
initialize(eeUimaEngine, appCtx);
// Wait until the top level service returns its metadata
waitUntilInitialized();
final Semaphore ctrlSemaphore = new Semaphore(1);
t2 = spinMonitorThread(ctrlSemaphore, howManyCASesPerRunningThread * howManyRunningThreads,
PROCESS_LATCH);
// Wait until the CPC Thread is ready.
waitOnMonitor(ctrlSemaphore);
if (failOnTimeout) {
// Spin a thread and wait for awhile before killing the remote service.
// This will cause the client to timeout waiting for a CAS reply and
// to send a Ping message to test service availability. The Ping times
// out and causes the client API to stop.
new Thread("WaitThenUndeploy") {
public void run() {
Object mux = new Object();
synchronized (mux) {
try {
mux.wait(5000);
// Undeploy service container
eeUimaEngine.undeploy(containerId);
} catch (Exception e) {
}
}
}
}.start();
}
// Spin runner threads and start sending CASes
for (int i = 0; i < howManyRunningThreads; i++) {
SynchRunner runner = new SynchRunner(eeUimaEngine, howManyCASesPerRunningThread, listener);
Thread runnerThread = new Thread(runner, "Runner" + i);
runnerThread.start();
System.out.println("runTest: Started Runner Thread::Id=" + runnerThread.getId());
}
// Wait until ALL CASes return from the service
t2.join();
t1 = spinMonitorThread(ctrlSemaphore, 1, CPC_LATCH);
if (!isStopped && !unexpectedException) {
System.out.println("runTest: Sending CPC");
// Send CPC
eeUimaEngine.collectionProcessingComplete();
}
// If have skipped CPC trip the latch
if (unexpectedException && cpcLatch != null) {
cpcLatch.countDown();
}
t1.join();
isStopping = true;
eeUimaEngine.stop();
}