@Override public void apply(JobListener jobListener, JobContext jobContext) throws Exception { jobListener.onJobCancellation(jobContext); } });
@Override public Void call() throws Exception { jobListener.onJobCancellation(jobContext); return null; } });
@Override public void onJobCancellation(JobContext jobContext) throws Exception { StringBuffer buf = new StringBuffer(); for (JobListener listener: listeners) { try { listener.onJobCancellation(jobContext); } catch (Exception e) { buf.append(listener.getClass().getName() + ":" + e.toString()); log.error(ExceptionUtils.getFullStackTrace(e)); } } String exceptions = buf.toString(); if (!exceptions.isEmpty()) { throw new RuntimeException(exceptions); } }
@Test public void testParallelJobListener() throws Exception { JobContext jobContext = mock(JobContext.class); JobListener mockJobListener1 = mock(JobListener.class); JobListener mockJobListener2 = mock(JobListener.class); CloseableJobListener closeableJobListener = JobListeners.parallelJobListener(Lists.newArrayList(mockJobListener1, mockJobListener2)); closeableJobListener.onJobCompletion(jobContext); closeableJobListener.onJobCancellation(jobContext); closeableJobListener.close(); verify(mockJobListener1, times(1)).onJobCompletion(jobContext); verify(mockJobListener1, times(1)).onJobCancellation(jobContext); verify(mockJobListener2, times(1)).onJobCompletion(jobContext); verify(mockJobListener2, times(1)).onJobCancellation(jobContext); } }
@Override public Void call() throws Exception { jobListener.onJobCancellation(jobContext); return null; } });
@Override public void apply(JobListener jobListener, JobContext jobContext) throws Exception { jobListener.onJobCancellation(jobContext); } });
@Override public void onJobCancellation(JobContext jobContext) throws Exception { StringBuffer buf = new StringBuffer(); for (JobListener listener: listeners) { try { listener.onJobCancellation(jobContext); } catch (Exception e) { buf.append(listener.getClass().getName() + ":" + e.toString()); log.error(ExceptionUtils.getFullStackTrace(e)); } } String exceptions = buf.toString(); if (!exceptions.isEmpty()) { throw new RuntimeException(exceptions); } }