try {
// Plugin custom timer for measuring performance of the CollectionReader
producer.setUimaTimer(getTimer());
} catch (Exception e) {
// Use default Timer. Ignore the exception
producer.setUimaTimer(new JavaTimer());
}
// indicate how many entities to process
producer.setNumEntitiesToProcess(numToProcess);
producer.setCollectionReader(collectionReader);
producer.setWorkQueue(workQueue);
// producer.setOutputQueue(outputQueue);
// collect stats in shared instance
producer.setCPMStatTable(stats);
//
for (int j = 0; j < statusCbL.size(); j++) {
BaseStatusCallbackListener statCL = (BaseStatusCallbackListener) statusCbL.get(j);
if (statCL != null)
statCL.initializationComplete();
}
// Just in case check if the CPM has the right state to start
if (isKilled()) {
return;
}
// Nov 2005, postpone starting the Producer Thread until all other threads are up.
// This prevents a problem when the Producer Thread starts, grabs all CASes, fills the
// input queue and there is an exception BEFORE Processing Units starts. This may lead
// to a hang, because the CR is waiting on the CAS Pool and no-one consumes the Input Queue.
// Name the thread
producer.setName("[CollectionReader Thread]::");
// Create Cas Consumer Thread
if (consumerList != null && consumerList.size() > 0) {
// Create a CasConsumer Processing Unit if there is at least one CasConsumer configured in a
// CPE descriptor
casConsumerPU = new ProcessingUnit(this, outputQueue, null);
casConsumerPU.setProcessingUnitProcessTrace(procTr);
casConsumerPU.setContainers(consumerList);
casConsumerPU.setCasPool(casPool);
casConsumerPU.setReleaseCASFlag(true);
casConsumerPU.setCasConsumerPipelineIdentity();
// Add Callback Listeners
for (int j = 0; j < statusCbL.size(); j++) {
BaseStatusCallbackListener statCL = (BaseStatusCallbackListener) statusCbL.get(j);
if (statCL != null) {
casConsumerPU.addStatusCallbackListener(statCL);
}
}
// Notify Callback Listeners when done processing entity
casConsumerPU.setNotifyListeners(true);
// Add custom timer
try {
casConsumerPU.setUimaTimer(getTimer());
} catch (Exception e) {
// Use default Timer
casConsumerPU.setUimaTimer(new JavaTimer());
}
// name the thread
casConsumerPU.setName("[CasConsumer Pipeline Thread]::");
// start the CasConsumer Thread
casConsumerPU.start();
consumerThreadStarted = true;
}
if (UIMAFramework.getLogger().isLoggable(Level.CONFIG)) {
UIMAFramework.getLogger(this.getClass()).logrb(
Level.CONFIG,
this.getClass().getName(),
"initialize",
CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_create_pus__CONFIG",
new Object[] { Thread.currentThread().getName(),
String.valueOf(workQueue.getCurrentSize()) });
}
// Adjust number of pipelines. Adjustment may be necessary in deployments using exclusive
// service access. The adjustment is
// based on number of available services that the CPM will connect to. If a static
// configuration calls for 5 processing
// pipelines but only three services are available (assuming exclusive access ), the CPM will
// reduce number of processing
// pipelines to 3.
for (int indx = 0; indx < annotatorList.size(); indx++) {
ProcessingContainer prContainer = (ProcessingContainer) annotatorList.get(indx);
CasProcessorConfiguration configuration = prContainer.getCasProcessorConfiguration();
if (configuration == null) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE, this.getClass().getName(),
"initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_cp_configuration_not_defined__SEVERE",
new Object[] { Thread.currentThread().getName(), prContainer.getName() });
return;
}
String serviceAccess = configuration.getDeploymentParameter("service-access");
if (serviceAccess != null && serviceAccess.equalsIgnoreCase("exclusive")) {
if (prContainer.getPool() != null) {
int totalInstanceCount = prContainer.getPool().getSize();
if (totalInstanceCount == 0) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.SEVERE,
this.getClass().getName(), "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_no_proxies__SEVERE",
new Object[] { Thread.currentThread().getName(), prContainer.getName() });
return;
}
if (totalInstanceCount < concurrentThreadCount) {
concurrentThreadCount = totalInstanceCount; // override
UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG,
this.getClass().getName(), "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_reduce_pipelines__CONFIG",
new Object[] { Thread.currentThread().getName(), prContainer.getName() });
}
}
}
}
// Setup Processing Pipelines
processingUnits = new ProcessingUnit[concurrentThreadCount];
synchronized (this) {
activeProcessingUnits = concurrentThreadCount; // keeps track of how many threads are still
// active. -Adam
}
// Capture the state of the pipelines. Initially the state is -1, meaning Not Started
processingThreadsState = new int[concurrentThreadCount];
for (int inx = 0; inx < concurrentThreadCount; inx++) {
processingThreadsState[inx] = -1; // Not Started
}
// Configure Processing Pipelines, and start each running in a seperate thread
for (int i = 0; i < concurrentThreadCount; i++) {
// casList = new CAS[readerFetchSize];
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
"initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_initialize_pipeline__FINEST",
new Object[] { Thread.currentThread().getName(), String.valueOf(i) });
}
// Plug in custom ProcessingUnit via -DPROCESSING_PIPELINE_IMPL=class
// Initialize Processing Pipeline with input and output queues
if (System.getProperty("PROCESSING_PIPELINE_IMPL") != null) {
String puClass = System.getProperty("PROCESSING_PIPELINE_IMPL");
try {
processingUnits[i] = producePU(puClass);
processingUnits[i].setInputQueue(workQueue);
processingUnits[i].setOutputQueue(outputQueue);
processingUnits[i].setCPMEngine(this);
} catch (Exception e) {
UIMAFramework.getLogger(this.getClass()).log(Level.SEVERE, e.getMessage(), e);
if (dbgCtrlThread != null) {
dbgCtrlThread.stop();
}
return; // / DONE HERE !!!
}
} else {
processingUnits[i] = new ProcessingUnit(this, workQueue, outputQueue);
}
// If there are no consumers in the pipeline, instruct the pipeline to release a CAS at the
// end of processing
if (consumerList == null || consumerList.size() == 0) {
processingUnits[i].setReleaseCASFlag(true);
}
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(
Level.FINEST,
this.getClass().getName(),
"initialize",
CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_pipeline_impl_class__FINEST",
new Object[] { Thread.currentThread().getName(),
processingUnits[i].getClass().getName() });
}
// Add tracing instance so that performance and stats are globally aggregated for all
// processing pipelines
processingUnits[i].setProcessingUnitProcessTrace(procTr);
// Add all annotators to the processing pipeline
processingUnits[i].setContainers(annotatorList);
// pass initialized list of cases to processing units in case cas conversion is required
// between
// CasData and CASObject based annotators.
processingUnits[i].setCasPool(casPool);
try {
processingUnits[i].setUimaTimer(getTimer());
} catch (Exception e) {
processingUnits[i].setUimaTimer(new JavaTimer());
}
// Add Callback Listeners
for (int j = 0; j < statusCbL.size(); j++) {
BaseStatusCallbackListener statCL = (BaseStatusCallbackListener) statusCbL.get(j);
if (statCL != null)