/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * 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.
 * </p>
 */

package io.shardingsphere.shardingjdbc.orchestration.internal.rule;

import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;
import io.shardingsphere.core.rule.MasterSlaveRule;

import java.util.Collection;
import java.util.LinkedList;

/**
 * Orchestration master slave rule.
 *
 * @author panjuan
 */
public class OrchestrationMasterSlaveRule extends MasterSlaveRule {
    
    private final Collection<String> disabledDataSourceNames = new LinkedList<>();
    
    public OrchestrationMasterSlaveRule(final MasterSlaveRuleConfiguration config) {
        super(config);
    }
    
    /**
     * Get slave data source names.
     *
     * @return available slave data source name
     */
    @Override
    public Collection<String> getSlaveDataSourceNames() {
        Collection<String> result = new LinkedList<>(super.getSlaveDataSourceNames());
        for (String each : disabledDataSourceNames) {
            result.remove(each);
        }
        return result;
    }
}

@@ -678,24 +678,69 @@
 rnal.rule;%0A%0A
+import com.google.common.eventbus.Subscribe;%0A
 import io.sh
@@ -840,24 +840,112 @@
 erSlaveRule;
+%0Aimport io.shardingsphere.orchestration.internal.event.state.DisabledStateEventBusEvent;
 %0A%0Aimport jav
@@ -1731,10 +1731,392 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * Renew disable dataSource names.%0A     *%0A     * @param disabledStateEventBusEvent jdbc disabled event bus event%0A     */%0A    @Subscribe%0A    public void renew(final DisabledStateEventBusEvent disabledStateEventBusEvent) %7B%0A        disabledDataSourceNames.clear();%0A        disabledDataSourceNames.addAll(disabledStateEventBusEvent.getDisabledDataSourceNames());%0A    %7D%0A
 %7D%0A

add renew()