/*
 * 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.shardingproxy.runtime;

import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;
import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.core.rule.MasterSlaveRule;
import io.shardingsphere.orchestration.internal.rule.OrchestrationMasterSlaveRule;
import lombok.Getter;

import java.util.Map;

/**
 * Master-slave schema.
 *
 * @author panjuan
 */
@Getter
public final class MasterSlaveSchema extends LogicSchema {
    
    private final MasterSlaveRule masterSlaveRule;
    
    public MasterSlaveSchema(final String name, final Map<String, DataSourceParameter> dataSources, final MasterSlaveRuleConfiguration masterSlaveRuleConfig, final boolean isUsingRegistry) {
        super(name, dataSources);
        masterSlaveRule = getMasterSlaveRule(masterSlaveRuleConfig, isUsingRegistry);
    }
    
    private MasterSlaveRule getMasterSlaveRule(final MasterSlaveRuleConfiguration masterSlaveRule, final boolean isUsingRegistry) {
        return isUsingRegistry ? new OrchestrationMasterSlaveRule(masterSlaveRule) : new MasterSlaveRule(masterSlaveRule);
    }
}

@@ -663,16 +663,61 @@
 ntime;%0A%0A
+import com.google.common.eventbus.Subscribe;%0A
 import i
@@ -774,16 +774,16 @@
 ration;%0A
-
 import i
@@ -878,24 +878,114 @@
 rSlaveRule;%0A
+import io.shardingsphere.orchestration.internal.event.config.MasterSlaveRuleChangedEvent;%0A
 import io.sh
@@ -1239,22 +1239,16 @@
 private 
-final 
 MasterSl
@@ -1723,32 +1723,32 @@
 singRegistry) %7B%0A
-
         return i
@@ -1860,10 +1860,415 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * Renew master-slave rule.%0A     *%0A     * @param masterSlaveEvent master-slave event.%0A     */%0A    @Subscribe%0A    public void renew(final MasterSlaveRuleChangedEvent masterSlaveEvent) %7B%0A        if (!getName().equals(masterSlaveEvent.getShardingSchemaName())) %7B%0A            return;%0A        %7D%0A        masterSlaveRule = new MasterSlaveRule(masterSlaveEvent.getMasterSlaveRuleConfig());%0A    %7D%0A
 %7D%0A

add renew()