package com.ctrip.xpipe.redis.keeper.config;


import com.ctrip.xpipe.redis.core.config.AbstractCoreConfig;

/**
 * @author marsqing
 *
 *         May 25, 2016 11:12:35 AM
 */
public class DefaultKeeperConfig extends AbstractCoreConfig implements KeeperConfig {
	
	public static final String KEY_REPLICATION_STORE_GC_INTERVAL_SECONDS = "replicationstore.gc.interval.seconds";
	public static final String KEY_REPLICATION_STORE_COMMANDFILE_SIZE = "replicationstore.commandfile.size";
	public static final String KEY_REPLICATION_STORE_COMMANDFILE_NUM_KEEP = "replicationstore.commandfile.num.keep";
	public static final String KEY_REPLICATION_STORE_MINITIME_GC_AFTERCREATE = "replicationstore.mintime.gc.aftercreate";
	public static final String KEY_REPLICATION_STORE_MAX_COMMANDS_TO_TRANSFER_BEFORE_CREATE_RDB = "replicationstore.max.commands.to.transfer";
	public static final String KEY_COMMAND_READER_FLYING_THRESHOLD = "command.reader.flying.threshold";
	public static final String KEY_RDB_DUMP_MIN_INTERVAL = "rdbdump.min.interval";
	public static final String KEY_DELAY_LOG_LIMIT_MICRO = "monitor.delay.log.limit.micro";
    private static final String KEY_TRAFFIC_REPORT_INTERVAL = "monitor.traffic.report.interval";

	@Override
	public int getMetaServerConnectTimeout() {
		return 2000;
	}

	@Override
	public int getMetaServerReadTimeout() {
		return 2000;
	}


	@Override
	public int getMetaRefreshIntervalMillis() {
		return 3000;
	}

	@Override
	public int getReplicationStoreGcIntervalSeconds() {
		return getIntProperty(KEY_REPLICATION_STORE_GC_INTERVAL_SECONDS, 2);
	}

	@Override
	public int getReplicationStoreCommandFileSize() {
		return getIntProperty(KEY_REPLICATION_STORE_COMMANDFILE_SIZE, 20);
	}

	@Override
	public int getReplicationStoreCommandFileNumToKeep() {
		return getIntProperty(KEY_REPLICATION_STORE_COMMANDFILE_NUM_KEEP, 2);
	}

	@Override
	public long getReplicationStoreMaxCommandsToTransferBeforeCreateRdb() {
		return getLongProperty(KEY_REPLICATION_STORE_MAX_COMMANDS_TO_TRANSFER_BEFORE_CREATE_RDB, 100L);
	}

	@Override
	public int getRdbDumpMinIntervalMilli() {
		return getIntProperty(KEY_RDB_DUMP_MIN_INTERVAL, 3600000);
	}

	@Override
	public
	int getReplicationStoreMinTimeMilliToGcAfterCreate(){
		return getIntProperty(KEY_REPLICATION_STORE_MINITIME_GC_AFTERCREATE, 60000);
	}

	@Override
	public long getCommandReaderFlyingThreshold() {
		return getLongProperty(KEY_COMMAND_READER_FLYING_THRESHOLD, (long) (1 << 15));
	}

	@Override
	public int getDelayLogLimitMicro() {
		return getIntProperty(KEY_DELAY_LOG_LIMIT_MICRO, 10000);
	}

    @Override
    public long getTrafficReportIntervalMillis() {
        return getLongProperty(KEY_TRAFFIC_REPORT_INTERVAL, DEFAULT_TRAFFIC_REPORT_INTERVAL_MILLIS);
    }
}

@@ -40,16 +40,264 @@
 nfig;%0A%0A%0A
+import com.ctrip.xpipe.api.config.Config;%0Aimport com.ctrip.xpipe.api.foundation.FoundationService;%0Aimport com.ctrip.xpipe.config.CompositeConfig;%0Aimport com.ctrip.xpipe.config.DefaultFileConfig;%0Aimport com.ctrip.xpipe.config.DefaultPropertyConfig;%0A
 import c
@@ -1464,16 +1464,663 @@
 rval%22;%0A%0A
+%09private static String KEEPER_CONTAINER_PROPERTIES_PATH = String.format(%22/opt/data/%25s%22, FoundationService.DEFAULT.getAppId());%0A%09private static String KEEPER_CONTAINER_PROPERTIES_FILE = %22keeper-container.properties%22;%0A%0A%09public DefaultKeeperConfig()%7B%0A%0A%09%09CompositeConfig compositeConfig = new CompositeConfig();%0A%09%09compositeConfig.addConfig(Config.DEFAULT);%0A%09%09try%7B%0A%09%09%09compositeConfig.addConfig(new DefaultFileConfig(KEEPER_CONTAINER_PROPERTIES_PATH, KEEPER_CONTAINER_PROPERTIES_FILE));%0A%09%09%7Dcatch (Exception e)%7B%0A%09%09%09logger.info(%22%5BDefaultKeeperConfig%5D%7B%7D%22, e);%0A%09%09%7D%0A%09%09compositeConfig.addConfig(new DefaultPropertyConfig());%0A%09%09setConfig(compositeConfig);%0A%09%7D%0A%0A
 %09@Overri

change KeeperConfig to be compitable with file config