properties = new ArrayList<Property>();
}
@Override
public synchronized void start(final StartContext context) throws StartException {
final Handler handler;
final ModuleLoader moduleLoader = Module.forClass(CustomHandlerService.class).getModuleLoader();
final ModuleIdentifier id = ModuleIdentifier.create(moduleName);
try {
final Class<?> handlerClass = Class.forName(className, false, moduleLoader.loadModule(id).getClassLoader());
if (Handler.class.isAssignableFrom(handlerClass)) {
handler = (Handler) handlerClass.newInstance();
} else {
throw new StartException(String.format("%s %s is not a valid %s.", CUSTOM_HANDLER, className, Handler.class.getName()));
}
} catch (ClassNotFoundException e) {
throw new StartException(e);
} catch (ModuleLoadException e) {
throw new StartException(String.format("%s %s is not a valid %s.", CUSTOM_HANDLER, className, Handler.class.getName()), e);
} catch (InstantiationException e) {
throw new StartException(String.format("%s %s is not a valid %s.", CUSTOM_HANDLER, className, Handler.class.getName()), e);
} catch (IllegalAccessException e) {
throw new StartException(String.format("%s %s is not a valid %s.", CUSTOM_HANDLER, className, Handler.class.getName()), e);
}
formatterSpec.apply(handler);
if (level != null) handler.setLevel(level);
try {
handler.setEncoding(encoding);
} catch (UnsupportedEncodingException e) {
throw new StartException(e);
}
// Set the properties
setProperties(handler, properties);