KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > virtualdatabase > protocol > VirtualDatabaseConfiguration


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.controller.virtualdatabase.protocol;
26
27 import java.io.Serializable JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.objectweb.cjdbc.common.i18n.Translate;
32 import org.objectweb.cjdbc.common.jmx.JmxConstants;
33 import org.objectweb.cjdbc.common.shared.BackendInfo;
34 import org.objectweb.cjdbc.controller.jmx.RmiConnector;
35 import org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase;
36
37 /**
38  * Transports the configuration of a virtual database to remote controllers so
39  * that compatibility checking can be performed.
40  *
41  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
42  * @version 1.0
43  */

44 public class VirtualDatabaseConfiguration implements Serializable JavaDoc
45 {
46   private static final long serialVersionUID = -4753828540599620782L;
47
48   private String JavaDoc controllerName;
49   private String JavaDoc controllerJmxName;
50   private String JavaDoc vdbName;
51   private String JavaDoc groupName = null;
52   private ArrayList JavaDoc vLogins;
53   private int schedulerRAIDbLevel;
54   private int loadBalancerRAIDbLevel;
55   private ArrayList JavaDoc backends;
56
57   // Jmx Information
58
private String JavaDoc rmiHostname;
59   private String JavaDoc rmiPort;
60
61   /**
62    * @return Returns the controllerName.
63    */

64   public String JavaDoc getControllerName()
65   {
66     return controllerName;
67   }
68
69   /**
70    * Returns the controllerJmxName value.
71    *
72    * @return Returns the controllerJmxName.
73    */

74   public String JavaDoc getControllerJmxName()
75   {
76     return controllerJmxName;
77   }
78
79   /**
80    * Constructs a new <code>VirtualDatabaseConfiguration</code> object from a
81    * <code>DistributedVirtualDatabase</code>.
82    *
83    * @param dvdb The distributed virtual database to get configuration from.
84    */

85   public VirtualDatabaseConfiguration(DistributedVirtualDatabase dvdb)
86   {
87     this.controllerName = dvdb.getControllerName();
88     this.controllerJmxName = dvdb.viewOwningController();
89     this.vdbName = dvdb.getVirtualDatabaseName();
90     this.groupName = dvdb.getGroupName();
91     this.vLogins = dvdb.getAuthenticationManager().getVirtualLogins();
92     this.schedulerRAIDbLevel = dvdb.getRequestManager().getScheduler()
93         .getRAIDbLevel();
94     this.loadBalancerRAIDbLevel = dvdb.getRequestManager().getLoadBalancer()
95         .getRAIDbLevel();
96     this.backends = dvdb.getBackendsInfo(dvdb.getBackends());
97
98     List JavaDoc connectors = RmiConnector.getRmiConnectors();
99     if (connectors.size() > 0)
100     {
101       RmiConnector rmi = (RmiConnector) connectors.get(0);
102       rmiHostname = rmi.getHostName();
103       rmiPort = String.valueOf(rmi.getPort());
104     }
105     else
106     {
107       rmiHostname = controllerName.substring(0, controllerName.indexOf(":"));
108       rmiPort = String.valueOf(JmxConstants.DEFAULT_JMX_RMI_PORT);
109     }
110   }
111
112   /**
113    * @return Returns the rmiHostname.
114    */

115   public String JavaDoc getRmiHostname()
116   {
117     return rmiHostname;
118   }
119
120   /**
121    * @return Returns the rmiPort.
122    */

123   public String JavaDoc getRmiPort()
124   {
125     return rmiPort;
126   }
127
128   /**
129    * Check if the local distributed virtual database is compatible with this
130    * virtual database configuration.
131    *
132    * @param localDvdb The local distributed virtual database
133    * @return true if both configurations are compatible, false otherwise
134    */

135   public boolean isCompatible(DistributedVirtualDatabase localDvdb)
136   {
137     try
138     {
139       if (controllerName.equals(localDvdb.getControllerName()))
140       {
141         localDvdb.logger
142             .warn(Translate
143                 .get("virtualdatabase.distributed.configuration.checking.duplicate.controller.name"));
144         return false;
145       }
146
147       // Sanity checks for virtual database name and group name
148
if (!vdbName.equals(localDvdb.getVirtualDatabaseName()))
149       {
150         localDvdb.logger
151             .warn(Translate
152                 .get("virtualdatabase.distributed.configuration.checking.mismatch.name"));
153         return false;
154       }
155       if (!groupName.equals(localDvdb.getGroupName()))
156       {
157         localDvdb.logger
158             .warn(Translate
159                 .get("virtualdatabase.distributed.configuration.checking.mismatch.groupname"));
160         return false;
161       }
162
163       // Authentication managers must contains the same set of elements but
164
// possibly in different orders (equals require the element to be in the
165
// same order).
166
if (!vLogins.containsAll(localDvdb.getAuthenticationManager()
167           .getVirtualLogins())
168           || !localDvdb.getAuthenticationManager().getVirtualLogins()
169               .containsAll(vLogins))
170       {
171         localDvdb.logger
172             .warn(Translate
173                 .get("virtualdatabase.distributed.configuration.checking.mismatch.vlogins"));
174         return false;
175       }
176
177       // Scheduler and Load Balancer checking
178
if (schedulerRAIDbLevel != localDvdb.getRequestManager().getScheduler()
179           .getRAIDbLevel())
180       {
181         localDvdb.logger
182             .warn(Translate
183                 .get("virtualdatabase.distributed.configuration.checking.mismatch.scheduler"));
184         return false;
185       }
186
187       if (loadBalancerRAIDbLevel != localDvdb.getRequestManager()
188           .getLoadBalancer().getRAIDbLevel())
189       {
190         localDvdb.logger
191             .warn(Translate
192                 .get("virtualdatabase.distributed.configuration.checking.mismatch.loadbalancer"));
193         return false;
194       }
195
196       // Checking backends
197
int size = backends.size();
198       for (int i = 0; i < size; i++)
199       {
200         BackendInfo b = (BackendInfo) backends.get(i);
201         if (!localDvdb.isCompatibleBackend(b))
202         {
203           localDvdb.logger
204               .warn(Translate
205                   .get(
206                       "virtualdatabase.distributed.configuration.checking.mismatch.backend.shared",
207                       b.getName()));
208           return false;
209         }
210       }
211
212       // Ok, all tests succeeded, configuration is compatible
213
return true;
214     }
215     catch (Exception JavaDoc e)
216     {
217       localDvdb.logger.error(Translate
218           .get("virtualdatabase.distributed.configuration.checking.error"), e);
219       return false;
220     }
221   }
222
223 }
Popular Tags