All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.broadinstitute.hellbender.utils.runtime.ProcessControllerAckResult Maven / Gradle / Ivy

There is a newer version: 4.6.0.0
Show newest version
package org.broadinstitute.hellbender.utils.runtime;

import org.broadinstitute.hellbender.exceptions.GATKException;

/**
 * Command acknowledgements that are returned from a process managed by StreamingProcessController.
 * Ack results can be positive, negative, or negative with a message.
 */
public class ProcessControllerAckResult {

    private final boolean isPositiveAck;
    private final String message;

    // three message types can be used by the remote process
    private static String displayMessageFormat = "%s received\n\n";
    private static String ACK_LOG_MESSAGE               = String.format(displayMessageFormat, StreamingToolConstants.STREAMING_ACK_MESSAGE);
    private static String NCK_LOG_MESSAGE               = String.format(displayMessageFormat, StreamingToolConstants.STREAMING_NCK_MESSAGE);
    private static String NCK_WITH_MESSAGE_LOG_MESSAGE  = String.format(displayMessageFormat, StreamingToolConstants.STREAMING_NCK_WITH_MESSAGE_MESSAGE);

    /**
     * Creates an ack result, for ACK or NCK.
     * @param isPositiveAck true for a positive ack (ACK), false for negative ack (NCK)
     */
    public ProcessControllerAckResult(final boolean isPositiveAck) {
        this.isPositiveAck = isPositiveAck;
        this.message = null;
    }

    /**
     * Creates an (negative NKM) ack result, with a message.
     * @param nckMessage Message detail indicating reason for negative ack (NKM).
     */
    public ProcessControllerAckResult(final String nckMessage) {
        this.isPositiveAck = false;
        this.message = nckMessage;
    }

    /**
     * @return true if this represents a positive ack, otherwise false
     */
    public boolean isPositiveAck() {
        return isPositiveAck;
    }

    /**
     * @return true if this ack is negative and includes a message
     */
    public boolean hasMessage() {
        return !isPositiveAck() && !message.isEmpty();
    }

    /**
     * @return A (possibly empty) String with any message sent from the remote process.
     * Only defined for negative acknowledgements {@link #hasMessage()}.
     */
    public String getNegativeACKMessage() {
        if (isPositiveAck()) {
            throw new GATKException("Can only retrieve messages for negative acknowledgements");
        }
        return message;
    }

    /**
     * @return A message string representing this ack/nck suitable for logging/display to the user.
     */
    public String getDisplayMessage() {
        if (isPositiveAck()) {
            return ACK_LOG_MESSAGE;
        } else if (hasMessage()) {
            return String.format("%s: %s", NCK_WITH_MESSAGE_LOG_MESSAGE, getNegativeACKMessage());
        } else {
            return NCK_LOG_MESSAGE;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy