Examples of RuntimeState


Examples of org.apache.sling.bgservlets.RuntimeState

        final int cycles = getIntParam(request, "cycles", 10);
        final int interval = getIntParam(request, "interval", 1000);
        final int flushEvery = getIntParam(request, "flushEvery", 2);
       
        // Use supplied RuntimeState if available
        final RuntimeState runtimeState = (RuntimeState)request.getAttribute(RuntimeState.class.getName());
        if(runtimeState == null) {
            log.warn("No RuntimeState attribute provided, won't report progress");
        } else {
            runtimeState.setEstimatedCompletionTime(new Date(System.currentTimeMillis() + cycles * interval));
        }

        w.println("Start at " + new Date());
        try {
            for (int i = 1; i <= cycles; i++) {
                if (i % flushEvery == 0) {
                    w.println("Flushing output<br/>");
                    w.flush();
                }
               
                final String msg = String.format("Cycle %d of %d", i, cycles);
                w.printf(msg);
                w.print("\n<br/>");
               
                if(runtimeState != null) {
                    runtimeState.setProgressMessage(msg);
                    final int remainingCycles = cycles - i;
                    runtimeState.setEstimatedCompletionTime(new Date(System.currentTimeMillis() + remainingCycles * interval));
                }
               
                try {
                    Thread.sleep(interval);
                } catch (InterruptedException iex) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.