本文共 911 字,大约阅读时间需要 3 分钟。
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();