예제 #1
0
  // To clone a message from a BytesMessage which is NOT BytesMessageImpl
  // Changing order of parameter to NOT accidentally clash with the constructor above.
  // This is midly confusing, but helps a lot in preventing accidental bugs !
  public BytesMessageImpl(BytesMessage message, SessionImpl session) throws JMSException {
    super((Message) message, session);

    if (message instanceof BytesMessageImpl) {
      throw new JMSException(
          "Coding bug - should use this constructor ONLY for non " + "BytesMessageImpl messages");
    }

    // copy the bytes ...
    final byte[] data;
    {
      final long length = message.getBodyLength();
      if (length < 0 || length >= Integer.MAX_VALUE)
        throw new JMSException("Unreasonably " + "large value for body Length : " + length);

      data = new byte[(int) length];
      int read = 0;
      while (read < length) {
        int sz = message.readBytes(data, read);
        read += sz;
      }
    }

    try {
      this.writeOnlyMessage = new WriteOnlyMessage(data);
    } catch (IOException e) {
      JMSException ex =
          new JMSException("Unable to clone/copy input message " + message + " .. " + e);
      ex.setLinkedException(e);
      throw ex;
    }
    this.readOnlyMessage = null;
    this.readMode = true;
  }
예제 #2
0
 @Override
 public void reset() throws JMSException {
   if (this.readMode) return;
   try {
     this.readOnlyMessage = new ReadOnlyMessage(writeOnlyMessage.getPayloadAsBytes());
   } catch (IOException e) {
     JMSException ex =
         new JMSException("Unable to convert write-only message to read-only message .. " + e);
     ex.setLinkedException(e);
     throw ex;
   }
   this.readMode = true;
   this.writeOnlyMessage = null;
 }
예제 #3
0
  @Override
  public PubSubProtocol.Message generateHedwigMessage() throws JMSException {
    PubSubProtocol.Message.Builder builder = PubSubProtocol.Message.newBuilder();
    super.populateBuilderWithHeaders(builder);

    // Now set body and type.
    try {
      builder.setBody(ByteString.copyFrom(getPayloadData()));
    } catch (IOException e) {
      JMSException ex = new JMSException("Unable to read message data .. " + e);
      ex.setLinkedException(e);
      throw ex;
    }

    return builder.build();
  }
예제 #4
0
파일: SessionImpl.java 프로젝트: ncdc/qpid
  public void unsubscribe(final String s) throws JMSException {
    checkClosed();

    checkNotQueueSession();

    Target target = new Target();
    target.setAddress(UUID.randomUUID().toString());

    try {
      Receiver receiver =
          new Receiver(
              getClientSession(),
              s,
              target,
              null,
              org.apache.qpid.amqp_1_0.client.AcknowledgeMode.ALO,
              false);

      final org.apache.qpid.amqp_1_0.type.Source receiverSource = receiver.getSource();
      if (receiverSource instanceof Source) {
        Source source = (Source) receiverSource;
        receiver.close();
        receiver =
            new Receiver(
                getClientSession(),
                s,
                target,
                source,
                org.apache.qpid.amqp_1_0.client.AcknowledgeMode.ALO,
                false);
      }
      receiver.close();
    } catch (AmqpErrorException e) {
      if (e.getError().getCondition() == AmqpError.NOT_FOUND) {
        throw new InvalidDestinationException(s);
      } else {
        JMSException jmsException = new JMSException(e.getMessage());
        jmsException.setLinkedException(e);
        throw jmsException;
      }
    }

    // TODO
  }
예제 #5
0
 // To clone a message
 public BytesMessageImpl(
     SessionImpl session, BytesMessageImpl message, String sourceTopicName, String subscriberId)
     throws JMSException {
   super(session, (MessageImpl) message, sourceTopicName, subscriberId);
   try {
     if (message.readMode) {
       this.readOnlyMessage = new ReadOnlyMessage(message.readOnlyMessage.getDataCopy());
       this.writeOnlyMessage = null;
     } else {
       this.readOnlyMessage = null;
       this.writeOnlyMessage = new WriteOnlyMessage(message.writeOnlyMessage.getPayloadAsBytes());
     }
   } catch (IOException e) {
     JMSException ex =
         new JMSException("Unable to clone/copy input message " + message + " .. " + e);
     ex.setLinkedException(e);
     throw ex;
   }
   this.readMode = message.readMode;
 }
예제 #6
0
  public static AMQTopic createDurableTopic(
      Topic topic, String subscriptionName, AMQConnection connection) throws JMSException {
    if (topic instanceof AMQDestination && topic instanceof javax.jms.Topic) {
      AMQDestination qpidTopic = (AMQDestination) topic;
      if (qpidTopic.getDestSyntax() == DestSyntax.ADDR) {
        try {
          AMQTopic t = new AMQTopic(qpidTopic.getAddress());
          AMQShortString queueName = getDurableTopicQueueName(subscriptionName, connection);
          // link is never null if dest was created using an address string.
          t.getLink().setName(queueName.asString());
          t.getSourceNode().setAutoDelete(false);
          t.getSourceNode().setDurable(true);

          // The legacy fields are also populated just in case.
          t.setQueueName(queueName);
          t.setAutoDelete(false);
          t.setDurable(true);
          return t;
        } catch (Exception e) {
          JMSException ex = new JMSException("Error creating durable topic");
          ex.initCause(e);
          ex.setLinkedException(e);
          throw ex;
        }
      } else {
        return new AMQTopic(
            qpidTopic.getExchangeName(),
            qpidTopic.getRoutingKey(),
            false,
            getDurableTopicQueueName(subscriptionName, connection),
            true);
      }
    } else {
      throw new InvalidDestinationException(
          "The destination object used is not from this provider or of type javax.jms.Topic");
    }
  }