forked from apolloconfig/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor according to code review comments
- Loading branch information
Showing
50 changed files
with
346 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
apollo-client/src/main/java/com/ctrip/framework/apollo/exceptions/ApolloConfigException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.ctrip.framework.apollo.exceptions; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public class ApolloConfigException extends RuntimeException { | ||
public ApolloConfigException(String message) { | ||
super(message); | ||
} | ||
|
||
public ApolloConfigException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,25 +6,37 @@ | |
|
||
import com.ctrip.framework.apollo.Config; | ||
import com.ctrip.framework.apollo.ConfigChangeListener; | ||
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; | ||
import com.ctrip.framework.apollo.enums.PropertyChangeType; | ||
import com.ctrip.framework.apollo.model.ConfigChange; | ||
import com.ctrip.framework.apollo.model.ConfigChangeEvent; | ||
import com.dianping.cat.Cat; | ||
import com.dianping.cat.message.Message; | ||
import com.dianping.cat.message.Transaction; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public abstract class AbstractConfig implements Config { | ||
private static final Logger logger = LoggerFactory.getLogger(AbstractConfig.class); | ||
private static ExecutorService m_executorService; | ||
private List<ConfigChangeListener> m_listeners = Lists.newCopyOnWriteArrayList(); | ||
|
||
static { | ||
m_executorService = Executors.newCachedThreadPool(ApolloThreadFactory | ||
.create("Config", true)); | ||
|
||
} | ||
|
||
@Override | ||
public void addChangeListener(ConfigChangeListener listener) { | ||
if (!m_listeners.contains(listener)) { | ||
|
@@ -80,19 +92,30 @@ public String[] getArrayProperty(String key, String delimiter, String[] defaultV | |
return value == null ? defaultValue : value.split(delimiter); | ||
} | ||
|
||
protected void fireConfigChange(ConfigChangeEvent changeEvent) { | ||
for (ConfigChangeListener listener : m_listeners) { | ||
try { | ||
listener.onChange(changeEvent); | ||
} catch (Throwable ex) { | ||
Cat.logError(ex); | ||
logger.error("Failed to invoke config change listener {}", listener.getClass(), ex); | ||
} | ||
protected void fireConfigChange(final ConfigChangeEvent changeEvent) { | ||
for (final ConfigChangeListener listener : m_listeners) { | ||
m_executorService.submit(new Runnable() { | ||
@Override | ||
public void run() { | ||
String listenerName = listener.getClass().getName(); | ||
Transaction transaction = Cat.newTransaction("Apollo.ConfigChangeListener", listenerName); | ||
try { | ||
listener.onChange(changeEvent); | ||
transaction.setStatus(Message.SUCCESS); | ||
} catch (Throwable ex) { | ||
transaction.setStatus(ex); | ||
Cat.logError(ex); | ||
logger.error("Failed to invoke config change listener {}", listenerName, ex); | ||
} finally { | ||
transaction.complete(); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
List<ConfigChange> calcPropertyChanges(String namespace, Properties previous, | ||
Properties current) { | ||
Properties current) { | ||
if (previous == null) { | ||
previous = new Properties(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
@Named(type = ConfigManager.class, value = "default") | ||
@Named(type = ConfigManager.class) | ||
public class DefaultConfigManager implements ConfigManager { | ||
@Inject | ||
private ConfigFactoryManager m_factoryManager; | ||
|
Oops, something went wrong.