Example #1
0
  public void createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly)
      throws Exception {
    Binding binding = postOffice.getBinding(queueName);

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

    securityStore.check(binding.getAddress(), CheckType.CONSUME, this);

    Filter filter = FilterImpl.createFilter(filterString);

    ServerConsumer consumer =
        new ServerConsumerImpl(
            consumerID,
            this,
            (QueueBinding) binding,
            filter,
            started,
            browseOnly,
            storageManager,
            callback,
            preAcknowledge,
            strictUpdateDeliveryCount,
            managementService);

    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());

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

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

      managementService.sendNotification(notification);
    }
  }
 public Response receive(final Proposal proposal, final int distance) throws Exception {
   TypedProperties props = new TypedProperties();
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());
   props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);
   props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
   props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance);
   Notification notification = new Notification(null, NotificationType.PROPOSAL, props);
   managementService.sendNotification(notification);
   return null;
 }
    private synchronized void doConsumerCreated(final ClientMessage message) throws Exception {
      if (HornetQServerLogger.LOGGER.isTraceEnabled()) {
        HornetQServerLogger.LOGGER.trace(
            ClusterConnectionImpl.this + " Consumer created " + message);
      }
      if (!message.containsProperty(ManagementHelper.HDR_DISTANCE)) {
        throw new IllegalStateException("distance is null");
      }

      if (!message.containsProperty(ManagementHelper.HDR_CLUSTER_NAME)) {
        throw new IllegalStateException("clusterName is null");
      }

      Integer distance = message.getIntProperty(ManagementHelper.HDR_DISTANCE);

      SimpleString clusterName = message.getSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME);

      message.putIntProperty(ManagementHelper.HDR_DISTANCE, distance + 1);

      SimpleString filterString =
          message.getSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING);

      RemoteQueueBinding binding = bindings.get(clusterName);

      if (binding == null) {
        throw new IllegalStateException(
            "Cannot find binding for " + clusterName + " on " + ClusterConnectionImpl.this);
      }

      binding.addConsumer(filterString);

      // Need to propagate the consumer add
      TypedProperties props = new TypedProperties();

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

      props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, clusterName);

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

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance + 1);

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

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

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

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

      managementService.sendNotification(notification);
    }
Example #4
0
  public Message putIntProperty(final String key, final int value) {
    properties.putIntProperty(new SimpleString(key), value);

    bufferValid = false;

    return this;
  }
Example #5
0
  public synchronized void stop() {
    if (!started) {
      return;
    }

    if (!paused) {
      InVMRegistry.instance.unregisterAcceptor(id);
    }

    for (Connection connection : connections.values()) {
      listener.connectionDestroyed(connection.getID());
    }

    connections.clear();

    if (notificationService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(
          new SimpleString("factory"), new SimpleString(InVMAcceptorFactory.class.getName()));
      props.putIntProperty(new SimpleString("id"), id);
      Notification notification = new Notification(null, NotificationType.ACCEPTOR_STOPPED, props);
      try {
        notificationService.sendNotification(notification);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    started = false;

    paused = false;
  }
  public Response propose(final Proposal proposal) throws Exception {
    // sanity check in case it is already selected
    Response response = responses.get(proposal.getGroupId());
    if (response != null) {
      return response;
    }

    try {
      lock.lock();

      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());

      props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, 0);

      Notification notification = new Notification(null, NotificationType.PROPOSAL, props);

      managementService.sendNotification(notification);

      if (!sendCondition.await(timeout, TimeUnit.MILLISECONDS))
        HornetQLogger.LOGGER.groupHandlerSendTimeout();
      response = responses.get(proposal.getGroupId());

    } finally {
      lock.unlock();
    }
    if (response == null) {
      throw new IllegalStateException(
          "no response received from group handler for " + proposal.getGroupId());
    }
    return response;
  }
Example #7
0
  public synchronized void start() throws Exception {
    if (started) {
      return;
    }

    InVMRegistry.instance.registerAcceptor(id, this);

    if (notificationService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(
          new SimpleString("factory"), new SimpleString(InVMAcceptorFactory.class.getName()));
      props.putIntProperty(new SimpleString("id"), id);
      Notification notification = new Notification(null, NotificationType.ACCEPTOR_STARTED, props);
      notificationService.sendNotification(notification);
    }

    started = true;

    paused = false;
  }
  public void close(final boolean failed) throws Exception {
    callback.removeReadyListener(this);

    setStarted(false);

    LargeMessageDeliverer del = largeMessageDeliverer;

    if (del != null) {
      del.finish();
    }

    if (browseOnly) {
      browserDeliverer.close();
    } else {
      messageQueue.removeConsumer(this);
    }

    session.removeConsumer(id);

    LinkedList<MessageReference> refs = cancelRefs(failed, false, null);

    Iterator<MessageReference> iter = refs.iterator();

    Transaction tx = new TransactionImpl(storageManager);

    while (iter.hasNext()) {
      MessageReference ref = iter.next();

      ref.getQueue().cancel(tx, ref);
    }

    tx.rollback();

    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.putSimpleStringProperty(
          ManagementHelper.HDR_FILTERSTRING, filter == null ? null : filter.getFilterString());

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

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

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

      props.putSimpleStringProperty(
          ManagementHelper.HDR_REMOTE_ADDRESS,
          SimpleString.toSimpleString(
              ((ServerSessionImpl) session).getRemotingConnection().getRemoteAddress()));

      props.putSimpleStringProperty(
          ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(session.getName()));

      Notification notification = new Notification(null, NotificationType.CONSUMER_CLOSED, props);

      managementService.sendNotification(notification);
    }
  }
 @Override
 public JMSProducer setProperty(String name, int value) {
   checkName(name);
   properties.putIntProperty(new SimpleString(name), value);
   return this;
 }
Example #10
0
  public void createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly,
      final boolean supportLargeMessage,
      final Integer credits)
      throws Exception {
    Binding binding = postOffice.getBinding(queueName);

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

    securityStore.check(binding.getAddress(), CheckType.CONSUME, this);

    Filter filter = FilterImpl.createFilter(filterString);

    ServerConsumer consumer =
        new ServerConsumerImpl(
            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, CONSUMER_CREATED, props);

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

      managementService.sendNotification(notification);
    }
  }