Package com.comcast.cqs.model

Examples of com.comcast.cqs.model.CQSQueue


     
        String queueUrl = null;

        long ts1 = System.currentTimeMillis();
     
        CQSQueue queue = CQSCache.getCachedQueue(Util.getRelativeQueueUrlForName(queueName, cnsInternal.getUserId()));
       
        if (queue != null) {
          queueUrl = queue.getAbsoluteUrl();
        }

        long ts2 = System.currentTimeMillis();
       
        CMBControllerServlet.valueAccumulator.addToCounter(AccumulatorName.CNSCQSTime, ts2 - ts1);
View Full Code Here


   
    // check if queue exists for cqs endpoints

    if (protocol.equals(CnsSubscriptionProtocol.cqs)) {
     
      CQSQueue queue = PersistenceFactory.getQueuePersistence().getQueue(com.comcast.cqs.util.Util.getRelativeQueueUrlForArn(endpoint));
     
      if (queue == null) {
        throw new CMBException(CMBErrorCodes.NotFound, "Queue with arn " + endpoint + " does not exist.");
      }
    }
View Full Code Here

      List<CQSQueue> queueList = persistence.listQueues(user.getUserId(), null, false);
      assertEquals(queueList.size(), 0);

        String queueName = QUEUE_PREFIX + randomGenerator.nextLong();
     
      CQSQueue queue = new CQSQueue(queueName, user.getUserId());
      persistence.createQueue(queue);
     
      queueName = QUEUE_PREFIX + randomGenerator.nextLong();
      queue = new CQSQueue(queueName, user.getUserId());
      persistence.createQueue(queue);

      queueName = QUEUE_PREFIX + randomGenerator.nextLong();
      queue = new CQSQueue(queueName, user.getUserId());

      persistence.createQueue(queue);
     
      queue = persistence.getQueue(user.getUserId(), queueName);
      assertQueue(region, queue);

      assertTrue(queue.getName().equals(queueName));
     
      queueList = persistence.listQueues(user.getUserId(), QUEUE_PREFIX, false);
      assertEquals(queueList.size(), 3);

      for (CQSQueue queue1 : queueList) {
View Full Code Here

        "}";
   
    try {
     
        String queueName1 = QUEUE_PREFIX + randomGenerator.nextLong();
      CQSQueue queue1 = new CQSQueue(queueName1, user.getUserId());
      queue1.setPolicy(policy);
      persistence.createQueue(queue1);
     
        String queueName2 = QUEUE_PREFIX + randomGenerator.nextLong();
      CQSQueue queue2 = new CQSQueue(queueName2, user.getUserId());
      persistence.createQueue(queue2);
      persistence.updatePolicy(queue2.getRelativeUrl(), policy);
     
      for (CQSQueue e: persistence.listQueues(user.getUserId(), QUEUE_PREFIX, false)) {
        CQSQueue q = persistence.getQueue(e.getRelativeUrl());
        assertTrue(policy.equals(q.getPolicy()));
        persistence.deleteQueue(e.getRelativeUrl());
      }
     
    } catch (PersistenceException e) {
      fail("Test failed:" +  e.toString());
View Full Code Here

     
      List<CQSQueue> queueList = persistence.listQueues(userId, null, false);
      assertEquals(queueList.size(), 0);

        String queueName = QUEUE_PREFIX + randomGenerator.nextLong();
      CQSQueue queue = new CQSQueue(queueName, userId);
      persistence.createQueue(queue);
     
      queueList = persistence.listQueues(userId, null, false);
      assertEquals(queueList.size(), 1);
     
      String queueURL = queue.getRelativeUrl();
      String key = CQSConstants.COL_VISIBILITY_TO;
      String value = "5";
      String key2 = CQSConstants.COL_MSG_RETENTION_PERIOD;
      String value2 = "30";
      String key3 = CQSConstants.COL_MAX_MSG_SIZE;
      String value3 = "4002";
      String key4 = CQSConstants.COL_DELAY_SECONDS;
      String value4 = "26";
      String key5 = CQSConstants.COL_POLICY;
      String value5 = "no";

      HashMap<String, String> values = new HashMap<String, String>();
      values.put(key, value);
      values.put(key2, value2);
      values.put(key3, value3);
      values.put(key4, value4);
      values.put(key5, value5);
      persistence.updateQueueAttribute(queueURL, values);
      queueName = queue.getName();
      CQSQueue queue2 = persistence.getQueue(userId, queueName);
      assertTrue(queue2.getVisibilityTO() == 5);
      assertTrue(queue2.getMsgRetentionPeriod() == 30);
      assertTrue(queue2.getMaxMsgSize() == 4002);
      assertTrue(queue2.getDelaySeconds() == 26);
      assertTrue(queue2.getPolicy().equals("no"));
     
      key3 = CQSConstants.COL_MAX_MSG_SIZE;
      value3 = "4150";
      key4 = CQSConstants.COL_DELAY_SECONDS;
      value4 = "20";
     
      HashMap<String, String> values2 = new HashMap<String, String>();
      values2.put(key3, value3);
      values2.put(key4, value4);
      persistence.updateQueueAttribute(queueURL, values2);
     
      CQSQueue queue3 = persistence.getQueue(userId, queueName);
      assertTrue(queue3.getVisibilityTO() == 5);
      assertTrue(queue3.getMsgRetentionPeriod() == 30);
      assertTrue(queue3.getMaxMsgSize() == 4150);
      assertTrue(queue3.getDelaySeconds() == 20);
      assertTrue(queue3.getPolicy().equals("no"));
     
      key = CQSConstants.COL_VISIBILITY_TO;
      value = "8";
      key2 = CQSConstants.COL_MSG_RETENTION_PERIOD;
      value2 = "32";

      HashMap<String, String> values3 = new HashMap<String, String>();
      values3.put(key, value);
      values3.put(key2, value2);
      persistence.updateQueueAttribute(queueURL, values3);
     
      CQSQueue queue4 = persistence.getQueue(userId, queueName);
      assertTrue(queue4.getVisibilityTO() == 8);
      assertTrue(queue4.getMsgRetentionPeriod() == 32);
      assertTrue(queue4.getMaxMsgSize() == 4150);
      assertTrue(queue4.getDelaySeconds() == 20);
      assertTrue(queue4.getPolicy().equals("no"));
     
      queueList = persistence.listQueues(user.getUserId(), null, false);
     
      for(CQSQueue queue_: queueList) {
        persistence.deleteQueue(queue_.getRelativeUrl());
View Full Code Here

     if (!cacheAvailable) {
       return Collections.emptyList();
     }

     CQSQueue queue = null;
     int retention;
     try {
       queue = CQSCache.getCachedQueue(queueUrl);
       if (queue != null) {
         retention = queue.getMsgRetentionPeriod();
       } else {
         retention = CMBProperties.getInstance().getCQSMessageRetentionPeriod();
       }
     } catch (Exception e) {
       throw new PersistenceException (e);
View Full Code Here

    * @throws Exception
    */
   private long getQueueMessageCount(String queueUrl, MessageCountType type) throws Exception  {

     long messageCount = 0;
     CQSQueue queue = CQSCache.getCachedQueue(queueUrl);
     int numberOfShards = 1;

     int retention;
     if (queue != null) {
       numberOfShards = queue.getNumberOfShards();
       retention = queue.getMsgRetentionPeriod();
     } else {
       retention = CMBProperties.getInstance().getCQSMessageRetentionPeriod();
     }

     ShardedJedis jedis = null;
View Full Code Here

    * @throws Exception
    */
   public long getCacheQueueMessageCount(String queueUrl) throws Exception  {

     long messageCount = 0;
     CQSQueue queue = CQSCache.getCachedQueue(queueUrl);
     int numberOfShards = 1;

     int retention;
     if (queue != null) {
       numberOfShards = queue.getNumberOfShards();
       retention = queue.getMsgRetentionPeriod();
     } else {
       retention = CMBProperties.getInstance().getCQSMessageRetentionPeriod();
     }

     ShardedJedis jedis = null;
View Full Code Here

  public boolean doAction(User user, AsyncContext asyncContext) throws Exception {
     
        HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest();
        HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse();

    CQSQueue queue = CQSCache.getCachedQueue(user, request);
       
        List<String> attributesList = Util.fillGetAttributesRequests(request);
       
        for (String attribute : attributesList) {
       
View Full Code Here

      }

    } else if (actionParam != null && actionParam.equals("ReceiveMessage")) {

      String queueUrl = com.comcast.cqs.util.Util.getRelativeForAbsoluteQueueUrl(request.getRequestURL().toString());
      CQSQueue queue;
      int waitTimeSeconds = 0;

      try {

        queue = CQSCache.getCachedQueue(queueUrl);

        if (queue != null && queue.getReceiveMessageWaitTimeSeconds() > 0) {
          waitTimeSeconds = queue.getReceiveMessageWaitTimeSeconds();
        }

      } catch (Exception ex) {
        logger.warn("event=lookup_queue queue_url=" + queueUrl, ex);
      }

      if (waitTimeSeconds > 0) {
        asyncContext.setTimeout(waitTimeSeconds*1000);
        ((CQSHttpServletRequest)asyncContext.getRequest()).setWaitTime(waitTimeSeconds*1000);
        logger.debug("event=set_queue_timeout secs=" + waitTimeSeconds + " queue_url=" + queueUrl);
      } else {
        asyncContext.setTimeout(HARD_TIMEOUT_SEC*1000);
        logger.debug("event=set_default_timeout secs="+CMBProperties.getInstance().getCMBRequestTimeoutSec());
      }

    } else {
      asyncContext.setTimeout(HARD_TIMEOUT_SEC*1000);
      logger.debug("event=set_default_timeout secs=" + CMBProperties.getInstance().getCMBRequestTimeoutSec());
    }

    asyncContext.addListener(new AsyncListener() {

      @Override
      public void onComplete(AsyncEvent asyncEvent) throws IOException {

        AsyncContext asyncContext = asyncEvent.getAsyncContext();
        CQSHttpServletRequest request = (CQSHttpServletRequest)asyncContext.getRequest();
        String action = request.getParameter("Action");
        if(action.equals("ReceiveMessage")){
          String lpValue = (String)request.getAttribute("lp");

          if(lpValue!=null){

            User user = authModule.getUserByRequest(request);

            Object lp_ms = request.getAttribute("lp_ms");
            String logLine = null;
            if(lp_ms!=null){
              logLine = getLogLine(asyncContext, request, user, (Long)request.getAttribute("lp_ms"), "ok");
            }else{
              logLine = getLogLine(asyncContext, request, user, 0, "ok");
            }
            logger.info(logLine);
          }
        }
       
      }

      @Override
      public void onError(AsyncEvent asyncEvent) throws IOException {

        int httpCode = CMBErrorCodes.InternalError.getHttpCode();
        String code = CMBErrorCodes.InternalError.getCMBCode();
        String message = "There is an internal problem with CMB";

        if (asyncEvent.getThrowable() instanceof CMBException) {
          httpCode = ((CMBException)asyncEvent.getThrowable()).getHttpCode();
          code = ((CMBException)asyncEvent.getThrowable()).getCMBCode();
          message = asyncEvent.getThrowable().getMessage();
        }

        String errXml = CMBControllerServlet.createErrorResponse(code, message);
        HttpServletResponse response = ((HttpServletResponse)asyncEvent.getSuppliedResponse());
        response.setStatus(httpCode);
        Action.writeResponse(errXml, response);

        if (!(asyncEvent.getSuppliedRequest() instanceof CQSHttpServletRequest)) {
          logger.error("event=invalid_request stage=on_error");
          return;
        }         

        CQSQueue queue = ((CQSHttpServletRequest)asyncEvent.getSuppliedRequest()).getQueue();
        AsyncContext asyncContext = asyncEvent.getAsyncContext();

        if (queue != null) {

          logger.info("event=on_error queue_url=" + queue.getAbsoluteUrl());

          ConcurrentLinkedQueue<AsyncContext> queueContextsList = CQSLongPollReceiver.contextQueues.get(queue.getArn());

          if (queueContextsList != null && asyncContext != null) {
            queueContextsList.remove(asyncContext);
          }

        } else {
          logger.info("event=on_error");
        }

        asyncContext.complete();
      }

      @Override
      public void onTimeout(AsyncEvent asyncEvent) throws IOException {
       
        if (!(asyncEvent.getSuppliedRequest() instanceof CQSHttpServletRequest)) {
          logger.error("event=invalid_request stage=on_timeout");
          return;
        }
       
        //first check if it is long poll receive, if so, complete and return.
        AsyncContext asyncContext = asyncEvent.getAsyncContext();
        CQSHttpServletRequest request = (CQSHttpServletRequest)asyncContext.getRequest();
        String action = request.getParameter("Action");
        if(action.equals("ReceiveMessage")){
          String lpValue = (String)request.getAttribute("lp");
          if(lpValue!=null){
            String out = CQSMessagePopulator.getReceiveMessageResponseAfterSerializing(new ArrayList<CQSMessage>(), new ArrayList<String>());
            asyncEvent.getSuppliedResponse().getWriter().println(out);
           
            CQSQueue queue = ((CQSHttpServletRequest)asyncEvent.getSuppliedRequest()).getQueue();

            asyncContext = asyncEvent.getAsyncContext();

            if (queue != null) {

              logger.debug("event=on_timeout queue_url=" + queue.getAbsoluteUrl());

              ConcurrentLinkedQueue<AsyncContext> queueContextsList = CQSLongPollReceiver.contextQueues.get(queue.getArn());

              if (queueContextsList != null && asyncContext != null) {
                queueContextsList.remove(asyncContext);
              }

            } else {
              logger.debug("event=on_timeout");
            }
            asyncContext.complete();
            return;           
          }
        }       
        //for other Time out show log error and return error response.
        int httpCode = CMBErrorCodes.InternalError.getHttpCode();
        String code = CMBErrorCodes.InternalError.getCMBCode();
        String message = "CMB timeout after "+CMBProperties.getInstance().getCMBRequestTimeoutSec()+" seconds";

        if (asyncEvent.getThrowable() instanceof CMBException) {
          httpCode = ((CMBException)asyncEvent.getThrowable()).getHttpCode();
          code = ((CMBException)asyncEvent.getThrowable()).getCMBCode();
          message = asyncEvent.getThrowable().getMessage();
        }

        String errXml = CMBControllerServlet.createErrorResponse(code, message);
        HttpServletResponse response = ((HttpServletResponse)asyncEvent.getSuppliedResponse());
        response.setStatus(httpCode);
        Action.writeResponse(errXml, response);

        if (!(asyncEvent.getSuppliedRequest() instanceof CQSHttpServletRequest)) {
          logger.error("event=invalid_request stage=on_timeout");
          return;
        }         

        CQSQueue queue = ((CQSHttpServletRequest)asyncEvent.getSuppliedRequest()).getQueue();
        asyncContext = asyncEvent.getAsyncContext();

        if (queue != null) {

          logger.error("event=on_timeout queue_url=" + queue.getAbsoluteUrl());

          ConcurrentLinkedQueue<AsyncContext> queueContextsList = CQSLongPollReceiver.contextQueues.get(queue.getArn());

          if (queueContextsList != null && asyncContext != null) {
            queueContextsList.remove(asyncContext);
          }

View Full Code Here

TOP

Related Classes of com.comcast.cqs.model.CQSQueue

Copyright © 2018 www.massapicom. 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.