Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

BackendRecoveryPolicy.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.backend;
00026 
00027 import java.io.Serializable;
00028 import java.util.ArrayList;
00029 
00030 import org.objectweb.cjdbc.common.exceptions.ControllerException;
00031 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00032 
00033 /**
00034  * Distributed backend policy for distributed virtual databases (horizontal
00035  * scalability).
00036  * 
00037  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00038  * @version 1.0
00039  */
00040 public class BackendRecoveryPolicy implements Serializable
00041 {
00042   private String    backendName;
00043   private boolean   recoveryPolicy;
00044   private ArrayList controllers;
00045 
00046   /**
00047    * Create a new BackendRecoveryPolicy
00048    * 
00049    * @param backendName backend name
00050    * @param recoveryPolicy true if backends must be recovered
00051    */
00052   public BackendRecoveryPolicy(String backendName, boolean recoveryPolicy)
00053   {
00054     this.backendName = backendName;
00055     this.recoveryPolicy = recoveryPolicy;
00056   }
00057 
00058   /**
00059    * Get the backend name
00060    * 
00061    * @return backend name
00062    */
00063   public String getBackendName()
00064   {
00065     return backendName;
00066   }
00067 
00068   /**
00069    * Get the recoveryPolicy
00070    * 
00071    * @return true if the recovery policy is on, false otherwise.
00072    */
00073   public boolean getRecoveryPolicy()
00074   {
00075     return recoveryPolicy;
00076   }
00077 
00078   /**
00079    * Add a controller name that can recover this backend in case of the failure
00080    * of the current controller.
00081    * 
00082    * @param controllerName name of the controller
00083    * @throws ControllerException if the recovery policy is off
00084    */
00085   public void addController(String controllerName) throws ControllerException
00086   {
00087     if (recoveryPolicy == false)
00088       throw new ControllerException(
00089           "Cannot define controllers when recovery policy is off.");
00090     if (controllers == null)
00091       controllers = new ArrayList();
00092     controllers.add(controllerName);
00093   }
00094 
00095   /**
00096    * Returns whether the given controller name is authorized to recover this
00097    * backend or not.
00098    * 
00099    * @param controllerName controller asking for recovery
00100    * @return true if the controller is eligible
00101    */
00102   public boolean isEligibleForRecovery(String controllerName)
00103   {
00104     if (recoveryPolicy == false)
00105       return false;
00106     if (controllers == null)
00107       return true;
00108     else
00109       return controllers.contains(controllerName);
00110   }
00111 
00112   /**
00113    * Get the XML dump of this BackendRecoveryPolicy element
00114    * 
00115    * @return XML dump of this BackendRecoveryPolicy element
00116    */
00117   public String getXml()
00118   {
00119     String xml = "<" + DatabasesXmlTags.ELT_BackendRecoveryPolicy + " "
00120         + DatabasesXmlTags.ATT_backendName + "=\"" + backendName + "\" "
00121         + DatabasesXmlTags.ATT_recoveryPolicy + "=\""
00122         + (recoveryPolicy ? DatabasesXmlTags.VAL_on : DatabasesXmlTags.VAL_off);
00123     if (controllers != null)
00124     {
00125       xml += ">";
00126       int size = controllers.size();
00127       for (int i = 0; i < size; i++)
00128         xml += "<" + DatabasesXmlTags.ELT_ControllerName + " "
00129             + DatabasesXmlTags.ATT_name + "=\"" + backendName + "\"/>";
00130       xml += "</" + DatabasesXmlTags.ELT_BackendRecoveryPolicy + ">";
00131     }
00132     else
00133       xml += "\"/>";
00134     return xml;
00135   }
00136 
00137 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1