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

org.openstack4j.core.transport.ExecutionOptions Maven / Gradle / Ivy

There is a newer version: 3.12
Show newest version
package org.openstack4j.core.transport;

import com.google.common.base.Function;

/**
 * HTTP Execution Options
 *
 * @author Jeremy Unruh
 */
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);
    }
} 





© 2015 - 2024 Weber Informatics LLC | Privacy Policy