Skip to content

Commit

Permalink
add getPropertyNames interfact to Config
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam committed Aug 9, 2016
1 parent 15c5d41 commit a87984d
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 38 deletions.
2 changes: 1 addition & 1 deletion apollo-adminservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion apollo-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion apollo-biz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>apollo</artifactId>
<groupId>com.ctrip.framework.apollo</groupId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apollo-biz</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apollo-buildtools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion apollo-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
56 changes: 29 additions & 27 deletions apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.ctrip.framework.apollo;

import java.util.Set;

/**
* @author Jason Song([email protected])
*/
public interface Config {
/**
* Return the property value with the given key, or {@code defaultValue} if the key doesn't exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value
*/
Expand All @@ -16,80 +18,74 @@ public interface Config {
/**
* Return the integer property value with the given key, or {@code defaultValue} if the key
* doesn't exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value as integer
*
* @throws NumberFormatException if the property value is invalid
*/
public Integer getIntProperty(String key, Integer defaultValue);

/**
* Return the long property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value as long
*
* @throws NumberFormatException if the property value is invalid
*/
public Long getLongProperty(String key, Long defaultValue);

/**
* Return the short property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value as short
*
* @throws NumberFormatException if the property value is invalid
*/
public Short getShortProperty(String key, Short defaultValue);

/**
* Return the float property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value as float
*
* @throws NumberFormatException if the property value is invalid
*/
public Float getFloatProperty(String key, Float defaultValue);

/**
* Return the double property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value as double
*
* @throws NumberFormatException if the property value is invalid
*/
public Double getDoubleProperty(String key, Double defaultValue);

/**
* Return the byte property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value as byte
*
* @throws NumberFormatException if the property value is invalid
*/
public Byte getByteProperty(String key, Byte defaultValue);

/**
* Return the boolean property value with the given key, or {@code defaultValue} if the key
* doesn't exist.
*
* @param key the property name
*
* @param key the property name
* @param defaultValue the default value when key is not found
* @return the property value as boolean
*/
Expand All @@ -98,18 +94,24 @@ public interface Config {
/**
* Return the array property value with the given key, or {@code defaultValue} if the key doesn't
* exist.
*
* @param key the property name
* @param delimiter the delimiter regex
*
* @param key the property name
* @param delimiter the delimiter regex
* @param defaultValue the default value when key is not found
* @return
*/
public String[] getArrayProperty(String key, String delimiter, String[] defaultValue);

/**
* Add change listener to this config instance.
*
*
* @param listener the config change listener
*/
public void addChangeListener(ConfigChangeListener listener);

/**
* Return a set of the property names
*
* @return the property names
*/
public Set<String> getPropertyNames();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;


Expand Down Expand Up @@ -90,6 +92,16 @@ public String getProperty(String key, String defaultValue) {
return value == null ? defaultValue : value;
}

@Override
public Set<String> getPropertyNames() {
Properties properties = m_configProperties.get();
if (properties == null) {
return Collections.emptySet();
}

return properties.stringPropertyNames();
}

@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
if (newProperties.equals(m_configProperties.get())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
* @author Jason Song([email protected])
Expand Down Expand Up @@ -59,6 +61,15 @@ public String getProperty(String key, String defaultValue) {
return this.m_configProperties.getProperty(key, defaultValue);
}

@Override
public Set<String> getPropertyNames() {
if (m_configProperties == null) {
return Collections.emptySet();
}

return m_configProperties.stringPropertyNames();
}

@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
if (newProperties.equals(m_configProperties)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;

import java.util.Set;

import static org.junit.Assert.assertEquals;

/**
Expand Down Expand Up @@ -92,6 +94,11 @@ public String getProperty(String key, String defaultValue) {

return m_namespace + ":" + key;
}

@Override
public Set<String> getPropertyNames() {
return null;
}
}

private static class MockConfigFile implements ConfigFile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;

import java.util.Set;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
Expand Down Expand Up @@ -94,6 +96,11 @@ public Config create(final String namespace) {
public String getProperty(String key, String defaultValue) {
return namespace + ":" + key;
}

@Override
public Set<String> getPropertyNames() {
return null;
}
};
}

Expand Down
2 changes: 1 addition & 1 deletion apollo-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion apollo-configservice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion apollo-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion apollo-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>apollo</artifactId>
<groupId>com.ctrip.framework.apollo</groupId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apollo-demo</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apollo-portal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.0.9</version>
<version>0.0.10-SNAPSHOT</version>
<name>Apollo</name>
<packaging>pom</packaging>
<description>Ctrip Configuration Center</description>
Expand Down

0 comments on commit a87984d

Please sign in to comment.