use of com.ctrip.framework.dal.cluster.client.Cluster in project dal by ctripcorp.
the class ClusterConfigImpl method generate.
@Override
public Cluster generate() {
Cluster cluster = generatedClusterRef.get();
if (cluster == null) {
synchronized (generatedClusterRef) {
cluster = generatedClusterRef.get();
if (cluster == null) {
cluster = innerGenerate();
generatedClusterRef.set(cluster);
}
}
}
return cluster;
}
use of com.ctrip.framework.dal.cluster.client.Cluster in project dal by ctripcorp.
the class DalConfigureFactory method readClusters.
private Map<String, DatabaseSet> readClusters(Node databaseSetsNode, DalConnectionLocator locator, DalConfigCustomizedOption defaultOption) throws Exception {
Map<String, DatabaseSet> databaseSets = new HashMap<>();
ClusterManager clusterManager = new ClusterManagerImpl(locator.getIntegratedConfigProvider());
List<Node> clusterList = getChildNodes(databaseSetsNode, CLUSTER);
for (Node node : clusterList) {
DalConfigCustomizedOption option = defaultOption.clone();
String name = getDatabaseSetName(node);
overrideDefaultConfig(node, option);
Cluster cluster = readCluster(node, clusterManager, option);
databaseSets.put(name, new ClusterDatabaseSet(name, cluster, locator, getSettings(node)));
}
return databaseSets;
}
use of com.ctrip.framework.dal.cluster.client.Cluster in project dal by ctripcorp.
the class ClusterManagerImpl method getOrCreateCluster.
@Override
public Cluster getOrCreateCluster(String clusterName, DalConfigCustomizedOption customizedOption) {
if (StringUtils.isEmpty(clusterName))
throw new DalRuntimeException("cluster name is empty");
clusterName = StringUtils.toTrimmedLowerCase(clusterName);
Cluster cluster = clusters.get(clusterName);
if (cluster == null)
synchronized (clusters) {
cluster = clusters.get(clusterName);
if (cluster == null) {
cluster = createCluster(clusterName, customizedOption);
clusters.put(clusterName, cluster);
}
}
return cluster;
}
use of com.ctrip.framework.dal.cluster.client.Cluster in project dal by ctripcorp.
the class DataSourceLocator method getDataSource.
public DataSource getDataSource(DataSourceIdentity id) {
DataSource ds = cache.get(id);
if (ds == null) {
synchronized (cache) {
ds = cache.get(id);
if (ds == null) {
try {
if (id instanceof ClusterInfoDelegateIdentity) {
ClusterInfo clusterInfo = ((ClusterInfoDelegateIdentity) id).getClusterInfo();
Cluster cluster = clusterInfo.getCluster();
if (cluster == null)
throw new RuntimeException("Cluster not created");
ds = createDataSource(id, clusterInfo, cluster);
} else
ds = createDataSource(id);
cache.put(id, ds);
} catch (Throwable t) {
String msg = String.format("error when creating datasource: %s", id.getId());
LOGGER.error(msg, t);
throw new RuntimeException(msg, t);
}
}
}
}
return ds;
}
Aggregations