001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc.sync;
019
020import java.sql.Connection;
021import java.sql.SQLException;
022import java.util.Set;
023import java.util.concurrent.ExecutorService;
024
025import net.sf.hajdbc.Database;
026import net.sf.hajdbc.DatabaseProperties;
027import net.sf.hajdbc.codec.Decoder;
028import net.sf.hajdbc.dialect.Dialect;
029
030
031/**
032 * @author Paul Ferraro
033 * @param <D> Driver or DataSource
034 * @since 2.0
035 */
036public interface SynchronizationContext<Z, D extends Database<Z>>
037{
038        /**
039         * Returns a connection to the specified database.
040         * @param database a database to which to connect
041         * @return a database connection
042         * @throws SQLException if connection could not be obtained
043         */
044        Connection getConnection(D database) throws SQLException;
045        
046        /**
047         * Returns the database from which to synchronize.
048         * @return a database
049         */
050        D getSourceDatabase();
051        
052        /**
053         * Returns the database to synchronize.
054         * @return a database
055         */
056        D getTargetDatabase();
057        
058        /**
059         * Returns a snapshot of the activate databases in the cluster at the time synchronization started.
060         * @return a collection of databases
061         */
062        Set<D> getActiveDatabaseSet();
063        
064        /**
065         * Returns a cache of database meta data for the source database.
066         * @return a cache of database meta data
067         */
068        DatabaseProperties getSourceDatabaseProperties();
069        
070        /**
071         * Returns a cache of database meta data for the target database.
072         * @return a cache of database meta data
073         */
074        DatabaseProperties getTargetDatabaseProperties();
075        
076        /**
077         * Returns the dialect of the cluster.
078         * @return a dialect
079         */
080        Dialect getDialect();
081        
082        /**
083         * An executor service for executing tasks asynchronously.
084         * @return an executor service
085         */
086        ExecutorService getExecutor();
087        
088        SynchronizationSupport getSynchronizationSupport();
089        
090        Decoder getDecoder();
091        
092        /**
093         * Closes any open database connections and shuts down the executor service. 
094         */
095        void close();
096}