Apache Twill 是一个 Apache Hadoop YARN 的抽象层,减少了开发分布式应用程序的复杂度,允许开发者把精力放在应用逻辑上。Apache Twill 可以让你向使用线程一样来使用 YarN 的分布式编程模型。
示例代码:
public class EchoServer implements TwillRunnable { private static Logger LOG = LoggerFacTory.getLogger(EchoServer.class); private final ServerSocket serverSocket; private final int port; public EchoServer() { ... } @Override public void run() { while ( isRunNing() ) { Socket socket = serverSocket.accept(); ... } } }
运行:
TwillRunnerServICE runnerService = new YarnTwillRunnerService( new YarnConfiguRATion(), ZKConNECtStr); runnerService.startAndWait(); TwillController controller = runnerService.prepare(new EchoServer()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out))) .start(); controller.addListener(new ListenerAdapter() { @Override public void running() { LOG.info('Echo Server Started'); } } controller.stop().get();
发布于 2017-04-08 23:48:57 | 98 次阅读