Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
AnalyzerBeans Copyright (C) 2014 Neopost - Customer Information Management This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the GNU Lesser General Public License, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this distribution; if not, write to: Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
 
 package org.eobjects.analyzer.cluster;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
org.eobjects.analyzer.job.runner.AnalysisResultFuture implementation for clustered/distributed set-ups.
 
 public final class DistributedAnalysisResultFuture extends AbstractAnalysisResult implements AnalysisResultFuture {
 
     private final DistributedAnalysisResultReducer _reducer;
     private final List<AnalysisResultFuture_results;
     private final Map<ComponentJobAnalyzerResult_resultMap;
     private volatile Date _creationDate;
     private volatile boolean _cancelled;
 
          = results;
          = reducer;
          = new HashMap<ComponentJobAnalyzerResult>();
          = false;
     }
 
     @Override
     public void cancel() {
         if (isDone()) {
             // too late to cancel
             return;
         }
 
         if (!) {
             for (AnalysisResultFuture result : ) {
                 result.cancel();
             }
              = true;
         }
     }
 
     @Override
     public boolean isCancelled() {
         return ;
     }
 
     @Override
     public Date getCreationDate() {
         if (!isDone()) {
             return null;
         }
         return ;
     }
 
     @Override
     public boolean isDone() {
         for (AnalysisResultFuture result : ) {
             if (!result.isDone()) {
                 return false;
             }
         }
         return true;
     }
 
     @Override
     public void await() {
         for (AnalysisResultFuture result : ) {
            result.await();
        }
        if (.isEmpty()) {
            synchronized (this) {
                if (.isEmpty() && .isEmpty()) {
                    .reduce();
                }
            }
        }
    }
    @Override
    public void await(long timeoutTimeUnit timeUnit) {
        final long offsetMillis = System.currentTimeMillis();
        final long millisToWait = timeUnit.convert(timeout.);
        for (AnalysisResultFuture result : ) {
            if (!isDone()) {
                result.await(timeout.);
                final long currentMillis = System.currentTimeMillis();
                final long duration = currentMillis - offsetMillis;
                if (duration >= millisToWait) {
                    return;
                }
            }
        }
    }
    @Override
    public boolean isErrornous() {
        return !isSuccessful();
    }
    @Override
    public boolean isSuccessful() {
        await();
        for (AnalysisResultFuture result : ) {
            if (result.isErrornous()) {
                return false;
            }
        }
        return .isEmpty();
    }
    @Override
    public JobStatus getStatus() {
        if (isCancelled()) {
            return .;
        }
        for (AnalysisResultFuture result : ) {
            JobStatus slaveStatus = result.getStatus();
            if (slaveStatus == .) {
                return .;
            }
        }
        if (isSuccessful()) {
            return .;
        }
        return .;
    }
    @Override
        await();
        if (isErrornous()) {
            throw new AnalysisJobFailedException(getErrors());
        }
        final Collection<AnalyzerResultvalues = .values();
        return new ArrayList<AnalyzerResult>(values);
    }
    @Override
        await();
        if (isErrornous()) {
            throw new AnalysisJobFailedException(getErrors());
        }
        return Collections.unmodifiableMap();
    }
    @Override
    public List<ThrowablegetErrors() {
        final List<Throwableerrors = new ArrayList<Throwable>();
        for (AnalysisResultFuture result : ) {
            final List<ThrowableslaveErrors = result.getErrors();
            if (slaveErrors != null) {
                errors.addAll(slaveErrors);
            }
        }
        errors.addAll();
        return errors;
    }
New to GrepCode? Check out our FAQ X