/** * Recursively computes progress based on nested contexts. * * @param stack * @param parentChunk * @return */ protected static double computeSubprogressFor(Deque<ILifecycleProgressContext> stack, double current) { if (stack.isEmpty()) { return current; } ILifecycleProgressContext context = stack.removeLast(); double opIndex = (double) context.getCurrentOperationIndex(); double opCount = (double) context.getOperationCount(); double finished = Math.floor((opIndex - 1.0) / opCount * current); double working = Math.floor(1.0 / opCount * current); return finished + computeSubprogressFor(stack, working); } }
/** * Recursively computes progress based on nested contexts. * * @param stack * @param parentChunk * @return */ protected static double computeSubprogressFor(Deque<ILifecycleProgressContext> stack, double current) { if (stack.isEmpty()) { return current; } ILifecycleProgressContext context = stack.removeLast(); double opIndex = (double) context.getCurrentOperationIndex(); double opCount = (double) context.getOperationCount(); double finished = Math.floor((opIndex - 1.0) / opCount * current); double working = Math.floor(1.0 / opCount * current); return finished + computeSubprogressFor(stack, working); } }
/** * Common logic for starting an operation on an * {@link ILifecycleProgressMonitor}. * * @param monitor * @param operation * @throws SiteWhereException */ public static void startProgressOperation(ILifecycleProgressMonitor monitor, String operation) throws SiteWhereException { ILifecycleProgressContext context = monitor.getContextStack().peek(); if (context == null) { throw new SiteWhereException("Unable to start operation. No context available."); } int newIndex = context.getCurrentOperationIndex() + 1; if (newIndex > context.getOperationCount()) { throw new SiteWhereException( "Unable to start operation. Index will exceed expected operation count. Operation was: " + operation); } context.setCurrentOperationIndex(newIndex); context.setCurrentOperationMessage(operation); }
/** * Common logic for starting an operation on an * {@link ILifecycleProgressMonitor}. * * @param monitor * @param operation * @throws SiteWhereException */ public static void startProgressOperation(ILifecycleProgressMonitor monitor, String operation) throws SiteWhereException { ILifecycleProgressContext context = monitor.getContextStack().peek(); if (context == null) { throw new SiteWhereException("Unable to start operation. No context available."); } int newIndex = context.getCurrentOperationIndex() + 1; if (newIndex > context.getOperationCount()) { throw new SiteWhereException( "Unable to start operation. Index will exceed expected operation count. Operation was: " + operation); } context.setCurrentOperationIndex(newIndex); context.setCurrentOperationMessage(operation); }