All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.hajdbc.DatabaseCluster Maven / Gradle / Ivy

There is a newer version: 3.6.61
Show newest version
/*
 * HA-JDBC: High-Availability JDBC
 * Copyright (C) 2012  Paul Ferraro
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 */
package net.sf.hajdbc;

import net.sf.hajdbc.balancer.Balancer;
import net.sf.hajdbc.cache.DatabaseMetaDataCache;
import net.sf.hajdbc.codec.Decoder;
import net.sf.hajdbc.dialect.Dialect;
import net.sf.hajdbc.durability.Durability;
import net.sf.hajdbc.io.InputSinkStrategy;
import net.sf.hajdbc.lock.LockManager;
import net.sf.hajdbc.logging.Level;
import net.sf.hajdbc.state.StateManager;
import net.sf.hajdbc.state.distributed.DistributedManager;
import net.sf.hajdbc.state.distributed.NodeState;
import net.sf.hajdbc.state.health.ClusterHealth;
import net.sf.hajdbc.state.health.NodeDatabaseRestoreListener;
import net.sf.hajdbc.state.health.NodeStateListener;
import net.sf.hajdbc.state.sync.SyncMgr;
import net.sf.hajdbc.tx.TransactionIdentifierFactory;

import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;

/**
 * @author Paul Ferraro
 * @param  either java.sql.Driver or javax.sql.DataSource
 * @param  database implementation
 */
public interface DatabaseCluster> extends Lifecycle
{
	/**
	 * Returns the identifier of this cluster.
	 * @return an identifier
	 */
	String getId();
	
	/**
	 * Activates the specified database
	 * @param database a database descriptor
	 * @param manager a state manager
	 * @return true, if the database was activated, false it was already active
	 */
	boolean activate(D database, StateManager manager);
	
	/**
	 * Deactivates the specified database
	 * @param database a database descriptor
	 * @param manager a state manager
	 * @return true, if the database was deactivated, false it was already inactive
	 */
	boolean deactivate(D database, StateManager manager);
	
	/**
	 * Returns the database identified by the specified id
	 * @param id a database identifier
	 * @return a database descriptor
	 * @throws IllegalArgumentException if no database exists with the specified identifier
	 */
	D getDatabase(String id);

	D getDatabaseByIp(String ip);

	void addDatabase(D database);

	/**
	 * Returns the local database.
	 * @return local database
	 */
	D getLocalDatabase();
	
	/**
	 * Returns the Balancer implementation used by this database cluster.
	 * @return an implementation of Balancer
	 */
	Balancer getBalancer();
	
	TransactionMode getTransactionMode();
	
	ExecutorService getExecutor();
	
	/**
	 * Returns a dialect capable of returning database vendor specific values.
	 * @return an implementation of Dialect
	 */
	Dialect getDialect();
	
	/**
	 * Returns a LockManager capable of acquiring named read/write locks on the specific objects in this database cluster.
	 * @return a LockManager implementation
	 */
	LockManager getLockManager();
	
	/**
	 * Returns a StateManager for persisting database cluster state.
	 * @return a StateManager implementation
	 */
	StateManager getStateManager();

  /**
   Returns a ClusterHealth for persisting database cluster health.
   * @return a ClusterHealth implementation
   */
  ClusterHealth getClusterHealth();

  /**
   Returns a DistributedManager for distributed.
   * @return a DistributedManager implementation
   */
  DistributedManager getDistributedManager();
	
	/**
	 * Returns a DatabaseMetaData cache.
	 * @return a DatabaseMetaDataCache implementation
	 */
	DatabaseMetaDataCache getDatabaseMetaDataCache();
	
	/**
	 * Indicates whether or not sequence detection is enabled for this cluster.
	 * @return true, if sequence detection is enabled, false otherwise.
	 */
	boolean isSequenceDetectionEnabled();
	
	/**
	 * Indicates whether or not identity column detection is enabled for this cluster.
	 * @return true, if identity column detection is enabled, false otherwise.
	 */
	boolean isIdentityColumnDetectionEnabled();
	
	/**
	 * Indicates whether or not non-deterministic CURRENT_DATE SQL functions will be evaluated to deterministic static values.
	 * @return true, if temporal SQL replacement is enabled, false otherwise.
	 */
	boolean isCurrentDateEvaluationEnabled();
	
	/**
	 * Indicates whether or not non-deterministic CURRENT_TIME functions will be evaluated to deterministic static values.
	 * @return true, if temporal SQL replacement is enabled, false otherwise.
	 */
	boolean isCurrentTimeEvaluationEnabled();
	
	/**
	 * Indicates whether or not non-deterministic CURRENT_TIMESTAMP functions will be evaluated to deterministic static values.
	 * @return true, if temporal SQL replacement is enabled, false otherwise.
	 */
	boolean isCurrentTimestampEvaluationEnabled();
	
	/**
	 * Indicates whether or not non-deterministic RAND() functions will be replaced by evaluated to static values.
	 * @return true, if temporal SQL replacement is enabled, false otherwise.
	 */
	boolean isRandEvaluationEnabled();
	
	/**
	 * Indicates whether or not this cluster is active, i.e. started, but not yet stopped.
	 * @return true, if this cluster is active, false otherwise.
	 */
	boolean isActive();

  void changeState(NodeState oldState,NodeState newState);

	void addListener(DatabaseClusterListener listener);
	
	void removeListener(DatabaseClusterListener listener);

  void addListener(NodeStateListener listener);

  void removeListener(NodeStateListener listener);

	void addListener(NodeDatabaseRestoreListener listener);

	void removeListener(NodeDatabaseRestoreListener listener);

	void addSynchronizationListener(SynchronizationListener listener);
	
	void removeSynchronizationListener(SynchronizationListener listener);

	void addConfigurationListener(DatabaseClusterConfigurationListener listener);
	
	void removeConfigurationListener(DatabaseClusterConfigurationListener listener);


	Durability getDurability();
	
	ThreadFactory getThreadFactory();
	
	Decoder getDecoder();
	
	TransactionIdentifierFactory getTransactionIdentifierFactory();

	InputSinkStrategy getInputSinkStrategy();

	boolean isAlive(D database, Level level);

	int getNodeCount();

	SyncMgr getSyncMgr();

	List getNodes();

	void checkActiveDatabases(Set activeDatabases);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy