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

com.fasterxml.clustermate.client.operation.InfoOperationResult Maven / Gradle / Ivy

There is a newer version: 0.10.5
Show newest version
package com.fasterxml.clustermate.client.operation;

import java.util.*;

import com.fasterxml.clustermate.api.msg.ItemInfo;
import com.fasterxml.clustermate.client.ClusterServerNode;
import com.fasterxml.clustermate.client.NodeFailure;
import com.fasterxml.clustermate.client.call.ReadCallResult;

/**
 * Result value produced by EntryInspector, contains information
 * about success of individual call, as well as sequence of listed
 * entries in case of successful call.
 */
public class InfoOperationResult
    extends OperationResultImpl>
    implements Iterable>
{
    protected List> _info;

    protected int _successCount;

    protected int _missingCount;
    
    public InfoOperationResult(OperationConfig config, int approxSize)
    {
        super(config);
        _info = new ArrayList>(Math.max(1, approxSize));
    }

    /*
    /**********************************************************************
    /* Building
    /**********************************************************************
     */

    public InfoOperationResult withSuccess(ReadCallResult callResult) {
        ++_successCount;
        _info.add(callResult);
        return this;
    }

    public InfoOperationResult withFailed(ReadCallResult callResult) {
        return withFailed(callResult, new NodeFailure(callResult.getServer(), callResult.getFailure()));
    }

    public InfoOperationResult withFailed(ReadCallResult callResult, NodeFailure fail) {
        _info.add(callResult);
        super.withFailed(fail);
        return this;
    }
    
    public InfoOperationResult withMissing(ReadCallResult callResult) {
        ++_missingCount;
        _info.add(callResult);
        return this;
    }
    
    @Override
    public InfoOperationResult withFailed(Collection fails) {
        throw new UnsupportedOperationException();
    }

    @Override
    public InfoOperationResult withIgnored(ClusterServerNode server) {
        throw new UnsupportedOperationException();
    }
    
    /*
    /**********************************************************************
    /* Accessors, default
    /**********************************************************************
     */

    @Override
    public int getSuccessCount() {
        return _successCount;
    }

    @Override
    public OperationConfig getConfig() {
        return _config;
    }

    /*
    /**********************************************************************
    /* Accessors, additional
    /**********************************************************************
     */

    @Override
    public Iterator> iterator() {
        return _info.iterator();
    }

    public ReadCallResult get(int index) {
        if (index < 0 || index >= _info.size()) {
            return null;
        }
        return _info.get(index);
    }
    
    public int getMissingCount() {
        return _missingCount;
    }
}