1 21 22 package uk.org.primrose.pool.datasource; 23 24 import uk.org.primrose.pool.jmx.*; 25 import java.io.* ; 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import java.sql.Connection ; 30 import javax.sql.DataSource ; 31 import java.util.*; 32 33 import javax.naming.Context ; 34 import javax.naming.Name ; 35 import javax.naming.Reference ; 36 import javax.naming.spi.ObjectFactory ; 37 38 public class MasterPoolDataSourceFactory implements ObjectFactory , Serializable { 39 static PoolController pc; 40 41 public MasterPoolDataSourceFactory() { 42 } 43 44 public static Queue[] getPoolQueues() { 45 ArrayList al = pc.getQueues(); 46 if (al.size() == 0) return null; 47 48 Queue[] queues = new Queue[al.size()]; 49 for (int i = 0; i < queues.length; i++) { 50 queues[i] = (Queue)al.get(i); 51 } 52 53 return queues; 54 } 55 56 public static void shutdownPools() { 57 pc.stopAllPoolQueues(); 58 pc.destroy(); 59 } 60 61 62 public Object getObjectInstance(Object refObj, Name nm, Context ctx, Hashtable env) throws Exception { 63 64 Reference ref = (Reference ) refObj; 65 String className = ref.getClassName(); 66 67 Object configType = null; 68 if (ref.get("configFile") != null) configType = ref.get("configFile").getContent(); 69 70 Object dataSourceConfigType = null; 71 if (ref.get("dataSourceConfigFile") != null) dataSourceConfigType = ref.get("dataSourceConfigFile").getContent(); 72 73 Object adminConfigFileType = null; 74 if (ref.get("adminConfigFile") != null) adminConfigFileType = ref.get("adminConfigFile").getContent(); 75 if (configType == null && (dataSourceConfigType == null || adminConfigFileType == null)) { 76 System.out.println("[Primrose::MasterPoolDataSourceFactory] ERROR ! Cannot find either 'configFile' or ('dataSourceConfigFile' and 'adminConfigFile') parameters - check you have configured Primrose correctly"); 77 return null; 78 } 79 80 if (configType != null) { 81 dataSourceConfigType = configType; 82 adminConfigFileType = configType; 83 } 84 85 if (configType instanceof String || dataSourceConfigType instanceof String ) { 86 88 pc = new PoolController(); 90 pc.setPoolConfigFile((String )dataSourceConfigType); 91 pc.setAdminDetails((String )adminConfigFileType); 93 pc.init(new String []{}); 95 pc.loadPoolsFromConfigFile((String )dataSourceConfigType, true); 99 Object pools = pc.getQueues(); 101 return pools; 103 } else if (configType instanceof java.util.Properties ) { 104 if (pc == null) { 105 pc = new PoolController(); 107 108 pc.setPoolConfigFile(null); 109 110 116 Properties props = (Properties)configType; 117 118 pc.loadPoolsFromConfigFile(props); 119 121 122 pc.init(new String []{props.getProperty("encryptionKeyFile")}); 123 } else { 125 126 Properties props = (Properties)configType; 127 133 pc.loadPoolsFromConfigFile(props); 135 } 137 138 Object pools = pc.getQueues(); 139 return pools; 141 142 143 } 144 145 return null; 146 } 147 148 149 } 150 | Popular Tags |