1 23 package com.sun.enterprise.jbi.serviceengine.comm; 24 import com.sun.enterprise.jbi.serviceengine.work.OneWork; 25 import java.util.logging.Level ; 26 import javax.jbi.messaging.MessagingException; 27 import javax.jbi.messaging.ExchangeStatus; 28 import javax.jbi.messaging.MessageExchange; 29 30 31 39 public class MessageSender extends OneWork { 40 41 46 public void send() { 47 execute(); 48 } 49 50 53 public void doWork() { 54 try { 55 if (logger.isLoggable(Level.FINEST)) { 56 logger.log(Level.FINEST, 57 "Sending the message " + getMessageExchange() + "to NMR"); 58 } 59 60 boolean sendSync = shouldSendSync(getMessageExchange()); 61 if(sendSync) { 62 getDeliveryChannel().sendSync(getMessageExchange()); 63 } else { 64 getDeliveryChannel().send(getMessageExchange()); 65 } 66 67 if (getMessageExchange().getStatus()== ExchangeStatus.ERROR) 68 setException(getMessageExchange().getError()); 69 70 if (logger.isLoggable(Level.FINEST)) { 71 logger.log(Level.FINEST, 72 "Sent message " + getMessageExchange() + "to NMR"); 73 } 74 } catch (MessagingException me) { 75 logger.log(Level.WARNING, "Error sending message" + me.getMessage()); 76 setException(me); 77 } 78 } 79 80 private boolean shouldSendSync(MessageExchange exchange) { 81 boolean sendSync = true; 82 83 ExchangeStatus status = getMessageExchange().getStatus(); 84 85 89 if (ExchangeStatus.DONE.equals(status) || ExchangeStatus.ERROR.equals(status)) { 90 sendSync = false; 91 } 92 93 return sendSync; 94 } 95 } 96 | Popular Tags |