KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > DatabaseCluster


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
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.sql.SQLException JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import java.util.concurrent.ExecutorService JavaDoc;
27 import java.util.concurrent.locks.Lock JavaDoc;
28
29
30 /**
31  * @author Paul Ferraro
32  * @since 1.0
33  */

34 public interface DatabaseCluster extends DatabaseClusterMBean
35 {
36     /**
37      * Activates the specified database
38      * @param database a database descriptor
39      * @return true, if the database was activated, false it was already active
40      */

41     public boolean activate(Database database);
42     
43     /**
44      * Deactivates the specified database
45      * @param database a database descriptor
46      * @return true, if the database was deactivated, false it was already inactive
47      */

48     public boolean deactivate(Database database);
49     
50     /**
51      * Returns a map of database to connection factory for this obtaining connections to databases in this cluster.
52      * @return a connection factory map
53      */

54     public Map JavaDoc<Database, ?> getConnectionFactoryMap();
55     
56     /**
57      * Determines whether or not the specified database is responding
58      * @param database a database descriptor
59      * @return true, if the database is responding, false if it appears down
60      */

61     public boolean isAlive(Database database);
62     
63     /**
64      * Returns the database identified by the specified id
65      * @param id a database identifier
66      * @return a database descriptor
67      * @throws IllegalArgumentException if no database exists with the specified identifier
68      */

69     public Database getDatabase(String JavaDoc id);
70     
71     /**
72      * Loads the persisted state of this database cluster
73      * @return an array of database identifiers
74      * @throws SQLException if state could not be obtained
75      */

76     public String JavaDoc[] loadState() throws SQLException;
77     
78     /**
79      * Returns the default synchronization strategy for this database cluster
80      * @return a synchronization strategy implementation
81      */

82     public SynchronizationStrategy getDefaultSynchronizationStrategy();
83
84     /**
85      * Handles a failure caused by the specified cause on the specified database.
86      * If the database is not alive, then it is deactivated, otherwise an exception is thrown back to the caller.
87      * @param database a database descriptor
88      * @param cause the cause of the failure
89      * @throws SQLException if the database is alive
90      */

91     public void handleFailure(Database database, SQLException cause) throws SQLException;
92     
93     /**
94      * Returns the Balancer implementation used by this database cluster.
95      * @return an implementation of <code>Balancer</code>
96      */

97     public Balancer getBalancer();
98     
99     /**
100      * Returns an executor service used to execute transactional database writes.
101      * @return an implementation of <code>ExecutorService</code>
102      * @since 1.1
103      */

104     public ExecutorService JavaDoc getTransactionalExecutor();
105     
106     /**
107      * Returns an executor service used to execute non-transactional database writes.
108      * @return an implementation of <code>ExecutorService</code>
109      * @since 1.1
110      */

111     public ExecutorService JavaDoc getNonTransactionalExecutor();
112     
113     /**
114      * Returns a dialect capable of returning database vendor specific values.
115      * @return an implementation of <code>Dialect</code>
116      * @since 1.1
117      */

118     public Dialect getDialect();
119     
120     /**
121      * Returns a Lock that can acquire a read lock on this database cluster.
122      * @return a read lock
123      * @since 1.1
124      */

125     public Lock JavaDoc readLock();
126     
127     /**
128      * Returns a Lock that can acquire a write lock on this database cluster.
129      * @return a write lock
130      * @since 1.1
131      */

132     public Lock JavaDoc writeLock();
133     
134     /**
135      * Starts this database cluster.
136      * @throws SQLException if database cluster fails to start
137      * @since 1.1
138      */

139     public void start() throws SQLException;
140     
141     /**
142      * Stops this database cluster.
143      * @since 1.1
144      */

145     public void stop();
146 }
147
Popular Tags