1 24 package org.objectweb.joram.client.jms.ha.tcp; 25 26 import java.io.*; 27 import java.util.*; 28 29 import javax.jms.JMSException ; 30 31 import org.objectweb.joram.client.jms.*; 32 import org.objectweb.joram.client.jms.tcp.*; 33 import org.objectweb.joram.shared.client.*; 34 import org.objectweb.joram.client.jms.connection.RequestChannel; 35 36 import org.objectweb.util.monolog.api.BasicLevel; 37 38 public class HATcpConnection 39 implements RequestChannel { 40 41 private ReliableTcpClient tcpClient; 42 43 53 public HATcpConnection(String url, 54 FactoryParameters params, 55 String name, 56 String password) 57 throws JMSException { 58 this(url, 59 params, 60 name, 61 password, 62 "org.objectweb.joram.client.jms.tcp.ReliableTcpClient"); 63 } 64 65 76 public HATcpConnection(String url, 77 FactoryParameters params, 78 String name, 79 String password, 80 String reliableClass) 81 throws JMSException { 82 try { 83 tcpClient = 84 (ReliableTcpClient) Class.forName(reliableClass).newInstance(); 85 } catch (ClassNotFoundException exc) { 86 JMSException jmsExc = 87 new JMSException ("HATcpConnection: ClassNotFoundException : " + 88 reliableClass); 89 jmsExc.setLinkedException(exc); 90 throw jmsExc; 91 } catch (InstantiationException exc) { 92 JMSException jmsExc = 93 new JMSException ("HATcpConnection: InstantiationException : " + 94 reliableClass); 95 jmsExc.setLinkedException(exc); 96 throw jmsExc; 97 } catch (IllegalAccessException exc) { 98 JMSException jmsExc = 99 new JMSException ("HATcpConnection: IllegalAccessException : " + 100 reliableClass); 101 jmsExc.setLinkedException(exc); 102 throw jmsExc; 103 } 104 tcpClient.init(params, 105 name, 106 password, 107 true); 108 StringTokenizer tokenizer = new StringTokenizer(url, "/:,"); 109 if (! tokenizer.hasMoreElements()) 110 throw new javax.jms.JMSException ("URL not valid:" + url); 111 String protocol = tokenizer.nextToken(); 112 if (protocol.equals("hajoram")) { 113 while (tokenizer.hasMoreElements()) { 114 tcpClient.addServerAddress( 115 tokenizer.nextToken(), 116 Integer.parseInt(tokenizer.nextToken())); 117 } 118 } else { 119 throw new javax.jms.JMSException ("Unknown protocol:" + protocol); 120 } 121 } 122 123 public void setTimer(Timer timer) { 124 tcpClient.setTimer(timer); 125 } 126 127 public void connect() throws Exception { 128 tcpClient.connect(); 129 } 130 131 134 public void send(AbstractJmsRequest request) 135 throws Exception { 136 tcpClient.send(request); 137 } 138 139 public AbstractJmsReply receive() 140 throws Exception { 141 return (AbstractJmsReply)tcpClient.receive(); 142 } 143 144 145 public void close() { 146 tcpClient.close(); 147 } 148 149 } 150 | Popular Tags |