Package com.gainmatrix.lib.time

Examples of com.gainmatrix.lib.time.ChronometerTimer


    }

    private SshCommandActionResult processChannel(ChannelExec channel, SshCommandActionDefinition definition,
        InputStream stdOutStream, InputStream stdErrStream) throws Exception
    {
        ChronometerTimer timer = new ChronometerTimer(chronometer);

        OutputCapturer stdOutCapturer = new OutputCapturer(stdOutStream, definition.isSkipStdOutput());
        OutputCapturer stdErrCapturer = new OutputCapturer(stdErrStream, definition.isSkipStdError());

        while (true) {
            // Read data
            stdOutCapturer.read();
            stdErrCapturer.read();

            // Check is channel already closed
            if (channel.isClosed()) {
                int exitCode = channel.getExitStatus();
                boolean succeed = exitCode == definition.getExpectedExitCode();
                return produceSuccessResult(stdOutCapturer, stdErrCapturer, exitCode, succeed);
            }

            // Check timeout
            if ((definition.getTimeoutMs() > 0) && (timer.elapsed() > definition.getTimeoutMs())) {
                return produceTimeoutResult(stdOutCapturer, stdErrCapturer);
            }

            // Make a pause
            try {
View Full Code Here


        if (CollectionUtils.isEmpty(scheduleExecution.getNodes())) {
            return ScheduleExecutionStatus.EMPTYNODES;
        }

        // Remember when the process started
        ChronometerTimer timer = new ChronometerTimer(chronometer);

        // Succeed nodes counter
        int succeedNodes = 0;

        // All nodes iterator
        Iterator<ScheduleExecutionNode> nodeIterator = scheduleExecution.getNodes().iterator();

        // Start loop throught all execution nodes
        while (nodeIterator.hasNext()) {
            // Get fresh copy of execution and check the cancellation flag
            ScheduleExecution scheduleExecutionReloaded =
                executionManagementService.findExecution(scheduleExecution.getId());
            if (scheduleExecutionReloaded.isCancelled()) {
                LOGGER.debug("Execution [{}] is cancelled", scheduleExecution.getId());
                return ScheduleExecutionStatus.CANCELED;
            }

            // Current node
            ScheduleExecutionNode currentNode = nodeIterator.next();

            // Execution action on node
            ScheduleExecutionResult scheduleExecutionResult = executeJobNode(scheduleExecution, currentNode);

            // If last action succeedes break the node loop
            if (scheduleExecutionResult.isSucceed()) {
                LOGGER.debug("Success execution [{}] on node [{}]",
                    scheduleExecution.getId(), currentNode.getAddress());
                succeedNodes++;
                if (!scheduleExecution.isAllNodes()) {
                    return ScheduleExecutionStatus.SUCCEED;
                }
            } else {
                LOGGER.debug("Failed execution [{}] on node [{}]",
                    scheduleExecution.getId(), currentNode.getAddress());
            }

            // Are there any other pending nodes?
            if (nodeIterator.hasNext()) {
                // Check timeout
                if ((scheduleExecution.getTimeout() > 0) && (timer.elapsed() > scheduleExecution.getTimeout())) {
                    LOGGER.debug("Execution [{}] is timed out", scheduleExecution.getId());
                    return ScheduleExecutionStatus.TIMEOUT;
                }
            } else {
                if (scheduleExecution.isAllNodes() && (succeedNodes == scheduleExecution.getNodes().size())) {
View Full Code Here

TOP

Related Classes of com.gainmatrix.lib.time.ChronometerTimer

Copyright © 2018 www.massapicom. 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.