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

com.bronto.api.operation.AbstractAsyncObjectOperations Maven / Gradle / Ivy

There is a newer version: 1.0.9
Show newest version
package com.bronto.api.operation;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future;

import com.bronto.api.AsyncHandler;
import com.bronto.api.BrontoApiAsync;
import com.bronto.api.ObjectOperationsAsync;
import com.bronto.api.model.BrontoSoapPortType;
import com.bronto.api.model.SessionHeader;
import com.bronto.api.model.WriteResult;
import com.bronto.api.request.BrontoClientRequest;
import com.bronto.api.request.BrontoReadRequest;

public abstract class AbstractAsyncObjectOperations extends AbstractCommonOperations implements ObjectOperationsAsync {
    public AbstractAsyncObjectOperations(Class clazz, BrontoApiAsync client) {
        super(clazz, client);
    }

    protected Future callWriteAsync(final String method, List objects) {
        final Object call = reflect.fillMethodCall(method, objects);
        return callClientAsync(method, call);
    }

    protected  Future callWriteAsync(final String method, List objects, AsyncHandler handler) {
        final Object call = reflect.fillMethodCall(method, objects);
        return callClientAsync(method, call, handler);
    }

    protected Future callClientAsync(final String method, final Object call) {
        return client.async(reflect.createMethodRequest(method, call));
    }

    protected  Future callClientAsync(final String method, final Object call, final AsyncHandler handler) {
        return client.async(reflect.createMethodRequest(method, call), handler);
    }

    protected BrontoClientRequest getSingle(final BrontoReadRequest request) {
        return new BrontoClientRequest() {
            @Override
            public O invoke(BrontoSoapPortType service, SessionHeader header) throws Exception {
                return request.invoke(service, header).get(0);
            }
        };
    }

    @Override
    public Future> read(final BrontoReadRequest request) {
        return client.async(request);
    }

    @Override
    public  Future read(final BrontoReadRequest request, AsyncHandler, V> handler) {
        return client.async(request, handler);
    }

    @Override
    public Future get(final BrontoReadRequest request) {
        return client.async(getSingle(request));
    }

    @Override
    public  Future get(final BrontoReadRequest request, final AsyncHandler handler) {
        return client.async(getSingle(request), handler);
    }

    @Override
    public Future add(List objects) {
        return callWriteAsync("add", objects);
    }

    @Override
    public Future update(List objects) {
        return callWriteAsync("update", objects);
    }

    @Override
    public Future delete(List objects) {
        return callWriteAsync("delete", objects);
    }

    @SafeVarargs
    @Override
    public final Future add(O... objects) {
        return add(Arrays.asList(objects));
    }

    @SafeVarargs
    @Override
    public final Future update(O... objects) {
        return update(Arrays.asList(objects));
    }

    @SafeVarargs
    @Override
    public final Future delete(O... objects) {
        return delete(Arrays.asList(objects));
    }

    @Override
    public  Future add(List objects, AsyncHandler handler) {
        return callWriteAsync("add", objects, handler);
    }

    @Override
    public  Future update(List objects, AsyncHandler handler) {
        return callWriteAsync("update", objects, handler);
    }

    @Override
    public  Future delete(List objects, AsyncHandler handler) {
        return callWriteAsync("delete", objects, handler);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy