private Object executeScheduledJob(final ProceedingJoinPoint pjp, final String type) throws Throwable { addTypeToStatCounter(type); JobExecutingData data = new JobExecutingData( type, statCounter.count(type)); String id = buildId(type, data.getProcessingThread()); events.active(id, data); SystemData retVal = null; long correlationId = r.nextLong(); eventBus.post(new JobStartEvent( correlationId, type)); try { retVal = Optional.ofNullable(((SystemData) pjp.proceed())) .map(sd -> sd.withCorrelationId(id)) .orElse(null); return retVal; } finally { logSystemEvent(pjp, type, data, retVal); retVal = Optional.ofNullable(retVal) .orElse(SystemData.builder() .correlationId("" + correlationId) .errors(0l) .processed(0l) .build()); eventBus.post(new JobCompleteEvent( correlationId, type, retVal.getErrors(), retVal.getProcessed())); } }
@Override public Future<Void> saveAndIncrement(T data) { String correlationId = "" + System.currentTimeMillis() + ":" + r.nextLong(); Supplier<MapX<String, String>> dataMap = () -> MapX.fromMap(HashMapBuilder.map(MANIFEST_COMPARATOR_DATA_WRITER_KEY, comparator.toString()) .build()); return Future.<Void> of(() -> { comparator.saveAndIncrement(data); return null; } , executorService) .peek(t -> bus.post(SystemData.<String, String> builder() .correlationId(correlationId) .dataMap(dataMap.get()) .errors(0) .processed(1) .build())); // add // recover // option // here // also // with // cyclops-react // 1.0.0-final }
@Override public SystemData<String, String> scheduleAndLog() { String correlationId = "" + System.currentTimeMillis() + ":" + r.nextLong(); Supplier<MapX<String, String>> dataMap = () -> MapX .fromMap(HashMapBuilder.map(MANIFEST_COMPARATOR_DATA_LOADER_KEY, comparator.toString()).build()); try { boolean changed = comparator.load(); return SystemData.<String, String>builder() .correlationId(correlationId) .dataMap(dataMap.get()) .errors(0) .processed(changed ? 1 : 0) .build(); } catch (Exception e) { return SystemData.<String, String>builder() .correlationId(correlationId) .dataMap(dataMap.get().plus("Error", e.getMessage())) .errors(1) .processed(0) .build(); } }
private Object executeScheduledJob(final ProceedingJoinPoint pjp, final String type) throws Throwable { addTypeToStatCounter(type); JobExecutingData data = new JobExecutingData( type, statCounter.count(type)); String id = buildId(type, data.getProcessingThread()); events.active(id, data); SystemData retVal = null; long correlationId = r.nextLong(); eventBus.post(new JobStartEvent( correlationId, type)); try { retVal = Optional.ofNullable(((SystemData) pjp.proceed())) .map(sd -> sd.withCorrelationId(id)) .orElse(null); return retVal; } finally { logSystemEvent(pjp, type, data, retVal); retVal = Optional.ofNullable(retVal) .orElse(SystemData.builder() .correlationId("" + correlationId) .errors(0l) .processed(0l) .build()); eventBus.post(new JobCompleteEvent( correlationId, type, retVal.getErrors(), retVal.getProcessed())); } }
@Override public SystemData<String, String> scheduleAndLog() { String correlationId = "" + System.currentTimeMillis() + ":" + r.nextLong(); Supplier<MapX<String, String>> dataMap = () -> MapX.fromMap(HashMapBuilder.map(MANIFEST_COMPARATOR_DATA_CLEANER_KEY, comparator.toString()) .build()); try { comparator.cleanAll(); return SystemData.<String, String> builder() .correlationId(correlationId) .dataMap(dataMap.get()) .errors(0) .processed(1) .build(); } catch (Exception e) { return SystemData.<String, String> builder() .correlationId(correlationId) .dataMap(dataMap.get() .plus("Error", e.getMessage())) .errors(1) .processed(0) .build(); } }
@Override public Future<T> loadAndGet() { String correlationId = "" + System.currentTimeMillis() + ":" + r.nextLong(); Supplier<MapX<String, String>> dataMap = () -> MapX.fromMap(HashMapBuilder.map(MANIFEST_COMPARATOR_DATA_LOADER_KEY, comparator.toString()) .build()); return Future.of(() -> Tuple.tuple(comparator.load(), comparator.getData()), executorService) .peek(t -> bus.post(SystemData.<String, String> builder() .correlationId(correlationId) .dataMap(dataMap.get()) .errors(0) .processed(t._1() ? 1 : 0) .build())) // add // recover // option // here // also // with // cyclops-react // 1.0.0-final .map(t -> t._2()); }
@Override public SystemData scheduleAndLog() { return SystemData.builder().errors(0).processed(2).build(); }
@Override public SystemData<String,String> scheduleAndLog() { return SystemData.<String,String>builder().errors(0).processed(2).build(); }
@Before public void setUp() throws Exception { data = SystemData.builder() .dataMap(Maps.newHashMap()) .errors(1) .processed(100) .build(); bus = new EventBus(); bus.register(this); jobs = new JobsBeingExecuted( bus, 10, JobName.Types.SIMPLE); pjp = Mockito.mock(ProceedingJoinPoint.class); }
@Override public SystemData scheduleAndLog() { return SystemData.builder().errors(0).processed(2).build(); }
@Override public SystemData<String,String> scheduleAndLog() { return SystemData.<String,String>builder().errors(0).processed(2).build(); }
@Override public SystemData<String, String> scheduleAndLog() { return SystemData.<String, String> builder() .errors(0) .processed(2) .build(); }