View Javadoc
1 /*** 2 * Copyright (c) 2002, Reuters America Inc. All rights reserved.<p> 3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following 4 * conditions are met:<p> 5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 7 * in the documentation and/or other materials provided with the distribution. Neither the name of Reuters America Inc. nor the 8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written 9 * permission.<p> 10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p> 16 */ 17 18 package com.reuters.rc.db; 19 20 import com.tibco.tibrv.*; 21 22 /*** 23 * DbManager is the starting point for the application clients that wishes 24 * to access an ADB-like agent through the intefaces in this package. 25 * Clients can set/get their choice of DbFactory implementations by using 26 * the static methods in this class. 27 * 28 * DbManager also provides static methods to set/get the default rv transport, 29 * rv queue and the timeout values. 30 * 31 * @author Jawaid Hakim 32 * @author Cavit Aydin 33 * @see DbFactory 34 */ 35 public class DbManager 36 { 37 /*** 38 * Ctor. 39 */ 40 private DbManager() 41 { 42 } 43 44 /*** 45 * Set up a default TibrvTransport/TibrvQueue. 46 * @param rvTrans Default TibrvTransport. 47 * @param rvQueue Default TibrvQueue. 48 * @param defaultTimeout Default timeout in seconds for requests. 49 * @see #getDefaultTransport() 50 * @see #getDefaultQueue() 51 */ 52 public static final synchronized void setDefault(TibrvTransport rvTrans, TibrvQueue rvQueue, double defaultTimeout) throws DbBusinessException, DbSystemException 53 { 54 setDefault(rvTrans, rvQueue); 55 DEFAULT_TIMEOUT = defaultTimeout; 56 } 57 58 59 /*** 60 * Set up a default TibrvTransport/TibrvQueue. 61 * @param rvTrans Default TibrvTransport. 62 * @param rvQueue Default TibrvQueue. 63 * @see #getDefaultTransport() 64 * @see #getDefaultQueue() 65 */ 66 public static final synchronized void setDefault(TibrvTransport rvTrans, TibrvQueue rvQueue) throws DbBusinessException, DbSystemException 67 { 68 setDefault(rvTrans); 69 setDefault(rvQueue); 70 } 71 72 /*** 73 * Set up a default TibrvTransport. 74 * @param rvTrans Default TibrvTransport. 75 * @see #getDefaultTransport() 76 */ 77 public static final synchronized void setDefault(TibrvTransport rvTrans) throws DbBusinessException 78 { 79 if (rvTrans == null) 80 throw new DbBusinessException("NULL transport"); 81 82 rvTrans_ = rvTrans; 83 } 84 85 /*** 86 * Set up a default TibrvQueue. 87 * @param rvQueue Default TibrvQueue. 88 * @see #getDefaultQueue() 89 */ 90 public static final synchronized void setDefault(TibrvQueue rvQueue) throws DbBusinessException 91 { 92 if (rvQueue == null) 93 throw new DbBusinessException("NULL queue"); 94 95 rvQueue_ = rvQueue; 96 } 97 98 /*** 99 * Set up a default request timeout. 100 * @param timeout Default request timeout. 101 * @see #getDefaultTimeout() 102 */ 103 public static final synchronized void setDefault(double timeout) throws DbBusinessException 104 { 105 if (timeout <= 0.0) 106 throw new DbBusinessException("Invalid timeout : " + timeout); 107 108 DEFAULT_TIMEOUT = timeout; 109 } 110 111 /*** 112 * Get the default TibrvTransport. 113 * @return Default TibrvTransport. Returns <code>null</code> if no default 114 * transport has been set up. 115 * @see #setDefault(TibrvTransport) 116 */ 117 public static final synchronized TibrvTransport getDefaultTransport() 118 { 119 return rvTrans_; 120 } 121 122 /*** 123 * Get the default TibrvQueue. 124 * @return Default TibrvQueue. Returns <code>null</code> if no default 125 * queue has been set up. 126 * @see #setDefault(TibrvQueue) 127 */ 128 public static final synchronized TibrvQueue getDefaultQueue() 129 { 130 return rvQueue_; 131 } 132 133 /*** 134 * Get the default request timeout. 135 * @return Default request timeout. 136 */ 137 public static final synchronized double getDefaultTimeout() 138 { 139 return DEFAULT_TIMEOUT; 140 } 141 142 /*** 143 * Set the factory instance. 144 * @param pFactory Factory instance 145 */ 146 public static final void setFactory(DbFactory pFactory) throws DbBusinessException 147 { 148 if (pFactory == null) 149 throw new DbBusinessException("NULL factory"); 150 151 dbFactory_ = pFactory; 152 } 153 154 /*** 155 * Set the factory instance. 156 * 157 * @param pFactoryClassName The name of the factory class. 158 * @throws DbException 159 */ 160 public static final void setFactory(String pFactoryClassName) throws DbBusinessException, DbSystemException 161 { 162 try 163 { 164 if (pFactoryClassName == null) 165 throw new DbBusinessException("NULL factory name"); 166 167 dbFactory_ = (DbFactory) Class.forName(pFactoryClassName).newInstance(); 168 } 169 catch (ClassNotFoundException cnfe) 170 { 171 throw new DbSystemException(cnfe); 172 } 173 catch (IllegalAccessException iae) 174 { 175 throw new DbSystemException(iae); 176 } 177 catch (InstantiationException ie) 178 { 179 throw new DbSystemException(ie); 180 } 181 } 182 183 /*** 184 * Get the instance of the factory. 185 * 186 * @return the factory class instance 187 */ 188 public static final DbFactory getFactory() throws DbBusinessException 189 { 190 if (dbFactory_ == null) 191 throw new DbBusinessException("NULL factory"); 192 193 return dbFactory_; 194 } 195 196 197 private static DbFactory dbFactory_; 198 199 200 /*** 201 * Default TibrvTransport. 202 */ 203 protected static TibrvTransport rvTrans_; 204 205 /*** 206 * Default TibrvQueue. 207 */ 208 protected static TibrvQueue rvQueue_; 209 210 211 /*** 212 * Default timeout in seconds. 213 * TODO: read from a config file. 214 */ 215 protected static double DEFAULT_TIMEOUT = 60; 216 }

This page was automatically generated by Maven