1 25 package org.objectweb.joram.client.connector; 26 27 import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory; 28 import org.objectweb.joram.client.jms.tcp.QueueTcpConnectionFactory; 29 import org.objectweb.joram.client.jms.tcp.TopicTcpConnectionFactory; 30 31 import javax.jms.ConnectionFactory ; 32 import javax.jms.IllegalStateException ; 33 import javax.jms.JMSException ; 34 import javax.jms.JMSSecurityException ; 35 import javax.jms.QueueConnectionFactory ; 36 import javax.jms.TopicConnectionFactory ; 37 import javax.resource.ResourceException ; 38 import javax.resource.spi.CommException ; 39 import javax.resource.spi.ConnectionRequestInfo ; 40 import javax.resource.spi.ManagedConnectionFactory ; 41 import javax.resource.spi.SecurityException ; 42 43 import org.objectweb.util.monolog.api.BasicLevel; 44 45 50 public class DefaultConnectionManager 51 implements javax.resource.spi.ConnectionManager , 52 java.io.Serializable 53 { 54 58 private static DefaultConnectionManager ref = null; 59 60 61 64 public DefaultConnectionManager() 65 {} 66 67 68 76 public Object allocateConnection(ManagedConnectionFactory mcf, 77 ConnectionRequestInfo cxRequest) 78 throws ResourceException { 79 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 80 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 81 this + " allocateConnection(" + mcf + "," + cxRequest + ")"); 82 83 String userName; 84 String password; 85 86 if (cxRequest == null) { 87 userName = ((ManagedConnectionFactoryImpl) mcf).getUserName(); 88 password = ((ManagedConnectionFactoryImpl) mcf).getPassword(); 89 } else { 90 userName = ((ConnectionRequest) cxRequest).getUserName(); 91 password = ((ConnectionRequest) cxRequest).getPassword(); 92 } 93 94 String hostName = ((ManagedConnectionFactoryImpl) mcf).getHostName(); 95 int serverPort = 96 ((ManagedConnectionFactoryImpl) mcf).getServerPort().intValue(); 97 98 try { 99 if (cxRequest instanceof QueueConnectionRequest) { 100 QueueConnectionFactory factory = 101 QueueTcpConnectionFactory.create(hostName, serverPort); 102 setFactoryParameters((org.objectweb.joram.client.jms.ConnectionFactory) factory, 103 (ManagedConnectionFactoryImpl) mcf); 104 return factory.createQueueConnection(userName, password); 105 } else if (cxRequest instanceof TopicConnectionRequest) { 106 TopicConnectionFactory factory = 107 TopicTcpConnectionFactory.create(hostName, serverPort); 108 setFactoryParameters((org.objectweb.joram.client.jms.ConnectionFactory) factory, 109 (ManagedConnectionFactoryImpl) mcf); 110 return factory.createTopicConnection(userName, password); 111 } else { 112 ConnectionFactory factory = 113 TcpConnectionFactory.create(hostName, serverPort); 114 setFactoryParameters((org.objectweb.joram.client.jms.ConnectionFactory) factory, 115 (ManagedConnectionFactoryImpl) mcf); 116 return factory.createConnection(userName, password); 117 } 118 } catch (IllegalStateException exc) { 119 throw new CommException ("Could not access the JORAM server: " + exc); 120 } catch (JMSSecurityException exc) { 121 throw new SecurityException ("Invalid user identification: " + exc); 122 } catch (JMSException exc) { 123 throw new ResourceException ("Failed connecting process: " + exc); 124 } 125 } 126 127 private void setFactoryParameters(org.objectweb.joram.client.jms.ConnectionFactory factory , 128 ManagedConnectionFactoryImpl mcf) { 129 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 130 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 131 this + " setFactoryParameters(" + factory + "," + mcf + ")"); 132 factory.getParameters().connectingTimer = mcf.getConnectingTimer(); 133 factory.getParameters().cnxPendingTimer = mcf.getCnxPendingTimer(); 134 factory.getParameters().txPendingTimer = mcf.getTxPendingTimer(); 135 } 136 137 141 static DefaultConnectionManager getRef() 142 { 143 if (ref == null) 144 ref = new DefaultConnectionManager(); 145 146 return ref; 147 } 148 } 149 | Popular Tags |