由于项目使用apache eagle框架,所以学习了一下代码结构。由于还不会java,所以看得很艰难,只能大体先猜测了代码主结构,可能下面说的有不对的地方,望见谅。
页面保存出错,编辑了好几遍,格式太难调了,不调了。。。凑合看吧,想看带彩色的在编译器里看吧,页面实在调不出来了。
官方文档在:http://eagle.apache.org/docs/latest/getting-started/
源码中文档在E:\code\eagle\eagle-master-0.5.0-SNAPSHOT\docs\docs\目录下。
使用了Dropwizard框架,框架的文档在:https://www.dropwizard.io/0.7.1/docs/manual/core.html#bundles
目录
a)GuiceBundleLoader.load()注册所有的Module
ApplicationProviderServiceImpl
ServerModule
ApplicationGuiceModule
ModuleRegistry
b)EntityRepositoryScanner注册所有的Entity
EntityRepository repo
EntityDefinitionManager.registerEntity
jersey().register注册REST接口对应的resources
一、相关操作使用rest接口进行
例如启动一个app
E:\code\eagle\eagle-master-0.5.0-SNAPSHOT\eagle-security\eagle-security-hdfs-auditlog\README.md
二、eagle-server.sh启动脚本
E:\code\eagle\eagle-master-0.5.0-SNAPSHOT\eagle-assembly\src\main\bin\eagle-server.sh
PROGRAM="java $JVM_OPTS -cp $EAGLE_CLASSPATH org.apache.eagle.server.ServerMain server ${CONFIGURATION_YML}"
org.apache.eagle.server.ServerMain就是主入口
三、ServerMain.java程序主入口
E:\code\eagle\eagle-master-0.5.0-SNAPSHOT\eagle-server\src\main\java\org\apache\eagle\server\ServerMain.java
main函数
System.out.println("\nStarting Eagle Server ...\n");
try {
new ServerApplication().run(args);
}
1、ServerApplication
1)initialize函数
LOG.debug("Loading and registering guice bundle");
GuiceBundle<ServerConfig> guiceBundle = GuiceBundleLoader.load();
bootstrap.addBundle(guiceBundle);
LOG.debug("Loading and registering static AssetsBundle on /assets");
bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html", "/"));
LOG.debug("Initializing guice injector context for current ServerApplication");
guiceBundle.getInjector().injectMembers(this);
EntityRepositoryScanner.scan();
a)GuiceBundleLoader.load()注册所有的Module
public static GuiceBundle<ServerConfig> load(List<Module> modules) {
/*
We use tow injectors, one is Dropwizard injector, the other injector is to instantiate ApplicationProvider and load sub modules from applications
so we need make Config and ApplicationProviderServiceImpl to have a global instance across multiple injectors
*/
// Eagle server module
Config config = ConfigFactory.load();
ApplicationProviderService appProviderSvc = new ApplicationProviderServiceImpl[c2] (config);
ServerModule serveBaseModule = new ServerModule[c3] (appProviderSvc);
// load application specific modules
ModuleRegistry registry = ApplicationExtensionLoader.load(serveBaseModule);
// add application specific modules
MetadataStore metadataStoreModule = MetadataStoreModuleFactory.getModule[c4] ();
List<Module> metadataExtensions = metadataStoreModule.getModules(registry);
int extensionNum = 0;
GuiceBundle.Builder<ServerConfig> builder = GuiceBundle.newBuilder();
if (metadataExtensions != null) {
extensionNum = metadataExtensions.size();
metadataExtensions.forEach(builder::addModule);
}
LOGGER.warn("Loaded