我开发了一个基于Akka的服务器,并喜欢Microkernel的想法.但是,当我使用Java和Maven查看实现细节时,我在一个简单的Java主要启动类中交换一个框架特定的解决方案,承诺我不需要编写启动脚本,最后我发现它需要:
也许我错过了什么?但与普通的旧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");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
912 次 |
| 最近记录: |