1 28 29 package com.caucho.jms.jca; 30 31 import com.caucho.log.Log; 32 import com.caucho.services.message.MessageSender; 33 import com.caucho.services.message.MessageServiceException; 34 import com.caucho.util.L10N; 35 36 import javax.jms.Message ; 37 import javax.jms.ObjectMessage ; 38 import javax.resource.spi.ConnectionManager ; 39 import java.util.HashMap ; 40 import java.util.logging.Logger ; 41 42 45 class MessageSenderImpl implements MessageSender { 46 protected static final Logger log = Log.open(MessageSenderImpl.class); 47 private static final L10N L = new L10N(MessageSenderImpl.class); 48 49 private MessageSenderManager _manager; 50 private ConnectionManager _cm; 51 52 MessageSenderImpl(MessageSenderManager manager, ConnectionManager cm) 53 { 54 _manager = manager; 55 _cm = cm; 56 } 57 58 public void send(HashMap header, Object value) 59 throws MessageServiceException 60 { 61 ManagedSessionImpl session = null; 62 63 try { 64 session = (ManagedSessionImpl) _cm.allocateConnection(_manager, null); 65 66 Message message; 67 68 if (value == null) { 69 message = session.getSession().createMessage(); 70 } 71 else if (value instanceof String ) { 72 message = session.getSession().createTextMessage((String ) value); 73 } 74 else if (value instanceof java.io.Serializable ) { 75 ObjectMessage objMessage = session.getSession().createObjectMessage(); 76 objMessage.setObject((java.io.Serializable ) value); 77 message = objMessage; 78 } 79 else { 80 throw new MessageServiceException(L.l("value '{0}' must be serializable", 81 value)); 82 } 83 84 session.send(message); 85 } catch (MessageServiceException e) { 86 throw e; 87 } catch (Exception e) { 88 e.printStackTrace(); 89 throw new MessageServiceException(e); 90 } finally { 91 if (session != null) 92 session.close(); 93 } 94 } 95 } 96 97 | Popular Tags |