private void finalStep(FinalStep aStep, String aCasReferenceId)// throws AsynchAEException
{
Endpoint endpoint=null;
boolean subordinateCasInPlayCountDecremented=false;
CacheEntry cacheEntry = null;
try
{
cacheEntry = getInProcessCache().getCacheEntryForCAS(aCasReferenceId);
if ( cacheEntry.getState() != CacheEntry.FINAL_STATE )
{
cacheEntry.setState(CacheEntry.FINAL_STATE);
}
}
catch(Exception e)
{
return;
}
try
{
CacheEntry parentCASCacheEntry = null;
boolean replyWithInputCAS = false;
// Check if the CAS has subordinates, meaning is this CAS an input CAS from which
// other CASes (subordinates) were produced. If so, make sure that all subordinate
// CASes have been fully processed. Only when all subordinates are accounted for
// return the input CAS back to the client. While subordinates are in-play keep
// the input CAS in the cache.
// Check if this CAS is an input CAS
if (!cacheEntry.isSubordinate() || cacheEntry.getSubordinateCasInPlayCount() > 0 )
{
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(),
"finalStep", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_final_step_parent_cas__FINEST", new Object[] { getComponentName(),aCasReferenceId});
synchronized( cacheEntry )
{
if ( cacheEntry.getSubordinateCasInPlayCount() > 0 )
{
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(),
"finalStep", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_final_step_parent_cas_child_count__FINEST", new Object[] { getComponentName(),aCasReferenceId,cacheEntry.getSubordinateCasInPlayCount()});
// Leave input CAS in pending state. It will be returned to the client
// *only* if the last subordinate CAS is fully processed.
cacheEntry.setPendingReply(true);
// Done here. There are subordinate CASes still being processed.
return;
}
else
{
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(),
"finalStep", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_final_step_parent_cas_no_children__FINEST", new Object[] { getComponentName(),aCasReferenceId});
// All subordinates have been fully processed. Set the flag so that
// the input is returned back to the client.
replyWithInputCAS = true;
}
}
}
else //if ( isTopLevelComponent())
{
// This is a subordinate CAS. First get cache entry for the input (parent) CAS
parentCASCacheEntry =
getInProcessCache().getCacheEntryForCAS(cacheEntry.getInputCasReferenceId());
if ( getMessageOrigin(aCasReferenceId) == null )
{
replyWithInputCAS = decrementCasSubordinateCount( parentCASCacheEntry);
if ( parentCASCacheEntry != null )
{
// Set the flag to indicate that the cache entry for the parent CAS has been updated
// In case an exception happens below, the error handler will be instructed to skip
// decrementing subordinate count (since it's been done already)
subordinateCasInPlayCountDecremented = true;
}
}
else
{
replyWithInputCAS = true;
}
}
// Cas Processing has been completed. Check if the CAS should be sent to
// the client.
// Any of the two following conditions will prevent this aggregate from
// sending the CAS to the client:
// 1) FinalStep is configured to drop the CAS
// 2) If the CAS has been produced by the Cas Multiplier and the
// aggregate is not configured to output new CASes
String casProducer = cacheEntry.getCasProducerAggregateName();
boolean isNewCas = (cacheEntry.isNewCas() && casProducer != null && getComponentName().equals(casProducer));
// If debug level=FINEST show the size of the cache
getInProcessCache().dumpContents();
// New CASes must be dropped if aggregate doesn't output them or if flow controller has ActionAfterCasMultiplier="drop"
if (isNewCas && (aStep.getForceCasToBeDropped() || !aggregateMetadata.getOperationalProperties().getOutputsNewCASes()))
{
endpoint = getInProcessCache().getEndpoint(null, aCasReferenceId);
if ( cacheEntry.isReplyReceived())
{
dropCAS(aCasReferenceId, true);
}
if ( parentCASCacheEntry != null //&& parentCASCacheEntry.isSubordinate()
&& parentCASCacheEntry.isReplyReceived()
&& parentCASCacheEntry.getState() == CacheEntry.FINAL_STATE
&& parentCASCacheEntry.getSubordinateCasInPlayCount() == 0)
{
// All subordinate CASes have been processed. Process the parent
// CAS recursively.
finalStep(aStep, parentCASCacheEntry.getCasReferenceId());
}
}
/*
if ( replyWithInputCAS && parentCASCacheEntry != null )
{