safe loading of calculator engine

This commit is contained in:
Solovyev_S 2013-07-02 13:23:44 +04:00
parent 4dae4bbca4
commit b7b32b1002

View File

@ -179,13 +179,26 @@ public class CalculatorEngineImpl implements CalculatorEngine {
@Override @Override
public void reset() { public void reset() {
synchronized (lock) { synchronized (lock) {
varsRegistry.load(); safeLoadRegistry(varsRegistry);
functionsRegistry.load(); safeLoadRegistry(functionsRegistry);
operatorsRegistry.load(); safeLoadRegistry(operatorsRegistry);
postfixFunctionsRegistry.load(); safeLoadRegistry(postfixFunctionsRegistry);
} }
} }
private void safeLoadRegistry(@Nonnull CalculatorMathRegistry<?> registry) {
try {
registry.load();
} catch (Exception e) {
logException(e);
}
}
private void logException(@Nonnull Exception e) {
final CalculatorLogger logger = Locator.getInstance().getLogger();
logger.error("Engine", e.getMessage(), e);
}
@Override @Override
public void softReset() { public void softReset() {
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null); Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.engine_preferences_changed, null);