@Test public void testHandlingApplicationFinishedEvent() throws IOException { DeletionService delService = new DeletionService(null); NonAggregatingLogHandler aggregatingLogHandler = new NonAggregatingLogHandler(new InlineDispatcher(), delService, dirsHandler); dirsHandler.init(conf); dirsHandler.start(); delService.init(conf); delService.start(); aggregatingLogHandler.init(conf); aggregatingLogHandler.start(); aggregatingLogHandler.handle(new LogHandlerAppFinishedEvent(appId)); aggregatingLogHandler.stop(); aggregatingLogHandler.handle(new LogHandlerAppFinishedEvent(appId)); aggregatingLogHandler.close(); }
@SuppressWarnings("unchecked") @Override public void handle(LogHandlerEvent event) { switch (event.getType()) { case APPLICATION_STARTED: LogHandlerAppStartedEvent appStartedEvent = (LogHandlerAppStartedEvent) event; this.appOwners.put(appStartedEvent.getApplicationId(), appStartedEvent.getUser()); this.dispatcher.getEventHandler().handle( new ApplicationEvent(appStartedEvent.getApplicationId(), ApplicationEventType.APPLICATION_LOG_HANDLING_INITED)); break; case CONTAINER_FINISHED: break; case APPLICATION_FINISHED: LogHandlerAppFinishedEvent appFinishedEvent = (LogHandlerAppFinishedEvent) event; LOG.info("Scheduling Log Deletion for application: " + appFinishedEvent.getApplicationId() + ", with delay of " + this.deleteDelaySeconds + " seconds"); LogDeleterRunnable logDeleter = new LogDeleterRunnable(appOwners.remove(appFinishedEvent .getApplicationId()), appFinishedEvent.getApplicationId()); try { sched.schedule(logDeleter, this.deleteDelaySeconds, TimeUnit.SECONDS); } catch (RejectedExecutionException e) { logDeleter.run(); } break; default: ; } }
NonAggregatingLogHandler extends AbstractService implements
    LogHandler { @SuppressWarnings("unchecked") @Override public void handle(LogHandlerEvent event) { switch (event.getType()) { case APPLICATION_STARTED: LogHandlerAppStartedEvent appStartedEvent = (LogHandlerAppStartedEvent) event; this.appOwners.put(appStartedEvent.getApplicationId(), appStartedEvent.getUser()); this.dispatcher.getEventHandler().handle( new ApplicationEvent(appStartedEvent.getApplicationId(), ApplicationEventType.APPLICATION_LOG_HANDLING_INITED)); break; case CONTAINER_FINISHED: break; case APPLICATION_FINISHED: LogHandlerAppFinishedEvent appFinishedEvent = (LogHandlerAppFinishedEvent) event; LOG.info("Scheduling Log Deletion for application: " + appFinishedEvent.getApplicationId() + ", with delay of " + this.deleteDelaySeconds + " seconds"); LogDeleterRunnable logDeleter = new LogDeleterRunnable(appOwners.remove(appFinishedEvent .getApplicationId()), appFinishedEvent.getApplicationId()); try { sched.schedule(logDeleter, this.deleteDelaySeconds, TimeUnit.SECONDS); } catch (RejectedExecutionException e) { logDeleter.run(); } break; default: ; } } }
NonAggregatingLogHandler extends AbstractService implements
    LogHandler { @SuppressWarnings("unchecked") @Override public void handle(LogHandlerEvent event) { switch (event.getType()) { case APPLICATION_STARTED: LogHandlerAppStartedEvent appStartedEvent = (LogHandlerAppStartedEvent) event; this.appOwners.put(appStartedEvent.getApplicationId(), appStartedEvent.getUser()); this.dispatcher.getEventHandler().handle( new ApplicationEvent(appStartedEvent.getApplicationId(), ApplicationEventType.APPLICATION_LOG_HANDLING_INITED)); break; case CONTAINER_FINISHED: break; case APPLICATION_FINISHED: LogHandlerAppFinishedEvent appFinishedEvent = (LogHandlerAppFinishedEvent) event; LOG.info("Scheduling Log Deletion for application: " + appFinishedEvent.getApplicationId() + ", with delay of " + this.deleteDelaySeconds + " seconds"); LogDeleterRunnable logDeleter = new LogDeleterRunnable(appOwners.remove(appFinishedEvent .getApplicationId()), appFinishedEvent.getApplicationId()); try { sched.schedule(logDeleter, this.deleteDelaySeconds, TimeUnit.SECONDS); } catch (RejectedExecutionException e) { logDeleter.run(); } break; default: ; } } NonAggregatingLogHandler(Dispatcher dispatcher,
      DeletionService delService, LocalDirsHandlerService dirsHandler); }
NonAggregatingLogHandler extends AbstractService implements
    LogHandler { @SuppressWarnings("unchecked") @Override public void handle(LogHandlerEvent event) { switch (event.getType()) { case APPLICATION_STARTED: LogHandlerAppStartedEvent appStartedEvent = (LogHandlerAppStartedEvent) event; this.appOwners.put(appStartedEvent.getApplicationId(), appStartedEvent.getUser()); this.dispatcher.getEventHandler().handle( new ApplicationEvent(appStartedEvent.getApplicationId(), ApplicationEventType.APPLICATION_LOG_HANDLING_INITED)); break; case CONTAINER_FINISHED: break; case APPLICATION_FINISHED: LogHandlerAppFinishedEvent appFinishedEvent = (LogHandlerAppFinishedEvent) event; LOG.info("Scheduling Log Deletion for application: " + appFinishedEvent.getApplicationId() + ", with delay of " + this.deleteDelaySeconds + " seconds"); LogDeleterRunnable logDeleter = new LogDeleterRunnable(appOwners.remove(appFinishedEvent .getApplicationId()), appFinishedEvent.getApplicationId()); try { sched.schedule(logDeleter, this.deleteDelaySeconds, TimeUnit.SECONDS); } catch (RejectedExecutionException e) { logDeleter.run(); } break; default: ; } } NonAggregatingLogHandler(Dispatcher dispatcher,
      DeletionService delService, LocalDirsHandlerService dirsHandler); @SuppressWarnings("unchecked") @Override void handle(LogHandlerEvent event); }
NonAggregatingLogHandler extends AbstractService implements
    LogHandler { @SuppressWarnings("unchecked") @Override public void handle(LogHandlerEvent event) { switch (event.getType()) { case APPLICATION_STARTED: LogHandlerAppStartedEvent appStartedEvent = (LogHandlerAppStartedEvent) event; this.appOwners.put(appStartedEvent.getApplicationId(), appStartedEvent.getUser()); this.dispatcher.getEventHandler().handle( new ApplicationEvent(appStartedEvent.getApplicationId(), ApplicationEventType.APPLICATION_LOG_HANDLING_INITED)); break; case CONTAINER_FINISHED: break; case APPLICATION_FINISHED: LogHandlerAppFinishedEvent appFinishedEvent = (LogHandlerAppFinishedEvent) event; LOG.info("Scheduling Log Deletion for application: " + appFinishedEvent.getApplicationId() + ", with delay of " + this.deleteDelaySeconds + " seconds"); LogDeleterRunnable logDeleter = new LogDeleterRunnable(appOwners.remove(appFinishedEvent .getApplicationId()), appFinishedEvent.getApplicationId()); try { sched.schedule(logDeleter, this.deleteDelaySeconds, TimeUnit.SECONDS); } catch (RejectedExecutionException e) { logDeleter.run(); } break; default: ; } } NonAggregatingLogHandler(Dispatcher dispatcher,
      DeletionService delService, LocalDirsHandlerService dirsHandler); @SuppressWarnings("unchecked") @Override void handle(LogHandlerEvent event);  }