我开发了一个基于Akka的服务器,并喜欢Microkernel的想法。然而,当我使用Java和Maven查看实现细节时,我正在用一个简单的Java主启动类来换取一个特定于框架的解决方案,该解决方案承诺我不需要编写启动脚本,最后我发现它需要:
- 安装了Akka(否则我可以在没有安装Akka的情况下工作,只使用库)
- 我需要两个额外的与Maven相关的更改和一个额外的组装工件
- 我还需要一个"开始"脚本,那有什么意义呢
也许我错过了什么?但与普通的旧Java主解决方案相比,我看不到任何更简单的设置或优势。
更新:在得到答案后再思考。可能仍然有一个很好的例子可以根据Microkernel编写您的主类,以便将来可以通过Akka控制台启动它,例如
public class MapReduceServer implements Bootable {
//---------------------------------------------------------------
// public
//---------------------------------------------------------------
/**
* Default constructor simply initializes the system.
*/
public MapReduceServer() {
system = ActorSystem.create("MapReduceApp", ConfigFactory.
load().getConfig("MapReduceApp"));
}
//---------------------------------------------------------------
/**
* {@inheritDoc}
*/
@Override
public void startup() {
// create the list of reduce Actors
ActorRef reduceActor = system.actorOf(Props.create(ReduceActor.class)
.withRouter(new FromConfig()), "reduceActor");
// create the list of map Actors
ActorRef mapActor = system.actorOf(Props.create(MapActor.class, reduceActor).
withRouter(new FromConfig()), "mapActor");
// create the overall Master Actor that acts as the remote actor for clients
@SuppressWarnings("unused")
ActorRef masterActor = system.actorOf(
Props.create(MapReduceMasterActor.class, mapActor), "masterActor");
}
//---------------------------------------------------------------
/**
* {@inheritDoc}
*/
@Override
public void shutdown() {
system.shutdown();
}
//---------------------------------------------------------------
/**
* Main method
*
* @param args
*/
public static void main(String[] args) {
MapReduceServer mapReduceServer = null;
LOGGER.info("starting ...");
mapReduceServer = new MapReduceServer();
mapReduceServer.startup();
LOGGER.info("done");
}
当使用sbt时,Microkernel作为一种打包机制可以很方便,但对于Maven用户来说,我同意它不会增加任何价值。我认为您应该使用一个main类,并以maven的方式打包您的应用程序。
至少微内核为您保存了关机挂钩的定义(处理CTRL-C)。简单来说,这是你关心的问题。当然,这里没有什么特别或花哨的东西。