001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (c) 2004-2007 Paul Ferraro
004 * 
005 * This library is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Lesser General Public License as published by the 
007 * Free Software Foundation; either version 2.1 of the License, or (at your 
008 * option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this library; if not, write to the Free Software Foundation, 
017 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018 * 
019 * Contact: ferraro@users.sourceforge.net
020 */
021package net.sf.hajdbc;
022
023import java.net.URL;
024import java.util.Set;
025
026/**
027 * @author  Paul Ferraro
028 * @version $Revision: 2038 $
029 * @since   1.0
030 */
031public interface DatabaseClusterMBean
032{
033        /**
034         * Determines whether or not the specified database is responsive
035         * @param databaseId a database identifier
036         * @return true, if the database is alive, false otherwise
037         * @throws IllegalArgumentException if no database exists with the specified identifier.
038         */
039        public boolean isAlive(String databaseId);
040        
041        /**
042         * Deactivates the specified database.
043         * @param databaseId a database identifier
044         * @throws IllegalArgumentException if no database exists with the specified identifier.
045         * @throws IllegalStateException if mbean could not be re-registered using inactive database interface.
046         */
047        public void deactivate(String databaseId);
048
049        /**
050         * Synchronizes, using the default strategy, and reactivates the specified database.
051         * @param databaseId a database identifier
052         * @throws IllegalArgumentException if no database exists with the specified identifier.
053         * @throws IllegalStateException if synchronization fails, or if mbean could not be re-registered using active database interface.
054         */
055        public void activate(String databaseId);
056
057        /**
058         * Synchronizes, using the specified strategy, and reactivates the specified database.
059         * @param databaseId a database identifier
060         * @param syncId the class name of a synchronization strategy
061         * @throws IllegalArgumentException if no database exists with the specified identifier, or no synchronization strategy exists with the specified identifier.
062         * @throws IllegalStateException if synchronization fails, or if mbean could not be re-registered using active database interface.
063         */
064        public void activate(String databaseId, String syncId);
065        
066        /**
067         * Returns a collection of active databases in this cluster.
068         * @return a list of database identifiers
069         */
070        public Set<String> getActiveDatabases();
071        
072        /**
073         * Returns a collection of inactive databases in this cluster.
074         * @return a collection of database identifiers
075         */
076        public Set<String> getInactiveDatabases();
077        
078        /**
079         * Return the current HA-JDBC version
080         * @return the current version
081         */
082        public String getVersion();
083        
084        /**
085         * Removes the specified database/DataSource from the cluster.
086         * @param databaseId a database identifier
087         * @throws IllegalStateException if database is still active, or if mbean unregistration fails.
088         */
089        public void remove(String databaseId);
090        
091        /**
092         * Flushes this cluster's cache of DatabaseMetaData.
093         */
094        public void flushMetaDataCache();
095        
096        /**
097         * Returns the set of synchronization strategies available to this cluster.
098         * @return a set of synchronization strategy identifiers
099         */
100        public Set<String> getSynchronizationStrategies();
101        
102        /**
103         * Returns the default synchronization strategy used by this cluster.
104         * @return a synchronization strategy identifier
105         */
106        public String getDefaultSynchronizationStrategy();
107        
108        /**
109         * Returns the URL of the configuration file for this cluster.
110         * @return a URL
111         */
112        public URL getUrl();
113        
114        /**
115         * Provided so that mbean proxies will use mbean toString() implementation
116         * @return string representation of this cluster
117         */
118        public String toString();
119        
120        public void addActivationListener(DatabaseActivationListener listener);
121        
122        public void removeActivationListener(DatabaseActivationListener listener);
123        
124        public void addDeactivationListener(DatabaseDeactivationListener listener);
125        
126        public void removeDeactivationListener(DatabaseDeactivationListener listener);
127        
128        public void addSynchronizationListener(SynchronizationListener listener);
129        
130        public void removeSynchronizationListener(SynchronizationListener listener);
131}