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 2018/05/03 13:45:09 UTC
svn commit: r1830825 -
/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/http/HttpServiceTransport.java
Author: cwiklik
Date: Thu May 3 13:45:08 2018
New Revision: 1830825
URL: http://svn.apache.org/viewvc?rev=1830825&view=rev
Log:
UIMA-5756 modified recovery when client not available
Modified:
uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/http/HttpServiceTransport.java
Modified: uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/http/HttpServiceTransport.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/http/HttpServiceTransport.java?rev=1830825&r1=1830824&r2=1830825&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/http/HttpServiceTransport.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-pullservice/src/main/java/org/apache/uima/ducc/ps/service/transport/http/HttpServiceTransport.java Thu May 3 13:45:08 2018
@@ -27,6 +27,7 @@ import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.http.HttpEntity;
@@ -66,6 +67,7 @@ public class HttpServiceTransport implem
private int clientMaxConnectionsPerRoute = 60;
private int clientMaxConnectionsPerHostPort = 0;
private ReentrantLock lock = new ReentrantLock();
+// private CountDownLatch initLatch = new CountDownLatch(1);
private ReentrantLock registryLookupLock = new ReentrantLock();
private long threadSleepTime=10000; // millis
private final String nodeIP;
@@ -153,7 +155,7 @@ public class HttpServiceTransport implem
String newTarget = registryClient.lookUp(currentTargetUrl.asString());
// logger.log(Level.INFO, "Registry lookup succesfull - current target URL:"+newTarget);
currentTargetUrl = TargetURIFactory.newTarget(newTarget);
- return;
+ break;
} catch( Exception e) {
synchronized (httpClient) {
@@ -170,8 +172,9 @@ public class HttpServiceTransport implem
registryLookupLock.unlock();
}
}
- public void initialize() throws ServiceInitializationException {
+ public void initialize() throws ServiceInitializationException {
+
// use plugged in registry to lookup target to connect to.
// Sets global: currentTarget
lookupNewTarget();
@@ -208,6 +211,7 @@ public class HttpServiceTransport implem
logger.log(Level.INFO,"Cmgr SoTimeout="+cMgr.getDefaultSocketConfig().getSoTimeout());
}
running = true;
+
}
private void addCommonHeaders( HttpPost method ) {
synchronized( HttpServiceTransport.class ) {
@@ -265,9 +269,10 @@ public class HttpServiceTransport implem
return response;
}
- private String doPost(HttpPost postMethod) throws URISyntaxException, IOException, TransportException {
+ private String doPost(HttpPost postMethod) throws URISyntaxException, NoHttpResponseException, IOException, TransportException {
postMethod.setURI(new URI(currentTargetUrl.asString()));
HttpResponse response = httpClient.execute(postMethod);
+
if ( stopping ) {
throw new TransportException("Service stopping - rejecting request");
}
@@ -312,7 +317,7 @@ public class HttpServiceTransport implem
}
// timeout so try again
- ex.printStackTrace();
+ //ex.printStackTrace();
} catch (HttpHostConnectException | UnknownHostException ex ) {
if ( stopping ) {
System.out.println("Process Thread:"+Thread.currentThread().getId()+" HttpHostConnectException ");
@@ -321,17 +326,15 @@ public class HttpServiceTransport implem
}
stats.incrementErrorCount();
- //ex.printStackTrace();
Action action = handleConnectionError(ex);
if ( Action.CONTINUE.equals(action)) {
try {
- //postMethod.setURI(new URI(currentTargetUrl.asString()));
// Lost connection to the Task Allocation App
// Block until connection is restored
if ( log ) {
log = false;
- logger.log(Level.INFO, ">>>>>>>>>> Unable to connect to target:"+currentTargetUrl.asString()+" - retrying until successfull - with between retries "+threadSleepTime+" ms");
+ logger.log(Level.INFO, ">>>>>>>>>> Unable to connect to target:"+currentTargetUrl.asString()+" - retrying until successfull - with "+threadSleepTime/1000+" seconds wait between retries ");
}
serializedResponse = retryUntilSuccessfull(serializedRequest, postMethod);
log = true;
@@ -349,8 +352,7 @@ public class HttpServiceTransport implem
} catch (SocketException ex) {
if ( stopping ) {
- System.out.println("Process Thread:"+Thread.currentThread().getId()+" SocketException ");
- //ex.printStackTrace();
+ //System.out.println("Process Thread:"+Thread.currentThread().getId()+" SocketException ");
throw new TransportException(ex);
}
@@ -383,8 +385,10 @@ public class HttpServiceTransport implem
}
public void stop() {
+
stopping = true;
running = false;
+ //initLatch.countDown();
logger.log(Level.INFO,this.getClass().getName()+" stop() called");
if ( cMgr != null ) {
cMgr.shutdown();