@Override public Map<String, AttributeValue> getNodes(WebsiteModel websiteModel) { try { ObjectMapper mapper = new ObjectMapper(); String string = mapper.writeValueAsString(websiteModel); Item item = new Item().withJSON(Utils.params.nodes, string); return InternalUtils.toAttributeValues(item); } catch (JsonProcessingException e) { LOG.error(e.getMessage()); } return new HashMap<>(); }
@Override public Mono<Map<String, Object>> getWebsites(String url) { return Mono.from(this.getItemResultMono(url)) .flatMap( (result) -> { if (result.getItem() != null) return Mono.just(result.getItem()); return this.putItemResultMono(url); }) .doOnError((throwable -> LOG.error(Utils.error.failed_get_website, url))) .map(InternalUtils::toSimpleMapValue); }
@Override protected void handle(final ILoggingEvent event, final String encoded) throws Exception { Item item = Item.fromJSON(encoded).withPrimaryKey(createEventId(event)); Map<String, AttributeValue> attributes = InternalUtils.toAttributeValues(item); PutItemRequest request = new PutItemRequest(table, attributes); String errorMessage = format("Appender '%s' failed to send logging event '%s' to DynamoDB table '%s'", getName(), event, table); CountDownLatch latch = new CountDownLatch(isAsyncParent() ? 0 : 1); dynamoDb.putItemAsync(request, new LoggingEventHandler<PutItemRequest, PutItemResult>(this, latch, errorMessage)); AppenderExecutors.awaitLatch(this, latch, getMaxFlushTime()); }
/** * This method is calling an internal API which could be changed over time. * It is only for use of this demo and not expected for external use. */ public static Map<String, Object> toSimpleMapValue( Map<String, AttributeValue> values) { return InternalUtils.toSimpleMapValue(values); }