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

io.shardingsphere.core.rule.MasterSlaveRule Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
/*
 * Copyright 2016-2018 shardingsphere.io.
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *

*/ package io.shardingsphere.core.rule; import com.google.common.base.Preconditions; import io.shardingsphere.core.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithm; import io.shardingsphere.core.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithmType; import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration; import lombok.Getter; import java.util.Collection; /** * Databases and tables master-slave rule configuration. * * @author zhangliang */ @Getter public final class MasterSlaveRule { private final String name; private final String masterDataSourceName; private final Collection slaveDataSourceNames; private final MasterSlaveLoadBalanceAlgorithm loadBalanceAlgorithm; public MasterSlaveRule(final MasterSlaveRuleConfiguration config) { Preconditions.checkNotNull(config.getName(), "Master-slave rule name cannot be null."); Preconditions.checkNotNull(config.getMasterDataSourceName(), "Master data source name cannot be null."); Preconditions.checkNotNull(config.getSlaveDataSourceNames(), "Slave data source names cannot be null."); Preconditions.checkState(!config.getSlaveDataSourceNames().isEmpty(), "Slave data source names cannot be empty."); name = config.getName(); masterDataSourceName = config.getMasterDataSourceName(); slaveDataSourceNames = config.getSlaveDataSourceNames(); loadBalanceAlgorithm = null == config.getLoadBalanceAlgorithm() ? MasterSlaveLoadBalanceAlgorithmType.getDefaultAlgorithmType().getAlgorithm() : config.getLoadBalanceAlgorithm(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy