private RecordValue ofJobBatchRecord(LoggedEvent event) { final JobBatchRecord record = new JobBatchRecord(); event.readValue(record); final List<Long> jobKeys = StreamSupport.stream(record.jobKeys().spliterator(), false) .map(LongValue::getValue) .collect(Collectors.toList()); final List<JobRecordValue> jobs = StreamSupport.stream(record.jobs().spliterator(), false) .map(this::ofJobRecord) .collect(Collectors.toList()); return new JobBatchRecordValueImpl( objectMapper, asString(record.getType()), asString(record.getWorker()), Duration.ofMillis(record.getTimeout()), record.getAmount(), jobKeys, jobs, record.getTruncated()); }
private RecordValue ofJobBatchRecord(LoggedEvent event) { final JobBatchRecord record = new JobBatchRecord(); event.readValue(record); final List<Long> jobKeys = StreamSupport.stream(record.jobKeys().spliterator(), false) .map(LongValue::getValue) .collect(Collectors.toList()); final List<JobRecordValue> jobs = StreamSupport.stream(record.jobs().spliterator(), false) .map(this::ofJobRecord) .collect(Collectors.toList()); return new JobBatchRecordValueImpl( objectMapper, asString(record.getType()), asString(record.getWorker()), Duration.ofMillis(record.getTimeout()), record.getAmount(), jobKeys, jobs, record.getTruncated()); }
private boolean isValid(final JobBatchRecord record) { return record.getAmount() > 0 && record.getTimeout() > 0 && record.getType().capacity() > 0 && record.getWorker().capacity() > 0; }
private boolean isValid(final JobBatchRecord record) { return record.getAmount() > 0 && record.getTimeout() > 0 && record.getType().capacity() > 0 && record.getWorker().capacity() > 0; }
private void activateJobs( final TypedRecord<JobBatchRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) { final JobBatchRecord value = record.getValue(); final long jobBatchKey = streamWriter.getKeyGenerator().nextKey(); final AtomicInteger amount = new AtomicInteger(value.getAmount()); collectJobsToActivate(record, amount); // Collecting of jobs and update state and write ACTIVATED job events should be separate, // since otherwise this will cause some problems (weird behavior) with the reusing of objects // // ArrayProperty.add will give always the same object - state.activate will // set/use this object for writing the new job state activateJobs(streamWriter, value); streamWriter.appendFollowUpEvent(jobBatchKey, JobBatchIntent.ACTIVATED, value); responseWriter.writeEventOnCommand(jobBatchKey, JobBatchIntent.ACTIVATED, value, record); }
private void activateJobs( final TypedRecord<JobBatchRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) { final JobBatchRecord value = record.getValue(); final long jobBatchKey = streamWriter.getKeyGenerator().nextKey(); final AtomicInteger amount = new AtomicInteger(value.getAmount()); collectJobsToActivate(record, amount); // Collecting of jobs and update state and write ACTIVATED job events should be separate, // since otherwise this will cause some problems (weird behavior) with the reusing of objects // // ArrayProperty.add will give always the same object - state.activate will // set/use this object for writing the new job state activateJobs(streamWriter, value); streamWriter.appendFollowUpEvent(jobBatchKey, JobBatchIntent.ACTIVATED, value); responseWriter.writeEventOnCommand(jobBatchKey, JobBatchIntent.ACTIVATED, value, record); }