Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.client.operation;
  
  
Intermediate base class to simplify actual result implementations.
 
 public abstract class OperationResultImpl<T extends OperationResultImpl<T>>
     implements OperationResult<T>
 {
     protected final OperationConfig _config;

    
Information on servers for which at least one call was made, but none of calls succeeded.
 
     protected final Collection<NodeFailure_failed;

    
Set of servers that were not contacted; either due to timeout or because no further calls were necessary (disabled nodes, for example, are only called if absolutely necessary)
 
     protected final Collection<ClusterServerNode_ignored;
 
     /*
     /**********************************************************************
     /* Construction, initialization
     /**********************************************************************
      */
     
     protected OperationResultImpl(OperationConfig config)
     {
          = config;
          = new LinkedList<NodeFailure>();
          = new LinkedList<ClusterServerNode>();
     }
 
 
     // Ugly side of generics... needing to cast "this", from base class.
     @SuppressWarnings("unchecked")
     protected final T _this() {
         return (T) this;
     }
 
     public T withFailed(NodeFailure fail) {
         .add(fail);
         return _this();
     }
 
     public T withFailed(Collection<NodeFailurefails) {
         if (fails != null) {
             for (NodeFailure fail : fails) {
                 .add(fail);
             }
         }
         return _this();
     }
     
     public T withIgnored(ClusterServerNode server) {
         .add(server);
         return _this();
     }
 
     /*
     /**********************************************************************
     /* Accessors
     /**********************************************************************
      */
 
     @Override
     public OperationConfig getConfig() { return ; }

    
Simple accessor for checking whether call succeeded to minimum degree required, or not. This means that we had at least minimal required number of succesful individual calls.
 
     @Override
     public boolean succeededMinimally() {
         return getSuccessCount() >= .getMinimalOksToSucceed();
     }

    
Simple accessor for checking whether call succeeded well enough that we may consider it full success. We may either choose to do more updates (if nodes are available); up to succeededMaximally() level; or just return and declare success.
 
     @Override
     public boolean succeededOptimally() {
         return getSuccessCount() >= .getOptimalOks();
     }

    
Simple accessor for checking whether call succeeded as well as it could; meaning that no further calls should be made, even if more nodes were available.
    @Override
    public boolean succeededMaximally() {
        return getSuccessCount() >= .getMaxOks();
    }
    
    @Override
    public int getFailCount() { return .size(); }
    @Override
    public abstract int getSuccessCount();
    
    @Override
    public int getIgnoreCount() { return .size(); }
    @Override
    public Iterable<NodeFailuregetFailures() { return ; }
    @Override
    public Iterable<ClusterServerNodegetIgnoredServers() { return ; }
    @Override
    public NodeFailure getFirstFail() {
        return .isEmpty() ? null : .iterator().next();
    }
    
    /*
    /**********************************************************************
    /* Overrides
    /**********************************************************************
     */
    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("[Result: ");
        sb.append("succeed: ").append(getSuccessCount());
        sb.append(", failed: ").append(getFailCount());
        sb.append(", ignored: ").append(getIgnoreCount());
        _addExtraInfo(sb);
        sb.append("]");
        return sb.toString();
    }

    
Overridable method to augment 'toString()' results
    protected void _addExtraInfo(StringBuilder sb) { }
New to GrepCode? Check out our FAQ X