/*
 * 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.jdbc.orchestration.internal.listener;

import io.shardingsphere.core.jdbc.core.datasource.MasterSlaveDataSource;
import io.shardingsphere.core.jdbc.core.datasource.ShardingDataSource;
import io.shardingsphere.jdbc.orchestration.internal.config.ConfigMapListenerManager;
import io.shardingsphere.jdbc.orchestration.internal.config.ConfigurationListenerManager;
import io.shardingsphere.jdbc.orchestration.internal.state.datasource.DataSourceListenerManager;
import io.shardingsphere.jdbc.orchestration.internal.state.instance.InstanceListenerManager;
import io.shardingsphere.jdbc.orchestration.reg.api.RegistryCenter;

/**
 * Registry center's listener factory.
 *
 * @author caohao
 * @author panjuan
 */
public final class ListenerFactory {
    
    private final ConfigurationListenerManager configurationListenerManager;
    
    private final InstanceListenerManager instanceListenerManager;
    
    private final ConfigMapListenerManager configMapListenerManager;
    
    private final DataSourceListenerManager dataSourceListenerManager;
    
    public ListenerFactory(final String name, final RegistryCenter regCenter) {
        configurationListenerManager = new ConfigurationListenerManager(name, regCenter);
        instanceListenerManager = new InstanceListenerManager(name, regCenter);
        configMapListenerManager = new ConfigMapListenerManager(name, regCenter);
        dataSourceListenerManager = new DataSourceListenerManager(name, regCenter);
    }
    
    /**
     * Initialize listeners for sharding data source.
     * 
     * @param shardingDataSource sharding data source
     */
    public void initShardingListeners(final ShardingDataSource shardingDataSource) {
        configurationListenerManager.start(shardingDataSource);
        instanceListenerManager.start(shardingDataSource);
        dataSourceListenerManager.start(shardingDataSource);
        configMapListenerManager.start(shardingDataSource);
    }
    
    /**
     * Initialize listeners for master-slave data source.
     *
     * @param masterSlaveDataSource master-slave data source
     */
    public void initMasterSlaveListeners(final MasterSlaveDataSource masterSlaveDataSource) {
        configurationListenerManager.start(masterSlaveDataSource);
        instanceListenerManager.start(masterSlaveDataSource);
        dataSourceListenerManager.start(masterSlaveDataSource);
        configMapListenerManager.start(masterSlaveDataSource);
    }
    
    /**
     * Initialize listeners for proxy yaml configuration.
     *
     */
    public void initProxyListeners() {
        configurationListenerManager.start();
        instanceListenerManager.start();
        dataSourceListenerManager.start();
        configMapListenerManager.start();
    }
}

@@ -682,153 +682,8 @@
 r;%0A%0A
-import io.shardingsphere.core.jdbc.core.datasource.MasterSlaveDataSource;%0Aimport io.shardingsphere.core.jdbc.core.datasource.ShardingDataSource;%0A
 impo
@@ -2021,28 +2021,16 @@
 sharding
- data source
 .%0A     *
@@ -2041,145 +2041,48 @@
    *
- @param shardingDataSource sharding data source%0A     */%0A    public void initShardingListeners(final ShardingDataSource shardingDataSource
+/%0A    public void initShardingListeners(
 ) %7B%0A
@@ -2114,38 +2114,32 @@
 enerManager.
-start(
 sharding
 DataSource);
@@ -2122,34 +2122,30 @@
 ger.sharding
-DataSource
+Start(
 );%0A        i
@@ -2163,38 +2163,32 @@
 enerManager.
-start(
 sharding
 DataSource);
@@ -2171,34 +2171,30 @@
 ger.sharding
-DataSource
+Start(
 );%0A        d
@@ -2214,38 +2214,32 @@
 enerManager.
-start(
 sharding
 DataSource);
@@ -2222,34 +2222,30 @@
 ger.sharding
-DataSource
+Start(
 );%0A        c
@@ -2272,22 +2272,16 @@
 ger.
-start(
 sharding
 Data
@@ -2276,26 +2276,22 @@
 sharding
-DataSource
+Start(
 );%0A    %7D
@@ -2348,28 +2348,16 @@
 er-slave
- data source
 .%0A     *
@@ -2367,161 +2367,51 @@
    *
- @param masterSlaveDataSource master-slave data source%0A     */%0A    public void initMasterSlaveListeners(final MasterSlaveDataSource masterSlaveDataSource
+/%0A    public void initMasterSlaveListeners(
 ) %7B%0A
@@ -2439,38 +2439,32 @@
 ListenerManager.
-start(
 masterSlaveDataS
@@ -2454,34 +2454,30 @@
 .masterSlave
-DataSource
+Start(
 );%0A        i
@@ -2491,38 +2491,32 @@
 ListenerManager.
-start(
 masterSlaveDataS
@@ -2506,34 +2506,30 @@
 .masterSlave
-DataSource
+Start(
 );%0A        d
@@ -2545,38 +2545,32 @@
 ListenerManager.
-start(
 masterSlaveDataS
@@ -2560,34 +2560,30 @@
 .masterSlave
-DataSource
+Start(
 );%0A        c
@@ -2606,22 +2606,16 @@
 Manager.
-start(
 masterSl
@@ -2617,26 +2617,22 @@
 terSlave
-DataSource
+Start(
 );%0A    %7D
@@ -2686,27 +2686,8 @@
 roxy
- yaml configuration
 .%0A  
@@ -2767,33 +2767,38 @@
 ListenerManager.
-s
+proxyS
 tart();%0A        
@@ -2813,33 +2813,38 @@
 ListenerManager.
-s
+proxyS
 tart();%0A        
@@ -2861,33 +2861,38 @@
 ListenerManager.
-s
+proxyS
 tart();%0A        
@@ -2916,17 +2916,22 @@
 Manager.
-s
+proxyS
 tart();%0A

remove data source parameter