blob: 580c621cb209fbb1831e530f8ab6b6e28676d122 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.logserver;
import java.util.logging.Level;
import com.yahoo.plugin.Plugin;
import com.yahoo.plugin.SystemPropertyConfig;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Logger;
/**
* TODO: describe class
*
* @author Stig Bakken
*/
public abstract class AbstractPluginLoader implements PluginLoader {
private static final Logger log = Logger.getLogger(AbstractPluginLoader.class.getName());
public abstract void loadPlugins();
protected void loadFromClass(Class<? extends Plugin> pluginClass) {
Plugin plugin;
try {
plugin = pluginClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
log.log(LogLevel.ERROR, pluginClass.getName() + ": load failed: " + e);
throw new RuntimeException(e);
}
String pname = plugin.getPluginName();
String prefix = Server.APPNAME + "." + pname + ".";
SystemPropertyConfig config = new SystemPropertyConfig(prefix);
String enable = config.get("enable", "true");
if (! enable.equals("true")) {
log.log(LogLevel.INFO, pname + ": plugin disabled by config");
return;
}
try {
plugin.initPlugin(config);
log.log(Level.FINE, pname + ": plugin loaded");
} catch (Exception e) {
log.log(LogLevel.ERROR, pname + ": init failed", e);
}
}
}
|