-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dal-cluster' into 'master'
codegen 2.1.6 See merge request framework/dal-client-opensource!1
- Loading branch information
Showing
144 changed files
with
3,856 additions
and
1,721 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
dal-client/src/main/java/com/ctrip/platform/dal/dao/cluster/ClusterManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.ctrip.platform.dal.dao.cluster; | ||
|
||
import com.ctrip.framework.dal.cluster.client.Cluster; | ||
|
||
/** | ||
* @author c7ch23en | ||
*/ | ||
public interface ClusterManager { | ||
|
||
Cluster getOrCreateCluster(String clusterName); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
dal-client/src/main/java/com/ctrip/platform/dal/dao/cluster/ClusterManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.ctrip.platform.dal.dao.cluster; | ||
|
||
import com.ctrip.framework.dal.cluster.client.Cluster; | ||
import com.ctrip.framework.dal.cluster.client.config.ClusterConfig; | ||
import com.ctrip.framework.dal.cluster.client.util.StringUtils; | ||
import com.ctrip.platform.dal.dao.configure.ClusterConfigProvider; | ||
import com.ctrip.platform.dal.exceptions.DalRuntimeException; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author c7ch23en | ||
*/ | ||
public class ClusterManagerImpl implements ClusterManager { | ||
|
||
private final ClusterConfigProvider configProvider; | ||
private static final Map<String, Cluster> clusters = new ConcurrentHashMap<>(); | ||
|
||
public ClusterManagerImpl(ClusterConfigProvider configProvider) { | ||
this.configProvider = configProvider; | ||
} | ||
|
||
@Override | ||
public Cluster getOrCreateCluster(String clusterName) { | ||
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); | ||
clusters.put(clusterName, cluster); | ||
} | ||
} | ||
return cluster; | ||
} | ||
|
||
private Cluster createCluster(String clusterName) { | ||
ClusterConfig config = configProvider.getClusterConfig(clusterName); | ||
return new DynamicCluster(config); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.