Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.eyrie.remctl.client;
  
Encapsulates the response from a remctl server into an easy to use format.

Author(s):
pradtke
 
 public class RemctlResponse {

    
Allow logging.
 
     static final Logger logger = LoggerFactory.getLogger(RemctlResponse.class);

    
Output Messages on stream 1.
 
     private final String stdOut;
    
Output Messages on stream 2.
 
     private final String stdErr;

    
Exit status. Will be null if an error response happened.
 
     private final Integer returnStatus;

    
Use factory method.

Parameters:
stdOut stdOut string
stdErr stdErr string
returnStatus The return status (maybe null)
 
     RemctlResponse(final String stdOutfinal String stdErrfinal Integer returnStatus) {
         super();
         // TODO: assert stdout and stderr are not null
         this. = stdOut;
         this. = stdErr;
         this. = returnStatus;
     }

    
Build a response based on a set of remctl tokens.

Parameters:
responseTokens The token received from the server
Returns:
The remctlReponse
Throws:
org.eyrie.remctl.core.RemctlProtocolException If the list has an unexpected protocol
org.eyrie.remctl.core.RemctlErrorException If a token is malformed, or an error token is seen
 
     public static RemctlResponse buildFromTokens(final Iterable<RemctlTokenresponseTokens) {
         StringBuilder stdOutResponse = new StringBuilder();
         StringBuilder stdErrResponse = new StringBuilder();
         Integer status = null;
 
         for (RemctlToken outputToken : responseTokens) {
 
             .trace("Processing token {} " + outputToken.getClass());
             if (outputToken instanceof RemctlErrorToken) {
                 .info("RemctlErrorToken in response {}"outputToken);
                 throw new RemctlErrorException((RemctlErrorTokenoutputToken);
             } else if (outputToken instanceof RemctlOutputToken) {
                 RemctlOutputToken remctlOutputToken = (RemctlOutputTokenoutputToken;
                 byte stream = remctlOutputToken.getStream();
                 if (stream == 1) {
                     stdOutResponse.append(remctlOutputToken.getOutputAsString());
                 } else if (stream == 2) {
                     stdErrResponse.append(remctlOutputToken.getOutputAsString());
                 } else {
                     throw new RemctlErrorException(.."Unrecognized stream "
                             + stream);
                 }
             } else if (outputToken instanceof RemctlStatusToken) {
                 status = ((RemctlStatusTokenoutputToken).getStatus();
                 break;
             } else {
                 throw new RemctlProtocolException("Unrecognized response token " + outputToken.getClass());
             }
         }
 
         return new RemctlResponse(stdOutResponse.toString(), stdErrResponse.toString(), status);
    }

    
Get the stdout response returned from the server.

Returns:
the stout
    public String getStdOut() {
        return this.;
    }

    
Get the stderr response returned from the server.

Returns:
the stdErrResponse.
    public String getStdErr() {
        return this.;
    }

    
Return the status of the response.

May be null if an RemctlErrorCode was returned instead of a RemctlStatusToken.

Returns:
the returnStatus.
    public Integer getStatus() {
        return this.;
    }
New to GrepCode? Check out our FAQ X