Search in sources :

Example 21 with Data

use of lombok.Data in project completable-reactor by ru-fix.

the class CompletableReactorHandlerArgumentsTest method arguments_test_5.

@Test
public void arguments_test_5() throws Exception {
    @Reactored("Payload with string")
    @Data
    class Payload {

        String data;
    }
    class Service {

        @Reactored("method with 6 arguments")
        public CompletableFuture<String> foo(String arg1, short arg2, boolean arg3, BigInteger arg4, long arg5) {
            return CompletableFuture.completedFuture(arg1 + arg2 + arg3 + arg4 + arg5);
        }
    }
    final Service service = new Service();
    class Config {

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).passArg(pld -> "1").passArg(pld -> (short) 3).passArg(pld -> true).passArg(pld -> BigInteger.valueOf(6L)).passArg(pld -> 7L).withHandler(service::foo).withMerger((payload, result) -> {
            payload.data = result;
            return CompletableReactorTest.Status.OK;
        }).buildProcessor();

        ReactorGraph<Payload> graph() {
            return graphBuilder.payload(Payload.class).handle(processor).mergePoint(processor).onAny().complete().coordinates().buildGraph();
        }
    }
    val graph = new Config().graph();
    reactor.registerReactorGraph(graph);
    assertEquals("13true67", reactor.submit(new Payload()).getResultFuture().get(5, TimeUnit.SECONDS).getData());
}
Also used : Reactored(ru.fix.completable.reactor.api.Reactored) lombok.val(lombok.val) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) CompletableReactor(ru.fix.completable.reactor.runtime.CompletableReactor) TimeUnit(java.util.concurrent.TimeUnit) ReactorGraph(ru.fix.completable.reactor.runtime.ReactorGraph) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Data(lombok.Data) BigInteger(java.math.BigInteger) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) SimpleProfiler(ru.fix.commons.profiler.impl.SimpleProfiler) lombok.val(lombok.val) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) Reactored(ru.fix.completable.reactor.api.Reactored) BigInteger(java.math.BigInteger) Data(lombok.Data) Test(org.junit.Test)

Example 22 with Data

use of lombok.Data in project completable-reactor by ru-fix.

the class CompletableReactorHandlerArgumentsTest method arguments_test_1.

@Test
public void arguments_test_1() throws Exception {
    @Reactored("Payload with string")
    @Data
    class Payload {

        String data;
    }
    class Service {

        @Reactored("method with 6 arguments")
        public CompletableFuture<String> foo(long arg) {
            return CompletableFuture.completedFuture("" + arg);
        }
    }
    final Service service = new Service();
    class Config {

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).passArg(pld -> 7L).withHandler(service::foo).withMerger((payload, result) -> {
            payload.data = result;
            return CompletableReactorTest.Status.OK;
        }).buildProcessor();

        ReactorGraph<Payload> graph() {
            return graphBuilder.payload(Payload.class).handle(processor).mergePoint(processor).onAny().complete().coordinates().buildGraph();
        }
    }
    reactor.registerReactorGraph(new Config().graph());
    assertEquals("7", reactor.submit(new Payload()).getResultFuture().get(5, TimeUnit.SECONDS).getData());
}
Also used : ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) Reactored(ru.fix.completable.reactor.api.Reactored) Data(lombok.Data) Test(org.junit.Test)

Example 23 with Data

use of lombok.Data in project completable-reactor by ru-fix.

the class ReactorGraphExecutionBuilder method build.

/**
 * @param reactorGraph
 * @param <PayloadType>
 * @return
 */
public <PayloadType> ReactorGraphExecution<PayloadType> build(ReactorGraph<PayloadType> reactorGraph) {
    val crReactorGraph = (CRReactorGraph<PayloadType>) reactorGraph;
    /**
     * Internal representation of processing graph based on processing vertices.
     */
    final Map<CRProcessingItem, ProcessingVertex> processingVertices = new HashMap<>();
    final CompletableFuture<PayloadType> submitFuture = new CompletableFuture<>();
    /**
     * Will be completed on payload submission to processor chain
     */
    final CompletableFuture<ReactorGraphExecutionBuilder.TransitionPayloadContext> startPointTransitionFuture = submitFuture.thenApplyAsync(payload -> new TransitionPayloadContext().setPayload(payload));
    /**
     * Will be completed with payload when terminal graph state would be reached.
     */
    final CompletableFuture<PayloadType> executionResultFuture = new CompletableFuture<>();
    /**
     * Init Processing Vertices.
     */
    crReactorGraph.getProcessingItems().forEach((proc, info) -> {
        ProcessingVertex vertex = new ProcessingVertex().setProcessingItem(proc).setProcessingItemInfo(info);
        if (info.getProcessingItemType() == CRReactorGraph.ProcessingItemType.MERGE_POINT) {
            /**
             * Detached merge point does not uses {@code {@link ProcessingVertex#getProcessorFuture()}
             */
            vertex.getProcessorFuture().completeExceptionally(new IllegalStateException(String.format("Detached Merge Point %s should not use processorFuture.", vertex.getProcessingItem().getDebugName())));
        }
        processingVertices.put(proc, vertex);
    });
    /**
     * Populate start point transition
     */
    for (CRProcessingItem processor : crReactorGraph.getStartPoint().getProcessingItems()) {
        ProcessingVertex vertex = processingVertices.get(processor);
        if (vertex.getProcessingItemInfo().getProcessingItemType() == CRReactorGraph.ProcessingItemType.MERGE_POINT) {
            /**
             * In case of Detached merge point transition from start point is being converted
             * to a {@link MergePayloadContext}
             */
            vertex.getIncomingMergeFlows().add(new TransitionFuture<>(startPointTransitionFuture.thenApplyAsync(transitionPayloadContext -> new MergePayloadContext().setDeadTransition(transitionPayloadContext.isDeadTransition()).setTerminal(transitionPayloadContext.isTerminal()).setPayload(transitionPayloadContext.getPayload()).setMergeResult(null))));
        } else {
            vertex.getIncomingProcessorFlows().add(new TransitionFuture<>(startPointTransitionFuture));
        }
    }
    /**
     * Populate MergePoints
     */
    crReactorGraph.getMergePoints().forEach(mergePoint -> {
        ProcessingVertex mergePointVertex = processingVertices.get(mergePoint.asProcessingItem());
        mergePoint.getTransitions().forEach(mergePointVertex.getMergePointTransition()::add);
    });
    /**
     * Populate transitions to all MergePoints
     */
    crReactorGraph.getMergePoints().forEach(mergePoint -> {
        ProcessingVertex mergePointVertex = processingVertices.get(mergePoint.asProcessingItem());
        mergePoint.getTransitions().forEach(mergePointVertex.getMergePointTransition()::add);
    });
    /**
     * Populate outgoing flows
     */
    for (CRReactorGraph.MergePoint mergePoint : crReactorGraph.getMergePoints()) {
        /**
         * MergeGroup can contain more that one MergePoint, so we have to wait all merge points to complete before
         * invoke processors.
         * We should not wait all merge point to complete if we are invoking other merge point within mergeGroup.
         */
        ProcessingVertex mergePointVertex = processingVertices.get(mergePoint.asProcessingItem());
        CompletableFuture<MergePayloadContext> mergePointFuture = mergePointVertex.getMergePointFuture();
        for (CRReactorGraph.Transition transition : mergePoint.getTransitions()) {
            /**
             * Terminal merge point vertex handled synchronously with merging process
             * Skip that kind of transition during pre-processing.
             */
            if (!transition.isComplete()) {
                /**
                 * Populate outgoing processor flows
                 * activates when all merge points within merge group is completed
                 */
                if (transition.getHandleBy() != null) {
                    CRProcessingItem proc = transition.getHandleBy();
                    processingVertices.get(proc).getIncomingProcessorFlows().add(new TransitionFuture<>(mergePointFuture.thenApplyAsync(context -> {
                        if (context.isTerminal()) {
                            return new TransitionPayloadContext().setTerminal(true);
                        } else if (context.isDeadTransition()) {
                            return new TransitionPayloadContext().setDeadTransition(true);
                        } else if (transition.isOnAny() || transition.getMergeStatuses().contains(context.mergeResult)) {
                            return new TransitionPayloadContext().setPayload(context.payload);
                        } else {
                            return new TransitionPayloadContext().setPayload(context.payload).setDeadTransition(true);
                        }
                    }).exceptionally(exc -> {
                        log.error("Failed to activate");
                        return null;
                    })));
                }
                /**
                 * Populate outgoing merge flows
                 */
                if (transition.getMerge() != null) {
                    CRProcessingItem proc = transition.getMerge();
                    ProcessingVertex transitionDestinationVertex = processingVertices.get(proc);
                    transitionDestinationVertex.getIncomingMergeFlows().add(new TransitionFuture<>(mergePointFuture.thenApplyAsync(context -> {
                        if (context.isTerminal()) {
                            return new MergePayloadContext().setTerminal(true);
                        } else if (context.isDeadTransition()) {
                            return new MergePayloadContext().setDeadTransition(true);
                        } else if (transition.isOnAny() || transition.getMergeStatuses().contains(context.mergeResult)) {
                            return new MergePayloadContext().setPayload(context.payload).setMergeResult(context.mergeResult);
                        } else {
                            return new MergePayloadContext().setDeadTransition(true);
                        }
                    })));
                }
            }
        }
    }
    // TODO FIX!! allow detached processor to read data from payload and only after that execute merge point
    // down the flow, so merge point and detached processor would not run concurrently
    /**
     * Join incoming processor flows to single processor invocation
     */
    processingVertices.forEach((processor, processingItem) -> {
        if (processingItem.getProcessingItemInfo().getProcessingItemType() == CRReactorGraph.ProcessingItemType.MERGE_POINT) {
            /**
             * Detached merge point does not have graph processor, only merge point.
             * No processor invocation is needed
             */
            if (processingItem.getIncomingProcessorFlows().size() != 0) {
                throw new IllegalStateException(String.format("Invalid graph state. Detached merge point %s have more than 0 incoming flows.", processor.getDebugName()));
            }
            return;
        }
        if (processingItem.getIncomingProcessorFlows().size() <= 0) {
            throw new IllegalArgumentException(String.format("Invalid graph descriptor. Processor %s does not have incoming flows." + " Probably missing handleBy directive for this processor.", processor.getDebugName()));
        }
        CompletableFuture.allOf(processingItem.getIncomingProcessorFlows().stream().map(TransitionFuture::getFuture).toArray(CompletableFuture[]::new)).thenRunAsync(() -> {
            List<TransitionPayloadContext> incomingFlows = processingItem.getIncomingProcessorFlows().stream().map(future -> {
                try {
                    /**
                     * Future should be already complete
                     */
                    if (!future.getFuture().isDone()) {
                        Exception resultException = new Exception(String.format("Illegal graph execution state." + " Future is not completed. Processor: %s", processingItem.getProcessingItem().getDebugName()));
                        log.error(resultException.getMessage(), resultException);
                        executionResultFuture.completeExceptionally(resultException);
                        return INVALID_TRANSITION_PAYLOAD_CONTEXT;
                    } else {
                        return future.getFuture().get();
                    }
                } catch (Exception exc) {
                    Exception resultException = new Exception(String.format("Failed to get incoming processor flow future result" + " for processor: %s", processingItem.getProcessingItem().getDebugName()), exc);
                    log.error(resultException.getMessage(), resultException);
                    executionResultFuture.completeExceptionally(resultException);
                    return INVALID_TRANSITION_PAYLOAD_CONTEXT;
                }
            }).collect(Collectors.toList());
            if (incomingFlows.stream().anyMatch(context -> context == INVALID_TRANSITION_PAYLOAD_CONTEXT)) {
                /**
                 * Invalid graph execution state
                 * Mark as terminal all outgoing flows from processor
                 */
                processingItem.getProcessorFuture().complete(new HandlePayloadContext().setTerminal(true));
            } else if (incomingFlows.stream().anyMatch(TransitionPayloadContext::isTerminal)) {
                /**
                 * Terminal state reached.
                 * Mark as terminal all outgoing flows from processor
                 */
                processingItem.getProcessorFuture().complete(new HandlePayloadContext().setTerminal(true));
            } else {
                List<TransitionPayloadContext> activeIncomingFlows = incomingFlows.stream().filter(context -> !context.isDeadTransition()).collect(Collectors.toList());
                if (activeIncomingFlows.size() <= 0) {
                    /**
                     * There is no active incoming flow for given processor.
                     * Processor will not be invoked.
                     * All outgoing flows from processor will be marked as dead.
                     */
                    processingItem.getProcessorFuture().complete(new HandlePayloadContext().setDeadTransition(true));
                } else {
                    if (activeIncomingFlows.size() > 1) {
                        /**
                         * Illegal graph state. Too many active incoming flows.
                         * Mark as terminal all outgoing flows
                         * Complete graph with exception
                         */
                        Exception tooManyActiveIncomingFlowsExc = new Exception(String.format("There is more than one active incoming flow for processor %s." + " Reactor can not determinate from which of transitions" + " take payload." + " Possible loss of computation results." + " Possible concurrent modifications of payload.", processingItem.getProcessingItem().getDebugName()));
                        executionResultFuture.completeExceptionally(tooManyActiveIncomingFlowsExc);
                        processingItem.getProcessorFuture().complete(new HandlePayloadContext().setTerminal(true));
                    } else {
                        handle(processingItem, activeIncomingFlows.get(0), executionResultFuture);
                    }
                }
            }
        }).exceptionally(throwable -> {
            log.error("Join incoming processor flows failed.", throwable);
            return null;
        });
    });
    // processingVertices
    /**
     * Join incoming merge flows and processor handing future with single merging invocation
     */
    processingVertices.forEach((processor, vertex) -> {
        List<CompletableFuture> incomingFlows = new ArrayList<>();
        vertex.getIncomingMergeFlows().stream().map(TransitionFuture::getFuture).forEach(incomingFlows::add);
        if (vertex.getProcessingItemInfo().getProcessingItemType() != CRReactorGraph.ProcessingItemType.MERGE_POINT) {
            /**
             * Ignore processor future for detached merge point
             * And use it for all other cases
             */
            incomingFlows.add(vertex.getProcessorFuture());
        }
        CompletableFuture.allOf(incomingFlows.toArray(new CompletableFuture[incomingFlows.size()])).thenRunAsync(() -> {
            /**
             * Processor result, could be INVALID_HANDLE_PAYLOAD_CONTEXT in case of exception
             * Could be NULL in case of detached merge point
             */
            HandlePayloadContext handlePayloadContext = null;
            if (vertex.getProcessingItemInfo().getProcessingItemType() != CRReactorGraph.ProcessingItemType.MERGE_POINT) {
                handlePayloadContext = Optional.of(vertex.getProcessorFuture()).map(future -> {
                    try {
                        if (!future.isDone()) {
                            RuntimeException resultException = new RuntimeException(String.format("Illegal graph execution state. Processor future" + " is not completed. Processor %s", vertex.getProcessingItem().getDebugName()));
                            log.error(resultException.getMessage(), resultException);
                            executionResultFuture.completeExceptionally(resultException);
                            return INVALID_HANDLE_PAYLOAD_CONTEXT;
                        } else {
                            return future.get();
                        }
                    } catch (Exception exc) {
                        RuntimeException resultException = new RuntimeException(String.format("Failed to get processor future result for processor: %s", vertex.getProcessingItem().getDebugName()), exc);
                        log.error(resultException.getMessage(), resultException);
                        executionResultFuture.completeExceptionally(resultException);
                        return INVALID_HANDLE_PAYLOAD_CONTEXT;
                    }
                }).orElse(INVALID_HANDLE_PAYLOAD_CONTEXT);
                if (handlePayloadContext == INVALID_HANDLE_PAYLOAD_CONTEXT) {
                    /**
                     * Failed to get processor result.
                     * Merging will not be applied to payload.
                     * All outgoing flows from merge point will be marked as terminal.
                     * executionResult completed by exception
                     */
                    vertex.getMergePointFuture().complete(new MergePayloadContext().setTerminal(true));
                    return;
                } else if (handlePayloadContext.isTerminal()) {
                    /**
                     * Processor was marked as terminal during flow by terminal transition.
                     * Merging will not be applied to payload.
                     * All outgoing flows from merge point will be marked as terminal.
                     */
                    vertex.getMergePointFuture().complete(new MergePayloadContext().setTerminal(true));
                    return;
                } else if (handlePayloadContext.isDeadTransition()) {
                    /**
                     * Processor was disabled during flow by dead transition.
                     * Merging will not be applied to payload.
                     * All outgoing flows from merge point will be marked as dead.
                     */
                    vertex.getMergePointFuture().complete(new MergePayloadContext().setDeadTransition(true));
                    return;
                }
            }
            /**
             * Incoming merge flows, could be empty for processors Merge Point
             */
            List<MergePayloadContext> incomingMergeFlows = vertex.getIncomingMergeFlows().stream().map(future -> {
                try {
                    if (!future.getFuture().isDone()) {
                        RuntimeException resultException = new RuntimeException(String.format("Illegal graph execution state. Incoming merge future" + " is not complete." + " ProcessingVertex: %s", vertex));
                        log.error(resultException.getMessage(), resultException);
                        executionResultFuture.completeExceptionally(resultException);
                        return INVALID_MERGE_PAYLOAD_CONTEXT;
                    } else {
                        return future.getFuture().get();
                    }
                } catch (Exception exc) {
                    RuntimeException resultException = new RuntimeException(String.format("Failed to get incoming merge flow future result for processor: %s", vertex.getProcessingItem().getDebugName()), exc);
                    log.error(resultException.getMessage(), resultException);
                    executionResultFuture.completeExceptionally(resultException);
                    return INVALID_MERGE_PAYLOAD_CONTEXT;
                }
            }).collect(Collectors.toList());
            if (incomingMergeFlows.stream().anyMatch(context -> context == INVALID_MERGE_PAYLOAD_CONTEXT)) {
                /**
                 * Exception during merging
                 * Mark as terminal all outgoing flows from merge point
                 */
                vertex.getMergePointFuture().complete(new MergePayloadContext().setTerminal(true));
            } else if (incomingMergeFlows.stream().anyMatch(MergePayloadContext::isTerminal)) {
                /**
                 * Terminal state reached.
                 * Mark as terminal all outgoing flows from merge point
                 */
                vertex.getMergePointFuture().complete(new MergePayloadContext().setTerminal(true));
            } else {
                final List<MergePayloadContext> activeIncomingMergeFlows = incomingMergeFlows.stream().filter(context -> !context.isDeadTransition()).collect(Collectors.toList());
                if (vertex.getProcessingItemInfo().getProcessingItemType() == CRReactorGraph.ProcessingItemType.MERGE_POINT) {
                    /**
                     * Detached merge point
                     */
                    if (activeIncomingMergeFlows.size() == 0) {
                        /**
                         * Check that there are at least one incoming transition that marked as dead
                         */
                        if (incomingMergeFlows.stream().anyMatch(MergePayloadContext::isDeadTransition)) {
                            /**
                             * Detached MergePoint marked as Dead, because there are no active incoming
                             * flows and there is at least one incoming dead transition
                             * Mark as dead all outgoing flows from merge point
                             */
                            vertex.getMergePointFuture().complete(new MergePayloadContext().setDeadTransition(true));
                        } else {
                            throw new IllegalStateException(String.format("There is no incoming merge flows for detached merge point %s." + " At least dead incoming transition expected.", vertex.getProcessingItem().getDebugName()));
                        }
                    } else {
                        if (activeIncomingMergeFlows.size() > 1) {
                            /**
                             * Illegal graph state. Too many active incoming flows.
                             * Mark as terminal all outgoing flows from merge point
                             * Complete graph with exception
                             */
                            Exception tooManyActiveIncomingFlowsExc = new Exception(String.format("There is more than one active incoming flow for routing point %s." + " Reactor can not determinate from which of transitions take" + " payload." + " Possible loss of computation results." + " Possible concurrent modifications of payload.", vertex.getProcessingItem().getDebugName()));
                            executionResultFuture.completeExceptionally(tooManyActiveIncomingFlowsExc);
                            vertex.getMergePointFuture().complete(new MergePayloadContext().setTerminal(true));
                        } else {
                            /**
                             * Single active incoming merge flow
                             */
                            merge(vertex, Optional.empty(), activeIncomingMergeFlows.get(0).getPayload(), executionResultFuture);
                        }
                    }
                } else {
                    /**
                     * Processors MergePoint
                     */
                    if (incomingMergeFlows.size() == 0) {
                        /**
                         * No incoming merge flows, only one flow from processors handle
                         */
                        merge(vertex, handlePayloadContext.getProcessorResult(), handlePayloadContext.getPayload(), executionResultFuture);
                    } else {
                        /**
                         * Incoming merge flows exists. But some of them can be marked as dead.
                         */
                        if (activeIncomingMergeFlows.size() == 0) {
                            /**
                             * There is no active incoming merge flow for given merge point.
                             * Mark merge point as dead.
                             */
                            vertex.getMergePointFuture().complete(new MergePayloadContext().setDeadTransition(true));
                        } else {
                            if (activeIncomingMergeFlows.size() > 1) {
                                /**
                                 * Illegal graph state. Too many active incoming flows.
                                 * Mark as terminal all outgoing flows from merge point
                                 * Complete graph with exception
                                 */
                                Exception tooManyActiveIncomingFlowsExc = new Exception(String.format("There is more than one active incoming flow for merge point for" + " processor %s." + " Reactor can not determinate from which of transitions" + " take payload." + " Possible loss of computation results." + " Possible concurrent modifications of payload.", vertex.getProcessingItem().getDebugName()));
                                executionResultFuture.completeExceptionally(tooManyActiveIncomingFlowsExc);
                                vertex.getMergePointFuture().complete(new MergePayloadContext().setTerminal(true));
                            } else {
                                merge(vertex, handlePayloadContext.getProcessorResult(), activeIncomingMergeFlows.get(0).getPayload(), executionResultFuture);
                            }
                        }
                    }
                }
            }
        }).exceptionally(throwable -> {
            log.error("Joining incoming merge flows failed.", throwable);
            return null;
        });
    });
    // processingVertices
    /**
     * Handle terminal vertices.
     * When execution reaches 'complete' vertex all transitions should be marked dead and complete.
     */
    executionResultFuture.thenRunAsync(() -> {
        processingVertices.entrySet().stream().map(Map.Entry::getValue).map(ProcessingVertex::getIncomingProcessorFlows).flatMap(Collection::stream).map(TransitionFuture::getFuture).forEach(future -> future.complete(new TransitionPayloadContext().setDeadTransition(true)));
        processingVertices.entrySet().stream().map(Map.Entry::getValue).map(ProcessingVertex::getIncomingProcessorFlows).flatMap(Collection::stream).map(TransitionFuture::getFuture).forEach(future -> future.complete(new TransitionPayloadContext().setDeadTransition(true)));
    }).exceptionally(throwable -> {
        log.error("Marking transitions as dead is failed.", throwable);
        return null;
    });
    /**
     * Collect chain execution processor handling futures
     * Processors futures holds handle invocation result or dead context.
     * Exception is an detached merge point which processorFuture is not used
     * Then all processors futures completes chainExecutionFuture completes too.
     */
    CompletableFuture<Void> chainExecutionFuture = CompletableFuture.allOf(processingVertices.entrySet().stream().map(Map.Entry::getValue).filter(vertex -> vertex.getProcessingItemInfo().getProcessingItemType() != CRReactorGraph.ProcessingItemType.MERGE_POINT).map(ProcessingVertex::getProcessorFuture).toArray(CompletableFuture[]::new));
    return new ReactorGraphExecution<PayloadType>(submitFuture, executionResultFuture, chainExecutionFuture, debugProcessingVertexGraphState ? processingVertices.values() : null);
}
Also used : ReactorGraphModel(ru.fix.completable.reactor.api.ReactorGraphModel) java.util(java.util) Accessors(lombok.experimental.Accessors) ProfiledCall(ru.fix.commons.profiler.ProfiledCall) lombok.val(lombok.val) CompletableFuture(java.util.concurrent.CompletableFuture) CRProcessingItem(ru.fix.completable.reactor.runtime.internal.CRProcessingItem) ThreadsafeCopyMaker(ru.fix.completable.reactor.runtime.cloning.ThreadsafeCopyMaker) ImmutabilityChecker(ru.fix.completable.reactor.runtime.immutability.ImmutabilityChecker) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) CRProcessorDescription(ru.fix.completable.reactor.runtime.internal.dsl.CRProcessorDescription) Slf4j(lombok.extern.slf4j.Slf4j) ReactorGraph(ru.fix.completable.reactor.runtime.ReactorGraph) ImmutabilityControlLevel(ru.fix.completable.reactor.runtime.immutability.ImmutabilityControlLevel) DebugSerializer(ru.fix.completable.reactor.runtime.debug.DebugSerializer) Tracer(ru.fix.completable.reactor.runtime.tracing.Tracer) CRReactorGraph(ru.fix.completable.reactor.runtime.internal.CRReactorGraph) ProfilerNames(ru.fix.completable.reactor.runtime.ProfilerNames) Data(lombok.Data) Profiler(ru.fix.commons.profiler.Profiler) CompletableFuture(java.util.concurrent.CompletableFuture) lombok.val(lombok.val) CRReactorGraph(ru.fix.completable.reactor.runtime.internal.CRReactorGraph) CRProcessingItem(ru.fix.completable.reactor.runtime.internal.CRProcessingItem)

Example 24 with Data

use of lombok.Data in project tomee by apache.

the class GenerateBoms method asDistribution.

/**
 * Extract the zip that represents a TomEE distribution.  Find
 * all jar files.  Match them up with jars in the local Maven
 * repository.  Identify any jars we could not match.  And finally,
 * return all the data so we have a canonical representation of
 * the distribution.
 */
private Distribution asDistribution(final File zip) {
    final File tmpdir = Files.tmpdir();
    try {
        Zips.unzip(zip, tmpdir);
    } catch (IOException e) {
        throw new UncheckedIOException("Cannot unzip " + zip.getAbsolutePath(), e);
    }
    final File serverDir = getServerDir(tmpdir);
    final Distribution distribution = new Distribution(zip, serverDir);
    final List<File> jars = Files.collect(serverDir, ".*.jar");
    final Function<File, Artifact> from = file1 -> {
        try {
            return repository.from(file1);
        } catch (IllegalStateException e) {
            distribution.missing.add(file1);
            return null;
        }
    };
    jars.stream().filter(jar -> !jar.getName().equals("bootstrap.jar")).filter(jar -> !jar.getName().equals("catalina-ant.jar")).filter(jar -> !jar.getName().startsWith("tomcat-i18n")).map(from).filter(Objects::nonNull).sorted().distinct().forEach(distribution.artifacts::add);
    return distribution;
}
Also used : Files(org.apache.openejb.loader.Files) Getter(lombok.Getter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) Strings(org.apache.openejb.util.Strings) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Map(java.util.Map) ToString(lombok.ToString) Zips(org.apache.openejb.loader.Zips) PrintStream(java.io.PrintStream) Predicate(java.util.function.Predicate) JarLocation(org.apache.openejb.loader.JarLocation) Test(org.junit.Test) IOException(java.io.IOException) Join(org.apache.openejb.util.Join) Collectors(java.util.stream.Collectors) File(java.io.File) IO(org.apache.openejb.loader.IO) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Data(lombok.Data) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) File(java.io.File)

Example 25 with Data

use of lombok.Data in project metacat by Netflix.

the class MysqlUserMetadataService method searchDefinitionMetadata.

@Override
@Transactional(readOnly = true)
public List<DefinitionMetadataDto> searchDefinitionMetadata(@Nullable final Set<String> propertyNames, @Nullable final String type, @Nullable final String name, @Nullable final HasMetadata holder, @Nullable final String sortBy, @Nullable final String sortOrder, @Nullable final Integer offset, @Nullable final Integer limit) {
    final List<DefinitionMetadataDto> result = Lists.newArrayList();
    final SearchMetadataQuery queryObj = new SearchMetadataQuery(SQL.SEARCH_DEFINITION_METADATAS).buildSearchMetadataQuery(propertyNames, type, name, sortBy, sortOrder, offset, limit);
    try {
        // Handler for reading the result set
        final ResultSetExtractor<Void> handler = rs -> {
            while (rs.next()) {
                final String definitionName = rs.getString("name");
                final String data = rs.getString("data");
                final DefinitionMetadataDto definitionMetadataDto = new DefinitionMetadataDto();
                definitionMetadataDto.setName(QualifiedName.fromString(definitionName));
                definitionMetadataDto.setDefinitionMetadata(metacatJson.parseJsonObject(data));
                result.add(definitionMetadataDto);
            }
            return null;
        };
        jdbcTemplate.query(queryObj.getSearchQuery().toString(), queryObj.getSearchParamList().toArray(), handler);
    } catch (Exception e) {
        log.error("Failed to search definition data", e);
        throw new UserMetadataServiceException("Failed to search definition data", e);
    }
    return result;
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) HasDataMetadata(com.netflix.metacat.common.dto.HasDataMetadata) StringUtils(org.apache.commons.lang3.StringUtils) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DefinitionMetadataDto(com.netflix.metacat.common.dto.DefinitionMetadataDto) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) Map(java.util.Map) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Config(com.netflix.metacat.common.server.properties.Config) BaseUserMetadataService(com.netflix.metacat.common.server.usermetadata.BaseUserMetadataService) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) InvalidMetadataException(com.netflix.metacat.common.server.connectors.exception.InvalidMetadataException) MetacatJson(com.netflix.metacat.common.json.MetacatJson) NonNull(lombok.NonNull) HasDefinitionMetadata(com.netflix.metacat.common.dto.HasDefinitionMetadata) Set(java.util.Set) QualifiedName(com.netflix.metacat.common.QualifiedName) Maps(com.google.common.collect.Maps) MetacatJsonException(com.netflix.metacat.common.json.MetacatJsonException) Collectors(java.util.stream.Collectors) SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) HasMetadata(com.netflix.metacat.common.dto.HasMetadata) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Data(lombok.Data) GetMetadataInterceptorParameters(com.netflix.metacat.common.server.usermetadata.GetMetadataInterceptorParameters) MetadataInterceptor(com.netflix.metacat.common.server.usermetadata.MetadataInterceptor) Optional(java.util.Optional) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ResultSetExtractor(org.springframework.jdbc.core.ResultSetExtractor) Joiner(com.google.common.base.Joiner) Transactional(org.springframework.transaction.annotation.Transactional) Types(java.sql.Types) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) DefinitionMetadataDto(com.netflix.metacat.common.dto.DefinitionMetadataDto) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) InvalidMetadataException(com.netflix.metacat.common.server.connectors.exception.InvalidMetadataException) MetacatJsonException(com.netflix.metacat.common.json.MetacatJsonException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Data (lombok.Data)30 CompletableFuture (java.util.concurrent.CompletableFuture)17 lombok.val (lombok.val)17 Test (org.junit.Test)15 List (java.util.List)14 Collectors (java.util.stream.Collectors)13 IOException (java.io.IOException)10 Slf4j (lombok.extern.slf4j.Slf4j)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Getter (lombok.Getter)9 Reactored (ru.fix.completable.reactor.api.Reactored)9 ReactorGraphBuilder (ru.fix.completable.reactor.runtime.ReactorGraphBuilder)9 Processor (ru.fix.completable.reactor.runtime.dsl.Processor)9 Futures (io.pravega.common.concurrent.Futures)8 TimeUnit (java.util.concurrent.TimeUnit)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Before (org.junit.Before)8 ReactorGraph (ru.fix.completable.reactor.runtime.ReactorGraph)8 Arrays (java.util.Arrays)7