You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2009/01/26 22:15:35 UTC
svn commit: r737854 - in
/incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main:
java/org/apache/uima/adapter/jms/client/ resources/
Author: cwiklik
Date: Mon Jan 26 21:15:35 2009
New Revision: 737854
URL: http://svn.apache.org/viewvc?rev=737854&view=rev
Log:
UIMA-1127 Fixes Ping Logic in the Client API
Modified:
incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java
incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/ClientServiceDelegate.java
incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/resources/jms_adapter_messages.properties
Modified: incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java?rev=737854&r1=737853&r2=737854&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java (original)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngineCommon_impl.java Mon Jan 26 21:15:35 2009
@@ -174,6 +174,8 @@
private Object stopMux = new Object();
+ private Object sendMux = new Object();
+
protected List pendingMessageList = new ArrayList();
protected volatile boolean producerInitialized;
abstract public String getEndPointName() throws Exception;
@@ -539,86 +541,101 @@
* Sends a given CAS for analysis to the UIMA EE Service.
*
*/
- private synchronized String sendCAS(CAS aCAS, ClientRequest requestToCache) throws ResourceProcessException
+ private String sendCAS(CAS aCAS, ClientRequest requestToCache) throws ResourceProcessException
{
- String casReferenceId = requestToCache.getCasReferenceId();
- try
- {
- if (!running)
- {
- if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) {
- UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "sendCAS", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_not_sending_cas_INFO", new Object[] { "Asynchronous Client is Stopping" });
- }
- return null;
- }
- PendingMessage msg = new PendingMessage(AsynchAEMessage.Process);
- long t1 = System.nanoTime();
- if ( serializationStrategy.equals("xmi")) {
- XmiSerializationSharedData serSharedData = new XmiSerializationSharedData();
- String serializedCAS = serializeCAS(aCAS, serSharedData);
- msg.put( AsynchAEMessage.CAS, serializedCAS);
- if (remoteService)
+ synchronized( sendMux ) {
+ String casReferenceId = requestToCache.getCasReferenceId();
+ try
+ {
+ if (!running)
{
- requestToCache.setCAS(aCAS);
- // Store the serialized CAS in case the timeout occurs and need to send the
- // the offending CAS to listeners for reporting
- requestToCache.setCAS(serializedCAS);
- requestToCache.setXmiSerializationSharedData(serSharedData);
+ if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) {
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "sendCAS", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_not_sending_cas_INFO", new Object[] { "Asynchronous Client is Stopping" });
+ }
+ return null;
}
- } else {
- byte[] serializedCAS = uimaSerializer.serializeCasToBinary(aCAS);
- msg.put( AsynchAEMessage.CAS, serializedCAS);
- if (remoteService)
- {
- requestToCache.setCAS(aCAS);
- }
- }
-
- requestToCache.setSerializationTime(System.nanoTime()-t1);
- msg.put( AsynchAEMessage.CasReference, casReferenceId);
- requestToCache.setIsRemote(remoteService);
- requestToCache.setEndpoint(getEndPointName());
- requestToCache.setProcessTimeout(processTimeout);
- requestToCache.setThreadId(Thread.currentThread().getId());
- requestToCache.clearTimeoutException();
-
- clientCache.put(casReferenceId, requestToCache);
-
- // Check delegate's state before sending it a CAS. The delegate
- // may have previously timed out and the client is in a process of pinging
- // the delegate to check its availability. While the delegate
- // is in this state, delay CASes by placing them on a list of
- // CASes pending dispatch. Once the ping reply is received all
- // delayed CASes will be dispatched to the delegate.
- if ( !delayCasIfDelegateInTimedOutState( casReferenceId) ) {
- // The delegate state is normal, add the CAS Id to the list
- // of CASes sent to the delegate.
- serviceDelegate.addCasToOutstandingList(casReferenceId);
- } else {
- // CAS was added to the list of CASes pending dispatch. The service
- // has previously timed out. A Ping message was dispatched to test
- // service availability. When the Ping reply is received ALL CASes
- // from the list of CASes pending dispatch will be sent to the
- // delegate.
- return casReferenceId;
- }
- synchronized( pendingMessageList )
- {
- pendingMessageList.add(msg);
- pendingMessageList.notifyAll();
- }
-
- synchronized (cpcGate)
- {
- howManySent++;
- }
- }
- catch (Exception e)
- {
- throw new ResourceProcessException(e);
- }
- return casReferenceId;
+ PendingMessage msg = new PendingMessage(AsynchAEMessage.Process);
+ long t1 = System.nanoTime();
+ if ( serializationStrategy.equals("xmi")) {
+ XmiSerializationSharedData serSharedData = new XmiSerializationSharedData();
+ String serializedCAS = serializeCAS(aCAS, serSharedData);
+ msg.put( AsynchAEMessage.CAS, serializedCAS);
+ if (remoteService)
+ {
+ requestToCache.setCAS(aCAS);
+ // Store the serialized CAS in case the timeout occurs and need to send the
+ // the offending CAS to listeners for reporting
+ requestToCache.setCAS(serializedCAS);
+ requestToCache.setXmiSerializationSharedData(serSharedData);
+ }
+ } else {
+ byte[] serializedCAS = uimaSerializer.serializeCasToBinary(aCAS);
+ msg.put( AsynchAEMessage.CAS, serializedCAS);
+ if (remoteService)
+ {
+ requestToCache.setCAS(aCAS);
+ }
+ }
+
+ requestToCache.setSerializationTime(System.nanoTime()-t1);
+ msg.put( AsynchAEMessage.CasReference, casReferenceId);
+ requestToCache.setIsRemote(remoteService);
+ requestToCache.setEndpoint(getEndPointName());
+ requestToCache.setProcessTimeout(processTimeout);
+ requestToCache.setThreadId(Thread.currentThread().getId());
+ requestToCache.clearTimeoutException();
+
+ clientCache.put(casReferenceId, requestToCache);
+ // The sendCAS() method is synchronized no need to synchronize the code
+ // below
+ if ( serviceDelegate.getState() == Delegate.TIMEOUT_STATE &&
+ !serviceDelegate.isAwaitingPingReply()) {
+ serviceDelegate.setAwaitingPingReply();
+ System.out.println("--------------> Client Sending Ping Message");
+ // Send PING Request to check delegate's availability
+ sendMetaRequest();
+ if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "sendCAS", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_client_sending_ping__FINE",
+ new Object[] { serviceDelegate.getKey() });
+ }
+ }
+ // Check delegate's state before sending it a CAS. The delegate
+ // may have previously timed out and the client is in a process of pinging
+ // the delegate to check its availability. While the delegate
+ // is in this state, delay CASes by placing them on a list of
+ // CASes pending dispatch. Once the ping reply is received all
+ // delayed CASes will be dispatched to the delegate.
+ if ( !delayCasIfDelegateInTimedOutState( casReferenceId) ) {
+ // The delegate state is normal, add the CAS Id to the list
+ // of CASes sent to the delegate.
+ serviceDelegate.addCasToOutstandingList(casReferenceId);
+ } else {
+ System.out.println("..... Delaying CAS. Awaiting Ping Reply");
+ // CAS was added to the list of CASes pending dispatch. The service
+ // has previously timed out. A Ping message was dispatched to test
+ // service availability. When the Ping reply is received ALL CASes
+ // from the list of CASes pending dispatch will be sent to the
+ // delegate.
+ return casReferenceId;
+ }
+ synchronized( pendingMessageList )
+ {
+ pendingMessageList.add(msg);
+ pendingMessageList.notifyAll();
+ }
+
+ synchronized (cpcGate)
+ {
+ howManySent++;
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ResourceProcessException(e);
+ }
+ return casReferenceId;
+ }
}
/**
@@ -807,7 +824,6 @@
switch( aCommand )
{
case AsynchAEMessage.GetMeta:
- case AsynchAEMessage.Ping:
statCL.initializationComplete(aStatus);
break;
@@ -816,6 +832,7 @@
break;
case AsynchAEMessage.Process:
+ case AsynchAEMessage.Ping:
statCL.entityProcessComplete(aCAS, aStatus);
break;
}
@@ -1451,6 +1468,7 @@
ClientRequest cachedRequest = produceNewClientRequestObject();
cachedRequest.setSynchronousInvocation();
+
// send CAS. This call does not block. Instead we will block the sending thread below.
casReferenceId = sendCAS(aCAS, cachedRequest);
if (threadMonitor != null && threadMonitor.getMonitor() != null) {
@@ -1481,6 +1499,10 @@
// If there service is in the ok state and the CAS is in the
// list of CASes pending dispatch, remove the CAS from the list
// and send it to the service.
+ if (cachedRequest.isTimeoutException()) {
+ // Handled below
+ break;
+ }
if ( running && serviceDelegate.getState() == Delegate.OK_STATE &&
serviceDelegate.removeCasFromPendingDispatchList(casReferenceId)) {
sendCAS(aCAS, cachedRequest);
@@ -1602,7 +1624,6 @@
UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "notifyOnTimout", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_process_timeout_INFO", new Object[] { anEndpoint });
}
ClientRequest cachedRequest = (ClientRequest)clientCache.get(casReferenceId);
-
if ( cachedRequest == null )
{
if ( UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
Modified: incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/ClientServiceDelegate.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/ClientServiceDelegate.java?rev=737854&r1=737853&r2=737854&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/ClientServiceDelegate.java (original)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/java/org/apache/uima/adapter/jms/client/ClientServiceDelegate.java Mon Jan 26 21:15:35 2009
@@ -73,26 +73,28 @@
if (cachedRequest != null && cachedRequest.isRemote()) {
cas = cachedRequest.getCAS();
}
- if ( isAwaitingPingReply() ) {
+ boolean isPingTimeout = false;
+ if ( errorContext.containsKey(AsynchAEMessage.ErrorCause)) {
+ isPingTimeout =
+ AsynchAEMessage.PingTimeout ==
+ (Integer)errorContext.get(AsynchAEMessage.ErrorCause);
+ }
+ if ( isPingTimeout && isAwaitingPingReply() ) {
System.out.println(">>>>> Client Ping Timedout");
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "handleError", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_client_ping_timed_out__WARNING",
+ new Object[] { getKey() });
+
clientUimaAsEngine.notifyOnTimout(cas, clientUimaAsEngine.getEndPointName(), BaseUIMAAsynchronousEngineCommon_impl.PingTimeout, casReferenceId);
- System.out.println("Stopping Uima AS Client API. Service Not Responding To a Ping.");
- clientUimaAsEngine.stop();
- break;
- }
- }
- clientUimaAsEngine.clientSideJmxStats.incrementProcessTimeoutErrorCount();
- System.out.println(">>>>> Client Process Timed Out");
- if ( !isAwaitingPingReply()) {
- setAwaitingPingReply();
- System.out.println(">>>>> Client Sending Ping");
- // Send PING Request to check delegate's availability
- clientUimaAsEngine.sendMetaRequest();
- if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
- UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "handleError", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_client_sending_ping__FINE",
- new Object[] { getKey() });
+ } else {
+ if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
+ UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, CLASS_NAME.getName(), "handleError", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_client_process_timedout__INFO",
+ new Object[] { getGetMetaTimeout() });
+ }
+ System.out.println(">>>>> Client Process Timed out. Notifying Listeners");
+ clientUimaAsEngine.notifyOnTimout(cas, clientUimaAsEngine.getEndPointName(), BaseUIMAAsynchronousEngineCommon_impl.ProcessTimeout, casReferenceId);
}
}
+ clientUimaAsEngine.clientSideJmxStats.incrementProcessTimeoutErrorCount();
break;
case AsynchAEMessage.GetMeta:
Modified: incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/resources/jms_adapter_messages.properties
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/resources/jms_adapter_messages.properties?rev=737854&r1=737853&r2=737854&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/resources/jms_adapter_messages.properties (original)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-jms/src/main/resources/jms_adapter_messages.properties Mon Jan 26 21:15:35 2009
@@ -158,4 +158,7 @@
UIMAJMS_send_failed_deleted_queue_INFO = >>>> Controller: {0} - Failed to Send Message To Queue: {1}. The Queue Has Been Deleted.
UIMAJMS_msg_size__FINE = Controller: {0} Sending {1} Message of Type: {2} to Endpoint: {3} Message Size: {4}
UIMAJMS_client_sending_ping__FINE = Uima AS Client Sent PING Message To Service: {0}
-UIMAJMS_client_serialization_ovveride__WARNING = \n\t***** WARNING: Service Doesn't Support Binary Serialization. Uima AS Client Defaulting to XMI Serialization\n
\ No newline at end of file
+UIMAJMS_client_serialization_ovveride__WARNING = \n\t***** WARNING: Service Doesn't Support Binary Serialization. Uima AS Client Defaulting to XMI Serialization\n
+UIMAJMS_client_ping_timed_out__WARNING = \n\t***** WARNING: Service: {0} Didn't Respond To Ping.\n
+UIMAJMS_client_process_timedout__INFO = Process Timeout. Uima AS Client Didn't Receive Process Reply Within Configured Window Of: {0}
+
\ No newline at end of file