Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.eyrie.remctl.client;
 
 import java.util.List;
 
A validation strategy that sends a command to the remclt server and checks the response.

Author(s):
pradtke
public class CommandValidationStrategy extends BaseValidationStrategy {

    
default commands is just noop.
    private String[] commands = { "noop" };

    
Default constructor.
    public CommandValidationStrategy() {
    }

    
Create a CommandValidationStrategy that runs the specified commands.

Parameters:
commands The commands to run
    public CommandValidationStrategy(final String... commands) {
        this.setCommands(commands);
    }
    @Override
    public boolean checkConnection(final RemctlConnection connection) {
        RemctlCommandToken token = new RemctlCommandToken(truethis.);
        connection.writeToken(token);
        List<RemctlTokentokens = connection.readAllTokens();
        RemctlResponse response = RemctlResponse.buildFromTokens(tokens);
        return this.checkResponse(response);
    }

    
Check the response for running the configured command.

By default simply checks the status of the response. Subclasses may override as needed to do perform more complicated checks

Parameters:
response The response from running the configured command
Returns:
true if the response is expected, false otherwise
    boolean checkResponse(final RemctlResponse response) {
        return response.getStatus() != null && response.getStatus() == 0;
    }

    

Returns:
the commands
    public String[] getCommands() {
        // don't let caller manipulate our internal state.
        return Arrays.copyOf(this..);
    }

    

Parameters:
commands the commands to set
    public void setCommands(final String... commands) {
        this. = commands;
    }
New to GrepCode? Check out our FAQ X