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.util.Set;
024
025/**
026 * @author  Paul Ferraro
027 * @since   1.0
028 * @param <D> either java.sql.Driver or javax.sql.DataSource
029 */
030public interface Balancer<D>
031{
032        /**
033         * Removes the specified database from this balancer.
034         * @param database a database descriptor
035         * @return true, if the database was removed successfully, false if it did not exist.
036         */
037        public boolean remove(Database<D> database);
038
039        /**
040         * Adds the specified database to this balancer.
041         * @param database a database descriptor
042         * @return true, if the database was added successfully, false if already existed.
043         */
044        public boolean add(Database<D> database);
045
046        /**
047         * Returns the next database from this balancer
048         * @return the next database from this balancer
049         */
050        public Database<D> next();
051
052        /**
053         * Returns an unmodifiable collection of databases known to this balancer
054         * @return a collection of database descriptors
055         */
056        public Set<Database<D>> all();
057        
058        /**
059         * Called before an operation is performed on the specified database retrieved via {@link #next()}.
060         * @param database a database descriptor
061         */
062        public void beforeInvocation(Database<D> database);
063        
064        /**
065         * Called after an operation is performed on the specified database retrieved via {@link #next()}.
066         * @param database a database descriptor
067         */
068        public void afterInvocation(Database<D> database);
069        
070        /**
071         * Removes all databases from this balancer.
072         */
073        public void clear();
074}