public LocalQueueBinding(
      final SimpleString address, final Queue queue, final SimpleString nodeID) {
    this.address = address;

    this.queue = queue;

    filter = queue.getFilter();

    name = queue.getName();

    clusterName = name.concat(nodeID);
  }
    public void run() {
      HashMap<Queue, LinkedList<MessageReference>> refs =
          new HashMap<Queue, LinkedList<MessageReference>>();

      runnables.remove(deliveryTime);

      final long now = System.currentTimeMillis();

      if (now < deliveryTime) {
        // Ohhhh... blame it on the OS
        // on some OSes (so far Windows only) the precision of the scheduled executor could
        // eventually give
        // an executor call earlier than it was supposed...
        // for that reason we will schedule it again so no messages are lost!
        // we can't just assume deliveryTime here as we could deliver earlier than what we are
        // supposed to
        // this is basically a hack to work around an OS or JDK bug!
        if (trace) {
          ActiveMQServerLogger.LOGGER.trace(
              "Scheduler is working around OS imprecisions on "
                  + "timing and re-scheduling an executor. now="
                  + now
                  + " and deliveryTime="
                  + deliveryTime);
        }
        ScheduledDeliveryHandlerImpl.this.scheduleDelivery(deliveryTime);
      }

      if (ScheduledDeliveryHandlerImpl.trace) {
        ActiveMQServerLogger.LOGGER.trace(
            "Is it "
                + System.currentTimeMillis()
                + " now and we are running deliveryTime = "
                + deliveryTime);
      }

      synchronized (scheduledReferences) {
        Iterator<RefScheduled> iter = scheduledReferences.iterator();
        while (iter.hasNext()) {
          MessageReference reference = iter.next().getRef();
          if (reference.getScheduledDeliveryTime() > now) {
            // We will delivery as long as there are messages to be delivered
            break;
          }

          iter.remove();

          reference.setScheduledDeliveryTime(0);

          LinkedList<MessageReference> references = refs.get(reference.getQueue());

          if (references == null) {
            references = new LinkedList<MessageReference>();
            refs.put(reference.getQueue(), references);
          }

          if (ScheduledDeliveryHandlerImpl.trace) {
            ActiveMQServerLogger.LOGGER.trace(
                "sending message " + reference + " to delivery, deliveryTime =  " + deliveryTime);
          }

          references.addFirst(reference);
        }
        if (ScheduledDeliveryHandlerImpl.trace) {
          ActiveMQServerLogger.LOGGER.trace("Finished loop on deliveryTime = " + deliveryTime);
        }
      }

      for (Map.Entry<Queue, LinkedList<MessageReference>> entry : refs.entrySet()) {

        Queue queue = entry.getKey();
        LinkedList<MessageReference> list = entry.getValue();
        if (trace) {
          ActiveMQServerLogger.LOGGER.trace(
              "Delivering " + list.size() + " elements on list to queue " + queue);
        }
        queue.addHead(list);
      }

      // Just to speed up GC
      refs.clear();
    }
  public boolean isHighAcceptPriority(final ServerMessage message) {
    // It's a high accept priority if the queue has at least one matching consumer

    return queue.hasMatchingConsumer(message);
  }
 public long getID() {
   return queue.getID();
 }
 public void close() throws Exception {
   queue.close();
 }
 public int consumerCount() {
   return queue.getConsumerCount();
 }
 public void routeWithAck(ServerMessage message, RoutingContext context) throws Exception {
   queue.routeWithAck(message, context);
 }
 public void route(final ServerMessage message, final RoutingContext context) throws Exception {
   queue.route(message, context);
 }
 @Override
 public void unproposed(SimpleString groupID) {
   queue.unproposed(groupID);
 }
Example #10
0
  @Override
  public ServerConsumer createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly,
      final boolean supportLargeMessage,
      final Integer credits)
      throws Exception {
    if (this.internal) {
      // internal sessions doesn't check security

      Binding binding = postOffice.getBinding(queueName);

      if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(queueName);
      }

      Filter filter = FilterImpl.createFilter(filterString);

      ServerConsumer consumer =
          newConsumer(
              consumerID,
              this,
              (QueueBinding) binding,
              filter,
              started,
              browseOnly,
              storageManager,
              callback,
              preAcknowledge,
              strictUpdateDeliveryCount,
              managementService,
              supportLargeMessage,
              credits);
      consumers.put(consumer.getID(), consumer);

      if (!browseOnly) {
        TypedProperties props = new TypedProperties();

        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());

        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());

        Queue theQueue = (Queue) binding.getBindable();

        props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());

        // HORNETQ-946
        props.putSimpleStringProperty(
            ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));

        props.putSimpleStringProperty(
            ManagementHelper.HDR_REMOTE_ADDRESS,
            SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));

        props.putSimpleStringProperty(
            ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));

        if (filterString != null) {
          props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
        }

        Notification notification =
            new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);

        if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
          ActiveMQServerLogger.LOGGER.debug(
              "Session with user="******", connection="
                  + this.remotingConnection
                  + " created a consumer on queue "
                  + queueName
                  + ", filter = "
                  + filterString);
        }

        managementService.sendNotification(notification);
      }

      return consumer;
    } else {
      return super.createConsumer(
          consumerID, queueName, filterString, browseOnly, supportLargeMessage, credits);
    }
  }