Package com.comcast.cqs.model

Examples of com.comcast.cqs.model.CQSQueue


   
    logger.debug("event=notification_received queue_arn=" + queueArn + " remote_address=" + remoteAddress);

        try {

          CQSQueue queue = request.getQueue();
          List<CQSMessage> messageList = PersistenceFactory.getCQSMessagePersistence().receiveMessage(queue, request.getReceiveAttributes());
   
      if (messageList.size() > 0) {
       
        messageCount = messageList.size();
       
        List<String> receiptHandles = new ArrayList<String>();
       
        for (CQSMessage message : messageList) {
                receiptHandles.add(message.getReceiptHandle());
              }
       
        request.setReceiptHandles(receiptHandles);
        request.setAttribute("lp", "yy"); // found lp call with messages
        CQSMonitor.getInstance().addNumberOfMessagesReturned(queue.getRelativeUrl(), messageList.size());
            String out = CQSMessagePopulator.getReceiveMessageResponseAfterSerializing(messageList, request.getFilterAttributes());
            Action.writeResponse(out, (HttpServletResponse)asyncContext.getResponse());
            long lp_ms = System.currentTimeMillis() - ts1;
            request.setAttribute("lp_ms", lp_ms);
            String cass_msString = String.valueOf(CQSControllerServlet.valueAccumulator.getCounter(AccumulatorName.CassandraTime));
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<CQSMessage> messageList = getMessages(request, true, queue);
       
        Map<String, String[]> requestParams = request.getParameterMap();
        List<String> filterAttributes = new ArrayList<String>();
       
View Full Code Here

        attributes.put(CQSConstants.SENT_TIMESTAMP, "" + System.currentTimeMillis());
        attributes.put(CQSConstants.APPROXIMATE_RECEIVE_COUNT, "0");
        attributes.put(CQSConstants.APPROXIMATE_FIRST_RECEIVE_TIMESTAMP, "");
       
        CQSMessage message = new CQSMessage(messageBody, attributes);
      CQSQueue queue = CQSCache.getCachedQueue(user, request);
     
      int shard = 0;
     
    String shardNumber = request.getParameter("Shard");

    if (shardNumber != null) {
      shard = Integer.parseInt(shardNumber);
    } else if (queue.getNumberOfShards() > 1) {
      shard = rand.nextInt(queue.getNumberOfShards());
    }
 
    if (shard < 0 || shard >= queue.getNumberOfShards()) {
          throw new CMBException(CMBErrorCodes.InvalidParameterValue, "Shard number " + shard +" exceeds number of available shards in queue (" + queue.getNumberOfShards() + ").");
    }

        String receiptHandle = PersistenceFactory.getCQSMessagePersistence().sendMessage(queue, shard, message);

        if (receiptHandle == null || receiptHandle.isEmpty()) {
            throw new CMBException(CMBErrorCodes.InternalError, "Failed to add message to queue");
        }
       
        request.setReceiptHandles(Arrays.asList(new String[] {receiptHandle}));
        message.setReceiptHandle(receiptHandle);
        message.setMessageId(receiptHandle);
        String out = CQSMessagePopulator.getSendMessageResponse(message);
        writeResponse(out, response);
        CQSMonitor.getInstance().addNumberOfMessagesReceived(queue.getRelativeUrl(), 1);
       
        try {
          CQSLongPollSender.send(queue.getArn());
        } catch (Exception ex) {
          logger.warn("event=failed_to_send_longpoll_notification", ex);
        }
       
        return true;
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);
        Map<String, String> idMap = new HashMap<String, String>();
        List<String> idList = new ArrayList<String>();
        List<CQSBatchResultErrorEntry> failedList = new ArrayList<CQSBatchResultErrorEntry>();
        int index = 1;
       
        String suppliedId = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + ".Id");
        String receiptHandle = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + "." + CQSConstants.RECEIPT_HANDLE);
       
        while (suppliedId != null && receiptHandle != null) {
           
          if (!Util.isValidId(suppliedId)) {
                throw new CMBException(CQSErrorCodes.InvalidBatchEntryId, "Id " + suppliedId + " is invalid. Only alphanumeric, hyphen, and underscore are allowed. It can be at most " + CMBProperties.getInstance().getCQSMaxMessageSuppliedIdLength() + " letters long.");
            }
           
          if (idList.contains(suppliedId)) {
                throw new CMBException(CQSErrorCodes.BatchEntryIdsNotDistinct, "You supplied same identifier for two messages");
            }
           
          idList.add(suppliedId);
           
          if (receiptHandle.isEmpty()) {
                failedList.add(new CQSBatchResultErrorEntry(suppliedId, true, "EmptyValue", "No Value Found for " + this.actionName + CQSConstants.REQUEST_ENTRY + index + "." + CQSConstants.RECEIPT_HANDLE));
            } else {
                idMap.put(suppliedId, receiptHandle);
            }
           
          index++;
            suppliedId = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + ".Id");
            receiptHandle = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + "." + CQSConstants.RECEIPT_HANDLE);
        }
       
        if (idMap.size() == 0) {
            throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "Both user supplied message Id and receiptHandle are required");
        }

        for (Map.Entry<String, String> entry : idMap.entrySet()) {
            receiptHandle = entry.getValue();
          PersistenceFactory.getCQSMessagePersistence().deleteMessage(queue.getRelativeUrl(), receiptHandle);
        }
       
        String out = CQSMessagePopulator.getDeleteMessageBatchResponse(new ArrayList<String>(idMap.keySet()), failedList);
        writeResponse(out, response);
       
View Full Code Here

    return messageList;
  }
 
  private CQSMessage extractMessageFromJSON(String queueUrl, CmbColumn column) throws JSONException, PersistenceException, IOException {
   
    CQSQueue queue = null;
    CQSMessage m = new CQSMessage();
   
    try {
      queue = CQSCache.getCachedQueue(queueUrl);
    } catch (Exception ex) {
      throw new PersistenceException(ex);
    }
   
    if (queue == null) {
      throw new PersistenceException(CMBErrorCodes.InternalError, "Unknown queue " + queueUrl);
    }
   
    JSONObject json = new JSONObject((String)column.getValue());

    m.setMessageId(json.getString("MessageId"));
    m.setReceiptHandle(json.getString("MessageId"));
    m.setMD5OfBody(json.getString("MD5OfBody"));
    m.setBody(json.getString("Body"));
   
    if (m.getAttributes() == null) {
      m.setAttributes(new HashMap<String, String>());
    }
   
    if (json.has(CQSConstants.SENT_TIMESTAMP)) {
      m.getAttributes().put(CQSConstants.SENT_TIMESTAMP, json.getString(CQSConstants.SENT_TIMESTAMP));
    }
   
    if (json.has(CQSConstants.APPROXIMATE_RECEIVE_COUNT)) {
      m.getAttributes().put(CQSConstants.APPROXIMATE_RECEIVE_COUNT, json.getString(CQSConstants.APPROXIMATE_RECEIVE_COUNT));
    }

    if (json.has(CQSConstants.SENDER_ID)) {
      m.getAttributes().put(CQSConstants.SENDER_ID, json.getString(CQSConstants.SENDER_ID));
    }
   
    m.setTimebasedId(column.getName());
   
    if (queue.isCompressed()) {
      m.setBody(Util.decompress(m.getBody()));
    }
   
      return m;
  }
View Full Code Here

        attributes.put("ApproximateReceiveCount", "0");
        attributes.put("ApproximateFirstReceiveTimestamp", "");     
    queue = queuePersistence.getQueue(queueUrl);
   
    if (queue == null) {
      queue = new CQSQueue("testQueue1824281", user.getUserId());
      queue.setRegion(CMBProperties.getInstance().getRegion());
      queuePersistence.createQueue(queue);
    }
   
    persistence.clearQueue(queue.getRelativeUrl(), 0);
View Full Code Here

    int numberPartitions = CMBProperties.getInstance().getCQSNumberOfQueuePartitions();
   
    try {
     
      CQSQueue queue = CQSCache.getCachedQueue(queueUrl);
     
      if (queue != null) {
        numberPartitions = queue.getNumberOfPartitions();
      }
     
    } catch (Exception ex) {
      logger.warn("event=queue_cache_failure queue_url=" + queueUrl, ex);
    }
View Full Code Here

    return minMessageId;
  }
 
  private long getQueueMessageCount(String queueUrl) throws Exception {
   
    CQSQueue queue = CQSCache.getCachedQueue(queueUrl);
    int numberOfPartitions = queue.getNumberOfPartitions();
    int numberOfShards = queue.getNumberOfShards();
    String queueHash = com.comcast.cqs.util.Util.hashQueueUrl(queueUrl);
    long messageCount = 0;
   
    for (int k=0; k<numberOfShards; k++) {
      for (int i=0; i<numberOfPartitions; i++) {
View Full Code Here

    int numberShards = 1;
   
    try {
     
      CQSQueue queue = CQSCache.getCachedQueue(queueUrl);
     
      if (queue != null) {
        numberShards = queue.getNumberOfShards();
      }
     
    } catch (Exception ex) {
      logger.warn("event=queue_cache_failure queue_url=" + queueUrl, ex);
    }
View Full Code Here

  }
 
  public static String getQueueUrlHashFromCache(String queueUrl){
    String queueUrlHash = null;
    try {
      CQSQueue queue = CQSCache.getCachedQueue(queueUrl);
      if(queue != null){
        queueUrlHash = CQSCache.getCachedQueue(queueUrl)
          .getRelativeUrlHash();
      }
      if (queueUrlHash == null) {
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.