Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.pubnub.api;
  
  import java.util.Vector;
  import static com.pubnub.api.PubnubError.*;
  
  
     private Exception excp = null;
 
     SubscribeWorker(Vector _requestQueueint connectionTimeout,
                     int requestTimeoutint maxRetriesint retryIntervalHashtable headers) {
         super(_requestQueueconnectionTimeoutrequestTimeout,
               maxRetriesretryIntervalheaders);
     }
 
     void process(HttpRequest hreq) {
         HttpResponse hresp = null;
         int currentRetryAttempt = (hreq.isDar())?1:;
         .verbose("disconnectAndResubscribe is " + hreq.isDar());
         if (hreq.getWorker() != null) {
             .verbose("Request placed by worker " + hreq.getWorker().getThread().getName());
             if (hreq.getWorker().) {
                 .verbose("The thread which placed the request has died, so ignore the request : " + hreq.getWorker().getThread().getName());
                 return;
             }
         }
         hreq.setWorker(this);
         boolean sleep = false;
         while (! && currentRetryAttempt <= ) {
             if (sleep) {
                 try {
                     Thread.sleep();
                 } catch (InterruptedException e) {
                 }
                 sleep = true;
             }
             try {
                 .debug(hreq.getUrl());
                 hresp = .fetch(hreq.getUrl(), hreq.getHeaders());
                 if (hresp != null
                         && HttpUtil.checkResponseSuccess(hresp
                                                          .getStatusCode())) {
                     currentRetryAttempt = 1;
                     break;
                 }
             } catch (SocketTimeoutException e) {
                 .verbose("No Traffic , Read Timeout Exception in Fetch : " + e.toString());
                 if () {
                     .verbose("Asked to Die, Don't do back from DAR processing");
                     break;
                 }
                 if (hreq.isDar()) {
                     hreq.getResponseHandler().handleBackFromDar(hreq);
                     return;
                 }
                 break;
 
             } catch (PubnubException e) {
                  = e;
                 switch (e.getPubnubError().) {
                 case :
                 case :
                     .verbose("Authentication Failure : " + e.toString());
                     currentRetryAttempt =  + 1;
                     break;
                 default:
                     .verbose("Retry Attempt : " + ((currentRetryAttempt == )?"last":currentRetryAttempt)
                                 + " Exception in Fetch : " + e.toString());
                     currentRetryAttempt++;
                     break;
                 }
 
             } catch (Exception e) {
                  = e;
                 .verbose("Retry Attempt : " + ((currentRetryAttempt == )?"last":currentRetryAttempt)
                             + " Exception in Fetch : " + e.toString());
                 currentRetryAttempt++;
             }
 
         }
         if (!) {
             if (hresp == null) {
                 .debug("Error in fetching url : " + hreq.getUrl());
                 if (hreq.isDar()) {
                     .verbose("Exhausted number of retries");
                     hreq.getResponseHandler().handleTimeout(hreq);
                 } else {
                     if ( != null &&  instanceof PubnubException && ((PubnubException).getPubnubError() != null) {
                         hreq.getResponseHandler().handleError(hreq, ((PubnubException).getPubnubError());
                     } else {
                         hreq.getResponseHandler().handleError(hreqgetErrorObject(, 1));
                     }
                 }
                 return;
             }
             .debug(hresp.getResponse());
             hreq.getResponseHandler().handleResponse(hreqhresp.getResponse());
        }
    }
    public void shutdown() {
        if ( != null.shutdown();
    }
New to GrepCode? Check out our FAQ X