1 24 package org.objectweb.joram.client.jms.tcp; 25 26 import java.util.Timer ; 27 28 import javax.jms.IllegalStateException ; 29 import javax.jms.JMSException ; 30 import javax.jms.JMSSecurityException ; 31 32 import org.objectweb.joram.client.jms.FactoryParameters; 33 import org.objectweb.joram.client.jms.connection.RequestChannel; 34 import org.objectweb.joram.shared.client.AbstractJmsReply; 35 import org.objectweb.joram.shared.client.AbstractJmsRequest; 36 37 import org.objectweb.joram.shared.JoramTracing; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 46 public class TcpConnection implements RequestChannel { 47 48 private ReliableTcpClient tcpClient = null; 49 50 60 public TcpConnection(FactoryParameters params, 61 String name, 62 String password) 63 throws JMSException { 64 this(params, 65 name, 66 password, 67 "org.objectweb.joram.client.jms.tcp.ReliableTcpClient"); 68 } 69 70 81 public TcpConnection(FactoryParameters params, 82 String name, 83 String password, 84 String reliableClass) 85 throws JMSException { 86 87 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 88 JoramTracing.dbgClient.log( 89 BasicLevel.DEBUG, 90 "TcpConnection.<init>(" + params + ',' + 91 name + ',' + password + ',' + reliableClass +')'); 92 93 if (reliableClass == null || 94 reliableClass.equals("") || 95 reliableClass.length() < 1) { 96 reliableClass = "org.objectweb.joram.client.jms.tcp.ReliableTcpClient"; 97 } 98 try { 99 tcpClient = 100 (ReliableTcpClient) Class.forName(reliableClass).newInstance(); 101 } catch (ClassNotFoundException exc) { 102 JMSException jmsExc = 103 new JMSException ("TcpConnection: ClassNotFoundException : " + 104 reliableClass); 105 jmsExc.setLinkedException(exc); 106 throw jmsExc; 107 } catch (InstantiationException exc) { 108 JMSException jmsExc = 109 new JMSException ("TcpConnection: InstantiationException : " + 110 reliableClass); 111 jmsExc.setLinkedException(exc); 112 throw jmsExc; 113 } catch (IllegalAccessException exc) { 114 JMSException jmsExc = 115 new JMSException ("TcpConnection: IllegalAccessException : " + 116 reliableClass); 117 jmsExc.setLinkedException(exc); 118 throw jmsExc; 119 } 120 tcpClient.init(params, 121 name, 122 password, 123 params.cnxPendingTimer > 0); 124 tcpClient.addServerAddress( 125 params.getHost(), 126 params.getPort()); 127 } 128 129 public void setTimer(Timer timer) { 130 tcpClient.setTimer(timer); 131 } 132 133 public void connect() throws Exception { 134 tcpClient.connect(); 135 } 136 137 142 public synchronized void send(AbstractJmsRequest request) 143 throws Exception { 144 tcpClient.send(request); 145 } 146 147 public AbstractJmsReply receive() 148 throws Exception { 149 return (AbstractJmsReply)tcpClient.receive(); 150 } 151 152 153 public void close() { 154 tcpClient.close(); 155 } 156 157 public String toString() { 158 return '(' + super.toString() + 159 ",tcpClient=" + tcpClient + ')'; 160 } 161 } 162 | Popular Tags |