Ejemplo n.º 1
0
  public void send(
      Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
      throws JMSException {
    if (message == null) {
      throw new MessageFormatException(Messages.getString("MessageProducerImpl_0")); // $NON-NLS-1$
    }

    // message.setJMSMessageID(MessageId.create());
    message.setJMSDestination(destination);
    message.setJMSTimestamp(new Date().getTime());
    message.setJMSPriority(priority);

    if (timeToLive > 0) {
      message.setJMSExpiration(System.currentTimeMillis() + timeToLive);
    } else {
      message.setJMSExpiration(0);
    }

    if (destination instanceof JMSTemporaryDestination) {
      message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    } else {
      message.setJMSDeliveryMode(deliveryMode);
    }

    session.sendMessage(message);
  }
Ejemplo n.º 2
0
  public Message receive(long timeout) throws JMSException {
    if (messageListener != null) {
      throw new JMSException(Messages.getString("MessageConsumerImpl.0")); // $NON-NLS-1$
    }

    if (timeout == DO_NOT_WAIT) {
      return messages.poll();
    }

    try {
      return messages.poll(timeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
      throw new JMSException(ex.getMessage());
    }
  }
Ejemplo n.º 3
0
  public void dispatchMessage() {
    MessageListener listener = messageListener;
    if (listener != null) {
      MessageImpl message = messages.poll();
      if (message == null) {
        OM.LOG.warn(Messages.getString("MessageConsumerImpl.1")); // $NON-NLS-1$
        return;
      }

      try {
        listener.onMessage(message);
        if (!session.getTransacted()
            && session.getAcknowledgeMode() != Session.CLIENT_ACKNOWLEDGE) {
          session.acknowledgeMessages(this);
        }
      } catch (RuntimeException ex) {
        OM.LOG.warn(ex);
      }
    }
  }