001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Nicolas Modrzyk.
021: * Contributor(s): Emmanuel Cecchet.
022: */package org.continuent.sequoia.common.jmx.management;
023:
024: import java.io.Serializable;
025: import java.util.ArrayList;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: import org.continuent.sequoia.controller.backend.DatabaseBackend;
030:
031: /**
032: * This class defines a BackendInfo. We cannot use DatabaseBackend as a
033: * serializable object because it is used as an MBean interface. We use this
034: * class to share configuration information on backends between distributed
035: * virtual database.
036: *
037: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
038: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
039: * @version 1.0
040: */
041: public class BackendInfo implements Serializable {
042: private static final long serialVersionUID = -9143159288188992488L;
043:
044: private String name;
045: private String url;
046: private String driverPath;
047: private String driverClassName;
048: private String virtualDatabaseName;
049: private String connectionTestStatement;
050: private int nbOfWorkerThreads;
051: private int dynamicPrecision;
052: private boolean gatherSystemTables = false;
053: private String schemaName;
054: private String xml;
055:
056: /**
057: * Creates a new <code>BackendInfo</code> object. Extract configuration
058: * information from the original backend object
059: *
060: * @param backend DatabaseBackend to extract information from
061: */
062: public BackendInfo(DatabaseBackend backend) {
063: this .url = backend.getURL();
064: this .name = backend.getName();
065: this .driverPath = backend.getDriverPath();
066: this .driverClassName = backend.getDriverClassName();
067: this .virtualDatabaseName = backend.getVirtualDatabaseName();
068: this .connectionTestStatement = backend
069: .getConnectionTestStatement();
070: this .nbOfWorkerThreads = backend.getNbOfWorkerThreads();
071: this .dynamicPrecision = backend.getDynamicPrecision();
072: this .gatherSystemTables = backend.isGatherSystemTables();
073: this .schemaName = backend.getSchemaName();
074: this .xml = backend.getXml();
075: }
076:
077: /**
078: * Create a corresponding DatabaseBackend object from the information stored
079: * in this object.
080: *
081: * @return a <code>DatabaseBackend</code>
082: */
083: public DatabaseBackend getDatabaseBackend() {
084: return new DatabaseBackend(name, driverPath, driverClassName,
085: url, virtualDatabaseName, true,
086: connectionTestStatement, nbOfWorkerThreads);
087: }
088:
089: /**
090: * Returns the xml value.
091: *
092: * @return Returns the xml.
093: */
094: public String getXml() {
095: return xml;
096: }
097:
098: /**
099: * Returns the connectionTestStatement value.
100: *
101: * @return Returns the connectionTestStatement.
102: */
103: public String getConnectionTestStatement() {
104: return connectionTestStatement;
105: }
106:
107: /**
108: * Returns the driverClassName value.
109: *
110: * @return Returns the driverClassName.
111: */
112: public String getDriverClassName() {
113: return driverClassName;
114: }
115:
116: /**
117: * Returns the driverPath value.
118: *
119: * @return Returns the driverPath.
120: */
121: public String getDriverPath() {
122: return driverPath;
123: }
124:
125: /**
126: * Returns the dynamicPrecision value.
127: *
128: * @return Returns the dynamicPrecision.
129: */
130: public int getDynamicPrecision() {
131: return dynamicPrecision;
132: }
133:
134: /**
135: * Returns the name value.
136: *
137: * @return Returns the name.
138: */
139: public String getName() {
140: return name;
141: }
142:
143: /**
144: * Returns the nbOfWorkerThreads value.
145: *
146: * @return Returns the nbOfWorkerThreads.
147: */
148: public final int getNbOfWorkerThreads() {
149: return nbOfWorkerThreads;
150: }
151:
152: /**
153: * Returns the schemaName value.
154: *
155: * @return Returns the schemaName.
156: */
157: public String getSchemaName() {
158: return schemaName;
159: }
160:
161: /**
162: * Returns the url value.
163: *
164: * @return Returns the url.
165: */
166: public String getUrl() {
167: return url;
168: }
169:
170: /**
171: * Returns the virtualDatabaseName value.
172: *
173: * @return Returns the virtualDatabaseName.
174: */
175: public String getVirtualDatabaseName() {
176: return virtualDatabaseName;
177: }
178:
179: /**
180: * Returns the gatherSystemTables value.
181: *
182: * @return Returns the gatherSystemTables.
183: */
184: public boolean isGatherSystemTables() {
185: return gatherSystemTables;
186: }
187:
188: /**
189: * Set the xml information on that BackendInfo object
190: *
191: * @param xml new XML to set
192: */
193: public void setXml(String xml) {
194: this .xml = null;
195: }
196:
197: /**
198: * Convert a <code>List<BackendInfo></code> to a
199: * <code>List<DatabaseBackend></code>.
200: * <em>The DatabaseBackends returned by this method does
201: * to reflect the state of the backends in the cluster. To
202: * get the "real" DatabaseBackends, use
203: * {@link org.continuent.sequoia.controller.virtualdatabase.VirtualDatabase#getAndCheckBackend(String, int)}.</em>
204: *
205: * @param backendInfos a <code>List</code> of <code>BackendInfo</code>
206: * @return a <code>List</code> of <code>DatabaseBackend</code> (possibly
207: * empty if the list of backendInfos was <code>null</code>
208: * @see DatabaseBackend#toBackendInfos(List)
209: */
210: public static List /*<DatabaseBackend>*/toDatabaseBackends(
211: List /*<BackendInfo>*/backendInfos) {
212: if (backendInfos == null) {
213: return new ArrayList();
214: }
215: // Convert BackendInfo arraylist to real DatabaseBackend objects
216: List backends = new ArrayList(backendInfos.size());
217: for (Iterator iter = backendInfos.iterator(); iter.hasNext();) {
218: BackendInfo info = (BackendInfo) iter.next();
219: backends.add(info.getDatabaseBackend());
220: }
221: return backends;
222: }
223:
224: }
|