| 1 | |
package com.ctrip.apollo.util; |
| 2 | |
|
| 3 | |
import com.google.common.base.Preconditions; |
| 4 | |
|
| 5 | |
import com.ctrip.apollo.core.ConfigConsts; |
| 6 | |
import com.ctrip.apollo.core.MetaDomainConsts; |
| 7 | |
import com.ctrip.apollo.core.enums.Env; |
| 8 | |
import com.ctrip.apollo.core.enums.EnvUtils; |
| 9 | |
import com.ctrip.framework.foundation.Foundation; |
| 10 | |
|
| 11 | |
import org.unidal.lookup.annotation.Named; |
| 12 | |
|
| 13 | |
import java.util.concurrent.TimeUnit; |
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
@Named(type = ConfigUtil.class) |
| 19 | 17 | public class ConfigUtil { |
| 20 | |
|
| 21 | |
private static final int refreshInterval = 5; |
| 22 | 1 | private static final TimeUnit refreshIntervalTimeUnit = TimeUnit.MINUTES; |
| 23 | |
private static final int connectTimeout = 5000; |
| 24 | |
private static final int readTimeout = 10000; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
public String getAppId() { |
| 32 | 0 | String appId = Foundation.app().getAppId(); |
| 33 | 0 | Preconditions.checkState(appId != null, "app.id is not set"); |
| 34 | 0 | return appId; |
| 35 | |
} |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public String getDataCenter() { |
| 42 | 0 | return Foundation.server().getDataCenter(); |
| 43 | |
} |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public String getCluster() { |
| 50 | 0 | String cluster = System.getProperty("apollo.cluster"); |
| 51 | 0 | if (cluster == null) { |
| 52 | 0 | cluster = ConfigConsts.CLUSTER_NAME_DEFAULT; |
| 53 | |
} |
| 54 | 0 | return cluster; |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public Env getApolloEnv() { |
| 63 | 0 | Env env = EnvUtils.transformEnv(Foundation.server().getEnvType()); |
| 64 | 0 | Preconditions.checkState(env != null, "env is not set"); |
| 65 | 0 | return env; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public String getMetaServerDomainName() { |
| 69 | 32 | return MetaDomainConsts.getDomain(getApolloEnv()); |
| 70 | |
} |
| 71 | |
|
| 72 | |
public int getConnectTimeout() { |
| 73 | 103 | return connectTimeout; |
| 74 | |
} |
| 75 | |
|
| 76 | |
public int getReadTimeout() { |
| 77 | 73 | return readTimeout; |
| 78 | |
} |
| 79 | |
|
| 80 | |
public int getRefreshInterval() { |
| 81 | 12 | return refreshInterval; |
| 82 | |
} |
| 83 | |
|
| 84 | |
public TimeUnit getRefreshTimeUnit() { |
| 85 | 8 | return refreshIntervalTimeUnit; |
| 86 | |
} |
| 87 | |
} |