org.openstack4j.core.transport.ExecutionOptions Maven / Gradle / Ivy
package org.openstack4j.core.transport;
import com.google.common.base.Function;
/**
* HTTP Execution Options
*
* @author Jeremy Unruh
* @param
*/
public class ExecutionOptions {
private Function parser;
private PropagateResponse propagateResponse;
private ExecutionOptions(Function parser, PropagateResponse propagateResponse) {
this.parser = parser;
this.propagateResponse = propagateResponse;
}
public static ExecutionOptions create(Function parser) {
return new ExecutionOptions(parser, null);
}
public static ExecutionOptions create(PropagateResponse propagateResponse) {
return new ExecutionOptions(null, propagateResponse);
}
public static ExecutionOptions create(Function parser, PropagateResponse propagateResponse) {
return new ExecutionOptions(parser, propagateResponse);
}
/**
* @return the result function parser or null
*/
public Function getParser() {
return parser;
}
/**
* @return true if a result parser is associated with these options
*/
public boolean hasParser() {
return parser != null;
}
/**
* If a PropagateResponse is associated with these options then it will be invoked otherwise a no-op
* @param response the HttpResponse
*/
public void propagate(HttpResponse response) {
if (propagateResponse != null)
propagateResponse.propagate(response);
}
}