Package com.cloudhopper.mq.queue

Examples of com.cloudhopper.mq.queue.Queue


    }

    synchronized private void startLocalToRemoteQueueProcessor(String queueName) {
        // get the local queue
        Queue localQueue = null;

        try {
            localQueue = queueManager.getQueue(queueName);
        } catch (QueueInvalidStateException e) {
            logger.error("Unable to complete startLocalToRemoteQueueProcessor since QueueManager is in an invalid state", e);
            return;
        }

        // if no local queue, silently ignore this event?
        if (localQueue == null) {
            logger.warn("Unable to complete startLocalToRemoteQueueProcessor since local queue [" + queueName + "] does not exist - perhaps a delayed event?");
            return;
        }

        // if there is a local consumer for this queue, we need to ignore this
        if (localQueue.getConsumerCount() > 0) {
            logger.warn("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: there are currently [" + localQueue.getConsumerCount() + "] local consumers");
            return;
        }

        // make sure there is a remote queue
        RemoteQueueInfo remoteQueue = dqs.getRemoteQueue(queueName);

        if (remoteQueue == null) {
            logger.error("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: there is no remote queue for it in DistributedQueueState");
            return;
        }

        if (remoteQueue.isNotAvailable()) {
            logger.error("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: the remote queue is not available (perhaps it flapped?)");
            return;
        }

        // is there already a processor?
        LocalToRemoteQueueProcessor queueProcessor = this.queueProcessors.get(queueName);

        if (queueProcessor != null) {
            // is it still alive?
            if (!queueProcessor.isKilled() && queueProcessor.isAlive()) {
                logger.error("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: the processor already exists and is still alive");
                return;
            }
        }

        logger.debug("Creating and starting LocalToRemoteQueueProcessor for queue [" + localQueue.getName() + "]");

  try {
      // create a new processor
      queueProcessor = new LocalToRemoteQueueProcessor(this, localQueue, remoteQueue, httpFactory);
     
View Full Code Here


    }

    public void inform() throws Exception {
  Enumeration<Queue> queues = queueManager.getQueues();
  while (queues.hasMoreElements()) {
      Queue queue = queues.nextElement();
      printHeader(queue);
  }
    }
View Full Code Here

    }

    public void dump() throws Exception {
  Enumeration<Queue> queues = queueManager.getQueues();
  while (queues.hasMoreElements()) {
      Queue queue = queues.nextElement();
      dump(queue);
  }
    }
View Full Code Here

    }

    public void inform(PrintStream out) {
  Enumeration<Queue> queues = queueManager.getQueues();
  while (queues.hasMoreElements()) {
      Queue queue = queues.nextElement();
      out.println(queue.toString());
  }
    }
View Full Code Here

    }

    public void dump() throws Exception {
  Enumeration<Queue> queues = queueManager.getQueues();
  while (queues.hasMoreElements()) {
      Queue queue = queues.nextElement();
      dump(queue);
  }
    }
View Full Code Here

    protected synchronized Runnable getNextRemoteTransfer() throws InterruptedException {
  logger.trace("getNextRemoteTransfer()");
  RemotingQueueDrain r = null;
  do {
      Queue q = workList.take();
      if (q != null) {
    if (processors.get(q) != null) {
        logger.trace("[{}] Queue from getNext(), returning RemotingQueueDrain.", q.getName());
        r = new RemotingQueueDrain(q, processors.get(q), maxConcurrentRequests, this);
    } else {
        logger.trace("[{}] Queue from getNext(), but L2R was already killed/null.", q.getName());
    }
      } else {
    logger.warn("Queue from getNext() was null, something is now WRONG.");
      }
  } while (r == null);
View Full Code Here

    ps.println("<tr><td>Queue Name</td><td>Size</td><td>Producers</td><td>Consumers</td><td>Last Producer Date</td><td>Last Consumer Date</td></tr>");

    // print out a list of every queue
    Enumeration<Queue> queues = queueManager.getQueues();
    while (queues.hasMoreElements()) {
        Queue queue = queues.nextElement();
        ps.print("<tr><td>");
        ps.print(queue.getName());
        ps.print("</td><td>");
        ps.print(queue.getSize());
        ps.print("</td><td>");
        ps.print(queue.getProducerCount());
        ps.print("</td><td>");
        ps.print(queue.getConsumerCount());
        ps.print("</td><td>");
        ps.print(queue.getLastProducerCountChangeTime());
        ps.print("</td><td>");
        ps.print(queue.getLastConsumerCountChangeTime());
        ps.print("</td></tr>");
    }
           
    ps.println("</table>");
      } else if (cmd.equals("monitor")) {
    // is the optional "since" parameter included -- this is asking
    // for updates only after this timestamp....
    long since = -1;
    String sinceString = request.getParameter("since");
    if (!StringUtil.isEmpty(sinceString)) {
        try {
      since = Long.parseLong(sinceString);
        } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      ps.print("Unable to convert since query parameter to a long value");
      return;
        }
    }

    // print out result code, version, areaId
    ps.print(ProtocolConstants.KEY_RESULT_CODE + ":" + ProtocolConstants.RC_OK + ProtocolConstants.LINE_DELIMITER);
    ps.print(ProtocolConstants.KEY_VERSION + ":" + ProtocolConstants.CURRENT_VERSION + ProtocolConstants.LINE_DELIMITER);
    ps.print(ProtocolConstants.KEY_AREA_ID + ":" + dqm.getConfiguration().getAreaId() + ProtocolConstants.LINE_DELIMITER);
           
    // print out a list of every queue
    Enumeration<Queue> queues = queueManager.getQueues();
    while (queues.hasMoreElements()) {
        Queue queue = queues.nextElement();

        // should we match the last timestamp for a consumer change?
        if (since > 0) {
      // if this queue hasn't been changed since the last time
      if (queue.getLastConsumerCountChangeTime() < since) {
          continue;
      }
        }

        // is this a "local only" queue?
        if (queue.isLocalOnly()) {
      continue;
        }

        ps.print(ProtocolConstants.KEY_QUEUE);
        ps.print(":");
        ps.print(queue.getName());
        ps.print(",");
        ps.print(queue.getConsumerCount());
        ps.print(ProtocolConstants.LINE_DELIMITER);
    }
      } else if (cmd.equals("transfer")) {

    String queueName = request.getParameter("queue");
    if (StringUtil.isEmpty(queueName)) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        ps.print("Parameter queue is required for a transfer request");
        return;
    }

    byte[] entityContent = requestToByteArray(request);
    if (entityContent == null || entityContent.length <= 0) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        ps.print("Probably not a POST request since body does not contain an entity");
        return;
    }

    logger.trace("[{}] Received transfer request to queue with an item having a byteLength [{}]", queueName, entityContent.length);

    // at this point, we'll be returning an actual response back
    int result = 0;
    String message = "OK";

    // ahh, let's see if the queue exists...
    if (!queueManager.hasQueue(queueName)) {

        result = ProtocolConstants.RC_NO_QUEUE;
        message = "The queue " + queueName + " was not found";

    } else {

        // get the queue -- we know it exists
        Queue queue = queueManager.getQueue(queueName);

        // are there still consumers?
        if (queue.getConsumerCount() <= 0) {

      result = ProtocolConstants.RC_NO_CONSUMER;
      message = "No local consumers for queue " + queueName;

        } else {

      // get the transcoder
      Transcoder tc = queue.getTranscoder();

      try {
          // transcode the item
          Object item = item = tc.decode(entityContent);
          logger.trace("[{}] Parsed item: {}", queueName, item);
View Full Code Here

    }

    synchronized private void startLocalToRemoteQueueProcessor(String queueName) {
        // get the local queue
        Queue localQueue = null;

        try {
            localQueue = queueManager.getQueue(queueName);
        } catch (QueueInvalidStateException e) {
            logger.error("Unable to complete startLocalToRemoteQueueProcessor since QueueManager is in an invalid state", e);
            return;
        }

        // if no local queue, silently ignore this event?
        if (localQueue == null) {
            logger.warn("Unable to complete startLocalToRemoteQueueProcessor since local queue [" + queueName + "] does not exist - perhaps a delayed event?");
            return;
        }

        // if there is a local consumer for this queue, we need to ignore this
        if (localQueue.getConsumerCount() > 0) {
            logger.warn("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: there are currently [" + localQueue.getConsumerCount() + "] local consumers");
            return;
        }

        // make sure there is a remote queue
        RemoteQueueInfo remoteQueue = dqs.getRemoteQueue(queueName);

        if (remoteQueue == null) {
            logger.error("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: there is no remote queue for it in DistributedQueueState");
            return;
        }

        if (remoteQueue.isNotAvailable()) {
            logger.error("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: the remote queue is not available (perhaps it flapped?)");
            return;
        }

        // is there already a processor?
        LocalToRemoteQueueProcessor queueProcessor = this.queueProcessors.get(queueName);

        if (queueProcessor != null) {
            // is it still alive?
            if (!queueProcessor.isKilled() && queueProcessor.isAlive()) {
                logger.error("Ignoring request to startLocalToRemoteQueueProcessor for queue [" + queueName + "]: the processor already exists and is still alive");
                return;
            }
        }

        logger.debug("Creating and starting LocalToRemoteQueueProcessor for queue [" + localQueue.getName() + "]");

  try {
      // create a new processor
      queueProcessor = new LocalToRemoteQueueProcessor(this, localQueue, remoteQueue, transferHttpFactory);
     
View Full Code Here

        ps.print(",\"queues\":[");
       
        int i = 0;
        Enumeration<Queue> queues = queueManager.getQueues();
        while (queues.hasMoreElements()) {
            Queue queue = queues.nextElement();
           
            if (i != 0) {
                ps.print(",");
            }
           
            ps.print("{");
            ps.print("\"name\":\"");
            ps.print(queue.getName());
            ps.print("\"");
            ps.print(",");
             ps.print("\"id\":");
            ps.print(queue.getId());
            ps.print(",");
            ps.print("\"size\":");
            ps.print(queue.getSize());
            ps.print(",");
            ps.print("\"putCount\":");
            ps.print(queue.getPutCount());
            ps.print(",");
            ps.print("\"takeCount\":");
            ps.print(queue.getTakeCount());
            ps.print(",");
            ps.print("\"errorCount\":");
            ps.print(queue.getErrorCount());
            ps.print(",");
            ps.print("\"sessionCount\":");
            ps.print(queue.getSessionCount());
            ps.print(",");
            ps.print("\"consumerCount\":");
            ps.print(queue.getConsumerCount());
            ps.print(",");
            ps.print("\"producerCount\":");
            ps.print(queue.getProducerCount());
            ps.print(",");
            ps.print("\"localOnly\":");
            ps.print(queue.isLocalOnly());
           
            ps.print("}");
           
            i++;
        }
View Full Code Here

        } else {
            // create TreeMap of queues so that queue names are sorted alphabetically
            TreeMap<String,Queue> sortedQueues = new TreeMap<String,Queue>();
            Enumeration<Queue> queues = queueManager.getQueues();
            while (queues.hasMoreElements()) {
                Queue queue = queues.nextElement();
                sortedQueues.put(queue.getName(), queue);
            }

            for (Queue queue : sortedQueues.values()) {
                ps.print("<tr><td>");
                ps.print(queue.getName());
                ps.print("</td><td align=right>");
                ps.print(queue.getSize());
                ps.print("</td><td align=right>");
                ps.print(queue.getPutCount());
                ps.print("</td><td align=right>");
                ps.print(queue.getTakeCount());
                ps.print("</td><td align=right>");
                ps.print(queue.getErrorCount());
                ps.print("</td><td align=right>");
                ps.print(queue.getSessionCount());
                ps.print("</td><td align=right>");
                ps.print(queue.getConsumerCount());
                ps.print("</td><td align=right>");
                ps.print(queue.getProducerCount());
                ps.print("</td><td align=center>");
                ps.print(dqm.getQueueProcessors().containsKey(queue.getName()));
                ps.print("</td><td>");
                ps.print(queue.getElementType().getCanonicalName());
                ps.print("</td></tr>");
            }
        }

        ps.println("</table>");
View Full Code Here

TOP

Related Classes of com.cloudhopper.mq.queue.Queue

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.