* - the destination where the delegate receives messages
*
* @throws AsynchAEException
*/
public void sendRequest(int aCommand, Endpoint anEndpoint) {
Delegate delegate = null;
try {
JmsEndpointConnection_impl endpointConnection = getEndpointConnection(anEndpoint);
TextMessage tm = endpointConnection.produceTextMessage("");
tm.setIntProperty(AsynchAEMessage.Payload, AsynchAEMessage.None);
tm.setText(""); // Need this to prevent the Broker from throwing an exception when sending a
// message to C++ service
populateHeaderWithRequestContext(tm, anEndpoint, aCommand);
// For remotes add a special property to the message. This property
// will be echoed back by the service. This property enables matching
// the reply with the right endpoint object managed by the aggregate.
if (anEndpoint.isRemote()) {
tm.setStringProperty(AsynchAEMessage.EndpointServer, anEndpoint.getServerURI());
}
boolean startTimer = false;
// Start timer for endpoints that are remote and are managed by a different broker
// than this service. If an endpoint contains a destination object, the outgoing
// request will contain a JMSReplyTo object which will point to a temp queue
if (anEndpoint.isRemote() && anEndpoint.getDestination() == null) {
startTimer = true;
}
if (aCommand == AsynchAEMessage.CollectionProcessComplete) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(),
"sendRequest", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_send_cpc_req__FINE", new Object[] { anEndpoint.getEndpoint() });
}
} else if (aCommand == AsynchAEMessage.ReleaseCAS) {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(
Level.FINEST,
CLASS_NAME.getName(),
"sendRequest",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAJMS_releasecas_request__endpoint__FINEST",
new Object[] { getAnalysisEngineController().getName(),
endpointConnection.getEndpoint() });
}
} else if (aCommand == AsynchAEMessage.GetMeta) {
if (anEndpoint.getDestination() != null) {
String replyQueueName = ((ActiveMQDestination) anEndpoint.getDestination())
.getPhysicalName().replaceAll(":", "_");
if (getAnalysisEngineController() instanceof AggregateAnalysisEngineController) {
String delegateKey = ((AggregateAnalysisEngineController) getAnalysisEngineController())
.lookUpDelegateKey(anEndpoint.getEndpoint());
ServiceInfo serviceInfo = ((AggregateAnalysisEngineController) getAnalysisEngineController())
.getDelegateServiceInfo(delegateKey);
if (serviceInfo != null) {
serviceInfo.setReplyQueueName(replyQueueName);
serviceInfo.setServiceKey(delegateKey);
}
delegate = lookupDelegate(delegateKey);
if (delegate.getGetMetaTimeout() > 0) {
delegate.startGetMetaRequestTimer();
}
}
} else if (!anEndpoint.isRemote()) {
ServiceInfo serviceInfo = ((AggregateAnalysisEngineController) getAnalysisEngineController())
.getServiceInfo();
if (serviceInfo != null) {
serviceInfo.setReplyQueueName(controllerInputEndpoint);
}
}
} else {
if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(CLASS_NAME).logrb(
Level.FINEST,
CLASS_NAME.getName(),
"sendRequest",
JmsConstants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAJMS_metadata_request__endpoint__FINEST",
new Object[] { endpointConnection.getEndpoint(),
endpointConnection.getServerUri() });
}
}
if (endpointConnection.send(tm, 0, startTimer) != true) {
throw new ServiceNotFoundException();
}
} catch (Exception e) {
if (delegate != null && aCommand == AsynchAEMessage.GetMeta) {
delegate.cancelDelegateTimer();
}
// Handle the error
ErrorContext errorContext = new ErrorContext();
errorContext.add(AsynchAEMessage.Command, aCommand);
errorContext.add(AsynchAEMessage.Endpoint, anEndpoint);