@Override @SuppressWarnings(value = "unchecked") public void writeRecords(Batch batch) throws Exception { for (Record record : batch) { collection.add(record.getPayload()); } }
@Override public void writeRecords(Batch batch) throws Exception { for (Record record : batch) { stringWriter.write(record.getPayload().toString()); stringWriter.write(Utils.LINE_SEPARATOR); } stringWriter.flush(); }
/** * Extract the payload form each record. * * @param records the list of records * @param <P> the type of payload * @return the list of payloads */ public static <P> List<P> extractPayloads(final List<? extends Record<P>> records) { List<P> payloads = new ArrayList<>(); for (Record<P> record : records) { payloads.add(record.getPayload()); } return payloads; }
@Override public void writeRecords(Batch batch) throws Exception { for (Record record : batch) { outputStreamWriter.write(record.getPayload().toString()); outputStreamWriter.write(lineSeparator); } outputStreamWriter.flush(); }
@Override public void writeRecords(Batch batch) throws Exception { for (Record record : batch) { queueSender.send((Message) record.getPayload()); } }
@Override public void writeRecords(Batch batch) throws Exception { for (Record record : batch) { for (QueueSender queue : queues) { queue.send((Message) record.getPayload()); } } }
@Override public void writeRecords(Batch batch) throws Exception { for (Record record : batch) { //dispatch record randomly to one of the queues QueueSender queue = queues.get(random.nextInt(queuesNumber)); queue.send((Message) record.getPayload()); } }
@Override public void writeRecords(Batch batch) throws Exception { for (Record record : batch) { //dispatch records to queues in round-robin fashion QueueSender queue = queues.get(next++ % queuesNumber); queue.send((Message) record.getPayload()); } }
@Override public Record processRecord(Record record) throws Exception { Set<ConstraintViolation<Object>> constraintViolationSet = validator.validate(record.getPayload()); if (!constraintViolationSet.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); for (ConstraintViolation<Object> constraintViolation : constraintViolationSet) { stringBuilder .append("Invalid value '").append(constraintViolation.getInvalidValue()).append("' ") .append("for property '").append(constraintViolation.getPropertyPath()).append("' : ") .append(constraintViolation.getMessage()) .append(Utils.LINE_SEPARATOR); } throw new Exception(stringBuilder.toString()); } return record; } }
@Override public XmlRecord processRecord(final Record<P> record) { return new XmlRecord(record.getHeader(), xStream.toXML(record.getPayload())); } }
@Override public StringRecord processRecord(final Record<P> record) throws Exception { Iterable<Object> values = fieldExtractor.extractFields(record.getPayload()); StringBuilder stringBuilder = new StringBuilder(); Iterator<?> iterator = values.iterator(); while (iterator.hasNext()) { Object value = iterator.next(); stringBuilder.append(qualifier); stringBuilder.append(value); stringBuilder.append(qualifier); if (iterator.hasNext()) { stringBuilder.append(delimiter); } } return new StringRecord(record.getHeader(), stringBuilder.toString()); } }
@Override public void writeRecords(Batch batch) throws Exception { QueueSender defaultQueue = queueMap.get(new DefaultPredicate()); for (Record record : batch) { boolean matched = false; Message payload = (Message) record.getPayload(); for (Map.Entry<Predicate, QueueSender> entry : queueMap.entrySet()) { Predicate predicate = entry.getKey(); //check if the record meets a given predicate if (!(predicate instanceof DefaultPredicate) && predicate.matches(record)) { //put it in the mapped queue queueMap.get(predicate).send(payload); matched = true; break; } } //if the record does not match any predicate, then put it in the default queue if (!matched && defaultQueue != null) { defaultQueue.send(payload); } } }