}
}
protected void initializeImpl(final long initId, final Collection<FunctionDefinition> functions) {
final OperationTimer timer = new OperationTimer(s_logger, "Initializing {} function definitions", functions.size());
final StaticFunctionRepository initialized = new StaticFunctionRepository(_initializedFunctionRepository);
final PoolExecutor.Service<FunctionDefinition> jobs = getExecutorService().createService(new CompletionListener<FunctionDefinition>() {
@Override
public void success(final FunctionDefinition function) {
if (function != null) {
synchronized (initialized) {
initialized.add(function);
}
}
}
@Override
public void failure(final Throwable error) {
s_logger.warn("Couldn't initialize function", error);
// Don't take any further action - the error has been logged and the function is not in the "initialized" set
}
});
getFunctionCompilationContext().setFunctionReinitializer(_reinitializer);
synchronized (initialized) {
for (final FunctionDefinition definition : functions) {
initialized.remove(definition);
}
}
for (final FunctionDefinition definition : functions) {
jobs.execute(new Callable<FunctionDefinition>() {
@Override
public FunctionDefinition call() {
try {
definition.init(getFunctionCompilationContext());
return definition;
} catch (final UnsupportedOperationException e) {
s_logger.warn("Function {}, is not supported in this configuration - {}", definition.getUniqueId(), e.getMessage());
s_logger.info("Caught exception", e);
return null;
} catch (final Exception e) {
s_logger.error("Couldn't initialize function {}", definition.getUniqueId());
throw new OpenGammaRuntimeException("Couldn't initialize " + definition.getShortName(), e);
}
}
});
}
try {
jobs.join();
} catch (final InterruptedException e) {
Thread.interrupted();
s_logger.warn("Interrupted while initializing function definitions.");
throw new OpenGammaRuntimeException("Interrupted while initializing function definitions. ViewProcessor not safe to use.");
}
_initializedFunctionRepository = initialized;
getFunctionCompilationContext().setFunctionReinitializer(null);
getFunctionCompilationContext().setFunctionInitId(initId);
timer.finished();
}