Package javax.jms

Examples of javax.jms.Message


           * The first queue entry shall be deleted after writing it
           * to the DeletedMessageStore, because the OnError
           * resolution is Delete
           */
          QueueReceiver receiver = getReceiver(mDeleteQueue);
          Message message = receiver.receiveNoWait();
          if (message.getJMSMessageID().equals(mDeleteMessageId)
              && DeletedMessageStore.getInstance().writeMessage()) {
            mSession.commit();
          } else {
            mSession.rollback();
          }
View Full Code Here


         if (!(message instanceof Message))
         {
            return false;
         }
        
         Message mess = (Message)message;
              
         // Set the identifiers values
         Iterator i = identifiers.values().iterator();
        
         while (i.hasNext())
         {
            Identifier id = (Identifier) i.next();
           
            Object find = mess.getObjectProperty(id.name);
           
            if (find == null)
               find = getHeaderFieldReferences(mess, id.name);
           
            if (find == null)
View Full Code Here

      MethodInvocation mi = (MethodInvocation)invocation;
     
      Object[] args = mi.getArguments();
     
      Destination destination = (Destination)args[0];
      Message m = (Message)args[1];
      int deliveryMode = ((Integer)args[2]).intValue();
      int priority = ((Integer)args[3]).intValue();
      long timeToLive = ((Long)args[4]).longValue();

      // configure the message for sending, using attributes stored as metadata

      ProducerState producerState = getProducerState(mi);

      if (deliveryMode == -1)
      {
         // Use the delivery mode of the producer
         deliveryMode = producerState.getDeliveryMode();
         if (trace) { log.trace("Using producer's default delivery mode: " + deliveryMode); }
      }
      m.setJMSDeliveryMode(deliveryMode);

      if (priority == -1)
      {
         // Use the priority of the producer
         priority = producerState.getPriority();
         if (trace) { log.trace("Using producer's default priority: " + priority); }
      }
      m.setJMSPriority(priority);

      if (producerState.isDisableMessageTimestamp())
      {
         m.setJMSTimestamp(0l);
      }
      else
      {
         m.setJMSTimestamp(System.currentTimeMillis());
      }

      if (timeToLive == Long.MIN_VALUE)
      {
         // Use time to live value from producer
         timeToLive = producerState.getTimeToLive();
         if (trace) { log.trace("Using producer's default timeToLive: " + timeToLive); }
      }
     
      if (timeToLive == 0)
      {
         // Zero implies never expires
         m.setJMSExpiration(0);
      }
      else
      {
         m.setJMSExpiration(System.currentTimeMillis() + timeToLive);
      }

      if (destination == null)
      {
         // use destination from producer
         destination = producerState.getDestination();
        
         if (destination == null)
         {
            throw new UnsupportedOperationException("Destination not specified");
         }

         if (trace) { log.trace("Using producer's default destination: " + destination); }
      }
      else
      {
         // if a default destination was already specified then this must be same destination as
         // that specified in the arguments

         if (producerState.getDestination() != null &&
             !producerState.getDestination().equals(destination))
         {
            throw new UnsupportedOperationException("Where a default destination is specified " +
                                                    "for the sender and a destination is " +
                                                    "specified in the arguments to the send, " +
                                                    "these destinations must be equal");
         }
      }

      m.setJMSDestination(destination);
     
      SessionState sessionState = (SessionState)producerState.getParent();
                 
      // Generate the message id
      ConnectionState connectionState = (ConnectionState)sessionState.getParent();
     
      long id =
         connectionState.getIdGenerator().getId((ConnectionDelegate)connectionState.getDelegate());
   
      JBossMessage messageToSend;
      boolean foreign = false;

      if (!(m instanceof MessageProxy))
      {
         // it's a foreign message

         foreign = true;
        
         // JMS 1.1 Sect. 3.11.4: A provider must be prepared to accept, from a client,
         // a message whose implementation is not one of its own.

         // create a matching JBossMessage Type from JMS Type
         if(m instanceof BytesMessage)
         {
            messageToSend = new JBossBytesMessage((BytesMessage)m,0);
         }
         else if(m instanceof MapMessage)
         {
            messageToSend = new JBossMapMessage((MapMessage)m,0);
         }
         else if(m instanceof ObjectMessage)
         {
            messageToSend = new JBossObjectMessage((ObjectMessage)m,0);
         }
         else if(m instanceof StreamMessage)
         {
            messageToSend = new JBossStreamMessage((StreamMessage)m,0);
         }
         else if(m instanceof TextMessage)
         {
            messageToSend = new JBossTextMessage((TextMessage)m,0);
         }
         else
         {
            messageToSend = new JBossMessage(m, 0);
         }
        
         messageToSend.setJMSMessageID(null);
      }
      else
      {
         // get the actual message
         MessageProxy proxy = (MessageProxy)m;
                                   
         //The following line executed on the proxy should cause a copy to occur
         //if it is necessary
         proxy.setJMSMessageID(null);
        
         //Get the underlying message
         messageToSend = proxy.getMessage();    
        
         proxy.beforeSend();
      }
     
      // Set the new id
     
      messageToSend.setMessageId(id);
     
      // This only really used for BytesMessages and StreamMessages to reset their state
      messageToSend.doBeforeSend();
     
      // now that we know the messageID, set it also on the foreign message, if is the case
      if (foreign)
      {
         m.setJMSMessageID(messageToSend.getJMSMessageID());
      }
           
      // we now invoke the send(Message) method on the session, which will eventually be fielded
      // by connection endpoint
      ((SessionDelegate)sessionState.getDelegate()).send(messageToSend, false);
View Full Code Here

   {
      try
      {
         while (count < numMessages)
         {
            Message m = sess.createMessage();
            m.setStringProperty("PROD_NAME", prodName);
            m.setIntProperty("MSG_NUMBER", count);
       //     log.info("sent: " + prodName + ":" + count);
            prod.send(m);
            count++;
         }
      }
View Full Code Here

      }
      //receive
     
      for (int i = 0; i < NUM_MESSAGES; i++)
      {
         Message m = cons.receive();
         log.info("Received " + i);
      }
   }
View Full Code Here

      }
      //receive
     
      for (int i = 0; i < NUM_MESSAGES/2; i++)
      {
         Message m = cons1.receive();
         log.info("Received " + i);
      }
      log.info("Starting second queue");
      for (int i = 0; i < NUM_MESSAGES/2; i++)
      {
         Message m = cons2.receive();
         log.info("Received " + i);
      }
   }
View Full Code Here

         for (int outerCount = 0; outerCount < iterations; outerCount++)
         {
            for (int innerCount = 0; innerCount < commitSize; innerCount++)
            {
               Message m = getMessage();
                          
               if (m == null)
               {
                  log.error("Message is null");
                  failed = true;
                  return;
               }
               String prodName = m.getStringProperty("PROD_NAME");
               Integer msgCount = new Integer(m.getIntProperty("MSG_NUMBER"));
              
              // log.info("got " + prodName + ":" + msgCount);
                       
               Count count = (Count)counts.get(prodName);
               if (count == null)
               {
                  //First time
                  if (msgCount.intValue() != 0)
                  {
                     log.error("First message from " + prodName + " is not 0, it is " + msgCount);
                     failed = true;
                     return;
                  }
                  else
                  {
                     count = new Count();
                     counts.put(prodName, count);
                  }
               }
               else
               {
                  if (count.lastCommitted != msgCount.intValue() - 1)
                  {
                     log.error("Message out of sequence for " + m.getJMSMessageID() + " " + prodName + ", expected " + (count.lastCommitted + 1) + ", actual " + msgCount);
                     failed = true;
                     return;
                  }
               }
               count.lastCommitted = msgCount.intValue();
              
               count.lastReceived = msgCount.intValue();
              
               if (innerCount == commitSize -1)
               {
                  sess.commit();
               }
              
               processingDone();           
            }           
                       
            if (outerCount == iterations - 1)
            {
               break;
            }
                       
            for (int innerCount = 0; innerCount < rollbackSize; innerCount++)
            {
               Message m = getMessage();
              
               if (m == null)
               {
                  log.error("Message is null");
                  failed = true;
                  return;
               }
               String prodName = m.getStringProperty("PROD_NAME");              
               Integer msgCount = new Integer(m.getIntProperty("MSG_NUMBER"));
              
            //   log.info("got " + prodName + ":" + msgCount);
                
               Count count = (Count)counts.get(prodName);
               if (count == null)
View Full Code Here

     
      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
     
      for (int i = 0; i < numMessages; i++)
      {
         Message m = sess.createMessage();
        
         m.setStringProperty("name", "Watt");
        
         prod.send(m);
        
         if (i % 100 == 0)
         {
View Full Code Here

        
         //Now send the message(s)  
           
         Iterator iter = messages.iterator();
        
         Message msg = null;
        
         while (iter.hasNext())
         {
            msg = (Message)iter.next();
           
View Full Code Here

         MessageProducer prod = sessSend.createProducer(queue2);

         prod.setDeliveryMode(DeliveryMode.PERSISTENT);

         Message m = sessSend.createTextMessage("hello");

         prod.send(m);

         sessSend.commit();
View Full Code Here

TOP

Related Classes of javax.jms.Message

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.