01: /*
02: * HA-JDBC: High-Availability JDBC
03: * Copyright (c) 2004-2007 Paul Ferraro
04: *
05: * This library is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as published by the
07: * Free Software Foundation; either version 2.1 of the License, or (at your
08: * option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13: * for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public License
16: * along with this library; if not, write to the Free Software Foundation,
17: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * Contact: ferraro@users.sourceforge.net
20: */
21: package net.sf.hajdbc;
22:
23: import java.util.Set;
24:
25: /**
26: * @author Paul Ferraro
27: * @since 1.0
28: * @param <D> either java.sql.Driver or javax.sql.DataSource
29: */
30: public interface Balancer<D> {
31: /**
32: * Removes the specified database from this balancer.
33: * @param database a database descriptor
34: * @return true, if the database was removed successfully, false if it did not exist.
35: */
36: public boolean remove(Database<D> database);
37:
38: /**
39: * Adds the specified database to this balancer.
40: * @param database a database descriptor
41: * @return true, if the database was added successfully, false if already existed.
42: */
43: public boolean add(Database<D> database);
44:
45: /**
46: * Returns the next database from this balancer
47: * @return the next database from this balancer
48: */
49: public Database<D> next();
50:
51: /**
52: * Returns an unmodifiable collection of databases known to this balancer
53: * @return a collection of database descriptors
54: */
55: public Set<Database<D>> all();
56:
57: /**
58: * Called before an operation is performed on the specified database retrieved via {@link #next()}.
59: * @param database a database descriptor
60: */
61: public void beforeInvocation(Database<D> database);
62:
63: /**
64: * Called after an operation is performed on the specified database retrieved via {@link #next()}.
65: * @param database a database descriptor
66: */
67: public void afterInvocation(Database<D> database);
68:
69: /**
70: * Removes all databases from this balancer.
71: */
72: public void clear();
73: }
|