Examples of CNSThrottlePolicy


Examples of com.comcast.cns.model.CNSThrottlePolicy

      }
     
      defaultHealthyRetryPolicy.setBackOffFunction(CnsBackoffFunction.valueOf(backoffFunc));
      deliveryPolicy.setDefaultHealthyRetryPolicy(defaultHealthyRetryPolicy);
      deliveryPolicy.setDisableSubscriptionOverrides(ignoreOverride != null ? true: false);
      CNSThrottlePolicy defaultThrottle = new CNSThrottlePolicy();
     
      if (maxReceiveRate.trim().length() > 0) {
        defaultThrottle.setMaxReceivesPerSecond(Integer.parseInt(maxReceiveRate));
      }
     
      deliveryPolicy.setDefaultThrottlePolicy(defaultThrottle );
     
      try {

        SetTopicAttributesRequest setTopicAttributesRequest = new SetTopicAttributesRequest(topicArn, "DeliveryPolicy", deliveryPolicy.toString());
        sns.setTopicAttributes(setTopicAttributesRequest);
       
        logger.debug("event=set_delivery_policy topic_arn=" + topicArn + " userId= " + userId);

      } catch (Exception ex) {
        logger.error("event=set_delivery_policy user_id= " + userId, ex);
        throw new ServletException(ex);
      }
     
      out.println("<body onload='javascript:window.opener.location.reload();window.close();'>");
     
    } else {

      int numRetries=0, retriesNoDelay = 0, minDelay = 0, minDelayRetries = 0, maxDelay = 0, maxDelayRetries = 0, maxReceiveRate = 0;
      String retryBackoff = "linear";
      boolean ignoreOverride = false;
     
      if (topicArn != null) {
     
        Map<String, String> attributes = null;
        CNSTopicDeliveryPolicy deliveryPolicy = null;
       
        try {
          GetTopicAttributesRequest getTopicAttributesRequest = new GetTopicAttributesRequest(topicArn);
          GetTopicAttributesResult getTopicAttributesResult = sns.getTopicAttributes(getTopicAttributesRequest);
          attributes = getTopicAttributesResult.getAttributes();
          deliveryPolicy = new CNSTopicDeliveryPolicy(new JSONObject(attributes.get("DeliveryPolicy")));
        } catch (Exception ex) {
          logger.error("event=failed_to_get_attributes arn=" + topicArn, ex);
          throw new ServletException(ex);
        }

        if (deliveryPolicy != null) {
         
         
          CNSRetryPolicy healPol = deliveryPolicy.getDefaultHealthyRetryPolicy();
         
          if (healPol != null) {
            numRetries= healPol.getNumRetries();
            retriesNoDelay = healPol.getNumNoDelayRetries();
            minDelay = healPol.getMinDelayTarget();
            minDelayRetries = healPol.getNumMinDelayRetries();
            maxDelay = healPol.getMaxDelayTarget();
            maxDelayRetries = healPol.getNumMaxDelayRetries();
            retryBackoff = healPol.getBackOffFunction().toString();
          }
         
          CNSThrottlePolicy throttlePol = deliveryPolicy.getDefaultThrottlePolicy();
         
          if (throttlePol != null) {
         
            if (throttlePol.getMaxReceivesPerSecond() != null) {
              maxReceiveRate = throttlePol.getMaxReceivesPerSecond().intValue();
            }
          }
         
          ignoreOverride = deliveryPolicy.isDisableSubscriptionOverrides();
        }
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

       assertTrue(srp.getNumMaxDelayRetries() == 14);
       assertTrue(srp.getNumMinDelayRetries() == 13);
       assertTrue(srp.getNumNoDelayRetries() == 15);
       assertTrue(srp.getBackOffFunction() == CnsBackoffFunction.geometric);
      
       CNSThrottlePolicy dtp = subpolicy.getDefaultThrottlePolicy();
       assertTrue(dtp != null);
       assertTrue(dtp.getMaxReceivesPerSecond() == 5);
       assertTrue(subpolicy.isDisableSubscriptionOverrides() == false);

      
       JSONObject json2 = new JSONObject(jsonStr2);
       CNSTopicDeliveryPolicy subpolicy2 = new CNSTopicDeliveryPolicy(json2);
       CNSRetryPolicy hrp2 = subpolicy2.getDefaultHealthyRetryPolicy();
       logger.debug("hrp2: " + hrp2.toString());
       assertTrue("minDelayTarget != 1", hrp2.getMinDelayTarget() == 1);
       assertTrue(hrp2.getMaxDelayTarget() == 2);
       assertTrue(hrp2.getNumRetries() == 17);
       assertTrue(hrp2.getNumMaxDelayRetries() == 4);
       assertTrue(hrp2.getNumMinDelayRetries() == 6);
       assertTrue(hrp2.getNumNoDelayRetries() == 7);
       assertTrue(hrp2.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy2.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp2 = subpolicy2.getDefaultThrottlePolicy();
       assertTrue(dtp2 != null);
       assertTrue(dtp2.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy2.isDisableSubscriptionOverrides() == true);
      
       //Default constructor
       CNSTopicDeliveryPolicy subpolicy3 = new CNSTopicDeliveryPolicy();
       assertTrue(subpolicy3 != null);
       logger.debug("subpolicy3: " + subpolicy3.toString());
       CNSRetryPolicy hrp3 = subpolicy3.getDefaultHealthyRetryPolicy();
       assertTrue(hrp3.getMinDelayTarget() == 20);
       assertTrue(hrp3.getMaxDelayTarget() == 20);
       assertTrue(hrp3.getNumRetries() == 3);
       assertTrue(hrp3.getNumMaxDelayRetries() == 0);
       assertTrue(hrp3.getNumMinDelayRetries() == 0);
       assertTrue(hrp3.getNumNoDelayRetries() == 0);
       assertTrue(hrp3.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy3.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp3 = subpolicy3.getDefaultThrottlePolicy();
       assertTrue(dtp3 != null);
       assertTrue(dtp3.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy3.isDisableSubscriptionOverrides() == false);
      
       //Default constructor
       JSONObject json3 = new JSONObject(jsonStr3);
       CNSTopicDeliveryPolicy subpolicy4 = new CNSTopicDeliveryPolicy(json3);
       assertTrue(subpolicy4 != null);
       logger.debug("subpolicy4: " + subpolicy4.toString());
       CNSRetryPolicy hrp4 = subpolicy4.getDefaultHealthyRetryPolicy();
       assertTrue(hrp4.getMinDelayTarget() == 20);
       assertTrue(hrp4.getMaxDelayTarget() == 20);
       assertTrue(hrp4.getNumRetries() == 3);
       assertTrue(hrp4.getNumMaxDelayRetries() == 0);
       assertTrue(hrp4.getNumMinDelayRetries() == 0);
       assertTrue(hrp4.getNumNoDelayRetries() == 0);
       assertTrue(hrp4.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy4.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp4 = subpolicy4.getDefaultThrottlePolicy();
       assertTrue(dtp4 != null);
       assertTrue(dtp4.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy4.isDisableSubscriptionOverrides() == true);
      
       //Default constructor
       boolean exceptionOccured = false;
       try {
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

       assertTrue(srp.getNumRetries() == 42);
       assertTrue(srp.getNumMaxDelayRetries() == 14);
       assertTrue(srp.getNumMinDelayRetries() == 13);
       assertTrue(srp.getNumNoDelayRetries() == 15);
       assertTrue(srp.getBackOffFunction() == CnsBackoffFunction.geometric);
       CNSThrottlePolicy dtp3 = topicPolicy.getDefaultThrottlePolicy();
       assertTrue(dtp3 != null);
       assertTrue(dtp3.getMaxReceivesPerSecond() == 5);
       assertTrue(topicPolicy.isDisableSubscriptionOverrides() == false);
      
       try {
         JSONObject json2 = new JSONObject(fakejsonStr);
         new CNSTopicDeliveryPolicy(json2);
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

   public void testGetterSetter() {
     CNSTopicDeliveryPolicy topicPolicy = new CNSTopicDeliveryPolicy();
     CNSRetryPolicy hrp = new CNSRetryPolicy();
     hrp.setNumRetries(19);
     CNSRetryPolicy srp = new CNSRetryPolicy();
     CNSThrottlePolicy dtp = new CNSThrottlePolicy();
    
     dtp.setMaxReceivesPerSecond(19);
    
     srp.setBackOffFunction(CnsBackoffFunction.geometric);
     topicPolicy.setDefaultHealthyRetryPolicy(hrp);
     topicPolicy.setDefaultSicklyRetryPolicy(srp);
     topicPolicy.setDefaultThrottlePolicy(dtp);
     topicPolicy.setDisableSubscriptionOverrides(true);
    
     CNSRetryPolicy nhrp = topicPolicy.getDefaultHealthyRetryPolicy();
     CNSRetryPolicy nsrp = topicPolicy.getDefaultSicklyRetryPolicy();
     CNSThrottlePolicy ndtp = topicPolicy.getDefaultThrottlePolicy();
     assertTrue("subscription Overrides not set", topicPolicy.isDisableSubscriptionOverrides());
     assertTrue("default healthy retry policy not set correctly", nhrp.getMinDelayTarget() == 20);
     assertTrue("default healthy retry policy not set correctly",nhrp.getMaxDelayTarget() == 20);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumRetries() == 19);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumMaxDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumMinDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumNoDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getBackOffFunction() == CnsBackoffFunction.linear);
    
     assertTrue("default sickly retry policy not set correctly", nsrp.getMinDelayTarget() == 20);
     assertTrue("default sickly retry policy not set correctly",nsrp.getMaxDelayTarget() == 20);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumRetries() == 3);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumMaxDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumMinDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumNoDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getBackOffFunction() == CnsBackoffFunction.geometric);
    
     assertTrue("defaultThrottlePolicy not set correctly", ndtp.getMaxReceivesPerSecond() == 19);
     try {
       JSONObject json = topicPolicy.toJSON();
       logger.debug("Json is:" + json.toString());
       assertTrue("toJSON fails to return proper JSON", json.has("http"));
       JSONObject httpJson = json.getJSONObject("http");
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

        defaultHealthyRetryPolicy.setNumRetries(Integer.parseInt(numRetries));
      }
     
      defaultHealthyRetryPolicy.setBackOffFunction(CnsBackoffFunction.valueOf(backoffFunc));
      effectiveDeliveryPolicy.setHealthyRetryPolicy(defaultHealthyRetryPolicy);
      CNSThrottlePolicy defaultThrottlePolicy = new CNSThrottlePolicy();
     
      if (maxReceiveRate.trim().length() > 0) {
        defaultThrottlePolicy.setMaxReceivesPerSecond(Integer.parseInt(maxReceiveRate));
      }
     
      effectiveDeliveryPolicy.setThrottlePolicy(defaultThrottlePolicy);
     
      try {

        SetSubscriptionAttributesRequest setSubscriptionAttributesRequest = new SetSubscriptionAttributesRequest(subArn, "DeliveryPolicy", effectiveDeliveryPolicy.toString());
        sns.setSubscriptionAttributes(setSubscriptionAttributesRequest);
       
        logger.debug("event=set_delivery_policy sub_arn=" + subArn + " user_id= " + userId);

      } catch (Exception ex) {
        logger.error("event=set_subscription_attribute sub_arn=" + subArn + " user_id= " + userId, ex);
        throw new ServletException(ex);
      }
     
      out.println("<body onload='javascript:window.opener.location.reload();window.close();'>");
     
    } else {
     
      int numRetries=0, retriesNoDelay = 0, minDelay = 0, minDelayRetries = 0, maxDelay = 0, maxDelayRetries = 0, maxReceiveRate = 0;
      String retryBackoff = "linear";
     
      if (subArn != null) {
       
        Map<String, String> attributes = null;
        CNSSubscriptionDeliveryPolicy deliveryPolicy = null;
       
        try {
          GetSubscriptionAttributesRequest getSubscriptionAttributesRequest = new GetSubscriptionAttributesRequest(subArn);
          GetSubscriptionAttributesResult getSubscriptionAttributesResult = sns.getSubscriptionAttributes(getSubscriptionAttributesRequest);
          attributes = getSubscriptionAttributesResult.getAttributes();
          deliveryPolicy = new CNSSubscriptionDeliveryPolicy(new JSONObject(attributes.get("DeliveryPolicy")));
        } catch (Exception ex) {
          logger.error("event=get_subscription_attributes sub_arn=" + subArn + " user_id= " + userId, ex);
          throw new ServletException(ex);
        }

        if (deliveryPolicy != null) {
       
          CNSRetryPolicy healthyRetryPolicy = deliveryPolicy.getHealthyRetryPolicy();
         
          if (healthyRetryPolicy != null) {
            numRetries= healthyRetryPolicy.getNumRetries();
            retriesNoDelay = healthyRetryPolicy.getNumNoDelayRetries();
            minDelay = healthyRetryPolicy.getMinDelayTarget();
            minDelayRetries = healthyRetryPolicy.getNumMinDelayRetries();
            maxDelay = healthyRetryPolicy.getMaxDelayTarget();
            maxDelayRetries = healthyRetryPolicy.getNumMaxDelayRetries();
            retryBackoff = healthyRetryPolicy.getBackOffFunction().toString();
          }
         
          CNSThrottlePolicy throttlePolicy = deliveryPolicy.getThrottlePolicy();
         
          if (throttlePolicy != null) {
            if (throttlePolicy.getMaxReceivesPerSecond() != null) {
              maxReceiveRate = throttlePolicy.getMaxReceivesPerSecond().intValue();
            }
          }
        }
      }
     
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

    healthyRetryPolicy.setNumMaxDelayRetries(1);
    healthyRetryPolicy.setNumMinDelayRetries(0);
    healthyRetryPolicy.setNumNoDelayRetries(2);
    healthyRetryPolicy.setNumRetries(97);
    deliveryPolicy.setHealthyRetryPolicy(healthyRetryPolicy);       
    CNSThrottlePolicy throttlePolicy = new CNSThrottlePolicy();
    throttlePolicy.setMaxReceivesPerSecond(2);
    deliveryPolicy.setThrottlePolicy(throttlePolicy);
    subscriptionAttributes.setDeliveryPolicy(deliveryPolicy);       
   
    attributeHandler.setSubscriptionAttributes(subscriptionAttributes , subscription.getArn());
   
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

       assertTrue(hRetryPolicy.getMaxDelayTarget() == 2);
       assertTrue(hRetryPolicy.getNumRetries() == 10);
       assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 4);
       assertTrue(hRetryPolicy.getNumMinDelayRetries() == 6);
       assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.linear);
       CNSThrottlePolicy tPolicy = subpolicy.getThrottlePolicy();
       assertTrue(tPolicy.getMaxReceivesPerSecond() == 5);
       assertTrue(subpolicy.getSicklyRetryPolicy() == null);
      
       //Test 2nd Json constructor
       JSONObject json2 = new JSONObject(jsonStr2);
       CNSSubscriptionDeliveryPolicy subpolicy3 = new CNSSubscriptionDeliveryPolicy(json2);
       hRetryPolicy = subpolicy3.getHealthyRetryPolicy();
       assertTrue(hRetryPolicy.getMinDelayTarget() == 20);
       assertTrue(hRetryPolicy.getMaxDelayTarget() == 20);
       assertTrue(hRetryPolicy.getNumRetries() == 3);
       assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 0);
       assertTrue(hRetryPolicy.getNumMinDelayRetries() == 0);
       assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.linear);
       CNSThrottlePolicy tPolicy2 = subpolicy3.getThrottlePolicy();
       assertTrue(tPolicy2.getMaxReceivesPerSecond() == null);
       CNSRetryPolicy sRetryPolicy = subpolicy3.getSicklyRetryPolicy();
       assertTrue(sRetryPolicy.getMinDelayTarget() == 1);
       assertTrue(sRetryPolicy.getMaxDelayTarget() == 2);
       assertTrue(sRetryPolicy.getNumRetries() == 10);
       assertTrue(sRetryPolicy.getNumMaxDelayRetries() == 4);
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

       assertTrue(hRetryPolicy.getMaxDelayTarget() == 13);
       assertTrue(hRetryPolicy.getNumRetries() == 43);
       assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 23);
       assertTrue(hRetryPolicy.getNumMinDelayRetries() == 20);
       assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.arithmetic);
       CNSThrottlePolicy tPolicy = subpolicy.getThrottlePolicy();
       assertTrue(tPolicy.getMaxReceivesPerSecond() == 7);
      
       CNSRetryPolicy sRetryPolicy = subpolicy.getSicklyRetryPolicy();
       assertTrue(sRetryPolicy == null);
      
       json = new JSONObject(jsonStr2);
       subpolicy.update(json);
       hRetryPolicy = subpolicy.getHealthyRetryPolicy();
       assertTrue(hRetryPolicy != null);
       logger.debug("hRetryPolicy is: " + hRetryPolicy.toString());
       assertTrue(hRetryPolicy.getMinDelayTarget() == 20);
       assertTrue(hRetryPolicy.getMaxDelayTarget() == 20);
       assertTrue(hRetryPolicy.getNumRetries() == 3);
       assertTrue(hRetryPolicy.getNumMaxDelayRetries() == 0);
       assertTrue(hRetryPolicy.getNumMinDelayRetries() == 0);
       assertTrue(hRetryPolicy.getBackOffFunction() == CnsBackoffFunction.linear);
       tPolicy = subpolicy.getThrottlePolicy();
       assertTrue(tPolicy.getMaxReceivesPerSecond() == null);
       sRetryPolicy = subpolicy.getSicklyRetryPolicy();
       logger.debug("sRetryPolicy is: " + sRetryPolicy.toString());
       assertTrue(sRetryPolicy.getMinDelayTarget() == 32);
       assertTrue(sRetryPolicy.getMaxDelayTarget() == 33);
       assertTrue(sRetryPolicy.getNumRetries() == 99);
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

       hrp.setBackOffFunction(CnsBackoffFunction.geometric);
      
       CNSRetryPolicy srp = new CNSRetryPolicy();
       srp.setBackOffFunction(CnsBackoffFunction.exponential);
      
       CNSThrottlePolicy tp = new CNSThrottlePolicy();
       tp.setMaxReceivesPerSecond(78);
      
       subpolicy.setHealthyRetryPolicy(hrp);
       subpolicy.setSicklyRetryPolicy(srp);
       subpolicy.setThrottlePolicy(tp);
      
       CNSRetryPolicy hrp2 = subpolicy.getHealthyRetryPolicy();
       CNSRetryPolicy srp2 = subpolicy.getSicklyRetryPolicy();
       CNSThrottlePolicy tp2 = subpolicy.getThrottlePolicy();
      
       assertTrue(hrp2 != null);
       assertTrue(srp2 != null);
       assertTrue(tp2 != null);
      
       assertTrue(hrp2.getBackOffFunction() == CnsBackoffFunction.geometric);
       assertTrue(srp2.getBackOffFunction() == CnsBackoffFunction.exponential);
       assertTrue(tp2.getMaxReceivesPerSecond() == 78);
      
     } catch (Exception e) {
             logger.error("Exception occured", e);
             fail("exception: "+e);
     }
View Full Code Here

Examples of com.comcast.cns.model.CNSThrottlePolicy

              "\"cookie\":\"cookie\"" +
           "}";
    
     try {
       JSONObject json = new JSONObject(jsonStr);
       CNSThrottlePolicy tp = new CNSThrottlePolicy();
       assertTrue(tp.getMaxReceivesPerSecond() == null);
       //TODO test;
       tp = new CNSThrottlePolicy(json);
       assertTrue(tp.getMaxReceivesPerSecond() == 5);
      
       json = new JSONObject(jsonStr2);
       tp = new CNSThrottlePolicy(json);
       assertTrue(tp.getMaxReceivesPerSecond() == null);
      
       json = new JSONObject(jsonStr3);
       tp = new CNSThrottlePolicy(json);
       assertTrue(tp.getMaxReceivesPerSecond() == null);
      
       json = new JSONObject(jsonStr4);
        boolean exceptionOccured = false;
        try {
           tp = new CNSThrottlePolicy(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(jsonStr5);
        try {
           tp = new CNSThrottlePolicy(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.