KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > jmx > management > BackendInfo


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Nicolas Modrzyk.
21  * Contributor(s): Emmanuel Cecchet.
22  */

23
24 package org.continuent.sequoia.common.jmx.management;
25
26 import java.io.Serializable JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.continuent.sequoia.controller.backend.DatabaseBackend;
32 import org.continuent.sequoia.controller.virtualdatabase.VirtualDatabase;
33
34 /**
35  * This class defines a BackendInfo. We cannot use DatabaseBackend as a
36  * serializable object because it is used as an MBean interface. We use this
37  * class to share configuration information on backends between distributed
38  * virtual database.
39  *
40  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
41  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
42  * @version 1.0
43  */

44 public class BackendInfo implements Serializable JavaDoc
45 {
46   private static final long serialVersionUID = -9143159288188992488L;
47
48   private String JavaDoc name;
49   private String JavaDoc url;
50   private String JavaDoc driverPath;
51   private String JavaDoc driverClassName;
52   private String JavaDoc virtualDatabaseName;
53   private String JavaDoc connectionTestStatement;
54   private int nbOfWorkerThreads;
55   private int dynamicPrecision;
56   /**
57    * gatherSystemTables is now obsolete because it is included in
58    * dynamicPrecision but it is kept for backward compatibility with 2.x
59    * controllers
60    *
61    * @deprecated use dynamic precision instead
62    */

63   private boolean gatherSystemTables = false;
64   private String JavaDoc schemaName;
65   private String JavaDoc xml;
66
67   /**
68    * Creates a new <code>BackendInfo</code> object. Extract configuration
69    * information from the original backend object
70    *
71    * @param backend DatabaseBackend to extract information from
72    */

73   public BackendInfo(DatabaseBackend backend)
74   {
75     this.url = backend.getURL();
76     this.name = backend.getName();
77     this.driverPath = backend.getDriverPath();
78     this.driverClassName = backend.getDriverClassName();
79     this.virtualDatabaseName = backend.getVirtualDatabaseName();
80     this.connectionTestStatement = backend.getConnectionTestStatement();
81     this.nbOfWorkerThreads = backend.getNbOfWorkerThreads();
82     this.dynamicPrecision = backend.getDynamicPrecision();
83     this.schemaName = backend.getSchemaName();
84     this.xml = backend.getXml();
85   }
86
87   /**
88    * Create a corresponding DatabaseBackend object from the information stored
89    * in this object.
90    *
91    * @param vdb the virtual database this backend will belong to
92    * @return a <code>DatabaseBackend</code>
93    */

94   public DatabaseBackend getDatabaseBackend(VirtualDatabase vdb)
95   {
96     return new DatabaseBackend(vdb, name, driverPath, driverClassName, url,
97         true, connectionTestStatement, nbOfWorkerThreads);
98   }
99
100   /**
101    * Returns the xml value.
102    *
103    * @return Returns the xml.
104    */

105   public String JavaDoc getXml()
106   {
107     return xml;
108   }
109
110   /**
111    * Returns the connectionTestStatement value.
112    *
113    * @return Returns the connectionTestStatement.
114    */

115   public String JavaDoc getConnectionTestStatement()
116   {
117     return connectionTestStatement;
118   }
119
120   /**
121    * Returns the driverClassName value.
122    *
123    * @return Returns the driverClassName.
124    */

125   public String JavaDoc getDriverClassName()
126   {
127     return driverClassName;
128   }
129
130   /**
131    * Returns the driverPath value.
132    *
133    * @return Returns the driverPath.
134    */

135   public String JavaDoc getDriverPath()
136   {
137     return driverPath;
138   }
139
140   /**
141    * Returns the dynamicPrecision value.
142    *
143    * @return Returns the dynamicPrecision.
144    */

145   public int getDynamicPrecision()
146   {
147     return dynamicPrecision;
148   }
149
150   /**
151    * Returns the name value.
152    *
153    * @return Returns the name.
154    */

155   public String JavaDoc getName()
156   {
157     return name;
158   }
159
160   /**
161    * Returns the nbOfWorkerThreads value.
162    *
163    * @return Returns the nbOfWorkerThreads.
164    */

165   public final int getNbOfWorkerThreads()
166   {
167     return nbOfWorkerThreads;
168   }
169
170   /**
171    * Returns the schemaName value.
172    *
173    * @return Returns the schemaName.
174    */

175   public String JavaDoc getSchemaName()
176   {
177     return schemaName;
178   }
179
180   /**
181    * Returns the url value.
182    *
183    * @return Returns the url.
184    */

185   public String JavaDoc getUrl()
186   {
187     return url;
188   }
189
190   /**
191    * Returns the virtualDatabaseName value.
192    *
193    * @return Returns the virtualDatabaseName.
194    */

195   public String JavaDoc getVirtualDatabaseName()
196   {
197     return virtualDatabaseName;
198   }
199
200   /**
201    * Set the xml information on that BackendInfo object
202    *
203    * @param xml new XML to set
204    */

205   public void setXml(String JavaDoc xml)
206   {
207     this.xml = null;
208   }
209   
210   /**
211    * for debug only.
212    *
213    * @see java.lang.Object#toString()
214    */

215   public String JavaDoc toString()
216   {
217     StringBuffer JavaDoc buff = new StringBuffer JavaDoc("BackendInfo[");
218     buff.append("name=").append(name);
219     buff.append(", virtualDatabaseName").append(virtualDatabaseName);
220     buff.append(", url=").append(url);
221     buff.append("]");
222     return buff.toString();
223   }
224
225   /**
226    * Convert a <code>List&lt;BackendInfo&gt;</code> to a
227    * <code>List&lt;DatabaseBackend&gt;</code>.
228    * <em>The DatabaseBackends returned by this method does
229    * to reflect the state of the backends in the cluster. To
230    * get the "real" DatabaseBackends, use
231    * {@link org.continuent.sequoia.controller.virtualdatabase.VirtualDatabase#getAndCheckBackend(String, int)}.</em>
232    *
233    * @param vdb the virtual database the backends will belong to
234    * @param backendInfos a <code>List</code> of <code>BackendInfo</code>
235    * @return a <code>List</code> of <code>DatabaseBackend</code> (possibly
236    * empty if the list of backendInfos was <code>null</code>
237    * @see DatabaseBackend#toBackendInfos(List)
238    */

239   public static List JavaDoc /* <DatabaseBackend> */toDatabaseBackends(
240       VirtualDatabase vdb, List JavaDoc /* <BackendInfo> */backendInfos)
241   {
242     if (backendInfos == null)
243     {
244       return new ArrayList JavaDoc();
245     }
246     // Convert BackendInfo arraylist to real DatabaseBackend objects
247
List JavaDoc backends = new ArrayList JavaDoc(backendInfos.size());
248     for (Iterator JavaDoc iter = backendInfos.iterator(); iter.hasNext();)
249     {
250       BackendInfo info = (BackendInfo) iter.next();
251       backends.add(info.getDatabaseBackend(vdb));
252     }
253     return backends;
254   }
255
256 }
Popular Tags