1 22 package org.jboss.mq; 23 24 import java.io.Serializable ; 25 import java.util.Properties ; 26 27 import javax.jms.JMSException ; 28 29 import org.jboss.logging.Logger; 30 import org.jboss.mq.il.ClientILService; 31 import org.jboss.mq.il.ServerIL; 32 import org.jboss.mq.il.ServerILFactory; 33 34 41 public class GenericConnectionFactory implements Serializable 42 { 43 45 46 private static final long serialVersionUID = 2288420610006129296L; 47 48 49 static Logger log = Logger.getLogger(GenericConnectionFactory.class); 50 51 53 56 private ServerIL server; 57 58 61 private Properties connectionProperties; 62 63 65 67 79 public GenericConnectionFactory(ServerIL server, Properties props) 80 { 81 this.server = server; 82 this.connectionProperties = props; 83 } 84 85 87 90 public Properties getProperties() 91 { 92 return connectionProperties; 93 } 94 95 100 public void initialise(Connection connection) throws JMSException 101 { 102 String clientID = connectionProperties.getProperty(ServerILFactory.CLIENTID); 103 if (clientID != null) 104 connection.clientID = clientID; 105 } 106 107 114 public ClientILService createClientILService(Connection connection) throws Exception 115 { 116 String pingPeriod = connectionProperties.getProperty(ServerILFactory.PING_PERIOD_KEY, "" + connection.pingPeriod); 118 connection.pingPeriod = Long.parseLong(pingPeriod); 119 120 String clientILServiceCN = connectionProperties.getProperty(ServerILFactory.CLIENT_IL_SERVICE_KEY); 122 ClientILService service = (ClientILService) Class.forName(clientILServiceCN).newInstance(); 123 service.init(connection, connectionProperties); 124 125 if (log.isTraceEnabled()) 126 log.trace("Handing out ClientIL: " + clientILServiceCN); 127 128 return service; 129 } 130 131 137 public ServerIL createServerIL() throws JMSException 138 { 139 try 140 { 141 if (server == null) 144 { 145 String className = connectionProperties.getProperty(ServerILFactory.SERVER_IL_FACTORY_KEY); 146 ServerILFactory factory = (ServerILFactory) Class.forName(className).newInstance(); 147 factory.init(connectionProperties); 148 149 server = factory.getServerIL(); 150 } 151 152 return server.cloneServerIL(); 155 } 156 catch (Exception e) 157 { 158 throw new SpyJMSException("Could not connect to the server", e); 159 } 160 } 161 162 164 public String toString() 165 { 166 return "GenericConnectionFactory[server=" + server + " connectionProperties=" + connectionProperties + "]"; 167 } 168 169 171 173 175 } | Popular Tags |