blob: 7ed3b631a4afcfcef4fcc56a1af926862d168294 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*******************************************************************************
* Copyright (c) 2011 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.display.presenter.internal;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.eclipse.osee.display.presenter.ArtifactFilter;
import org.eclipse.osee.executor.admin.CancellableCallable;
import org.eclipse.osee.executor.admin.ExecutorAdmin;
import org.eclipse.osee.executor.admin.WorkUtility;
import org.eclipse.osee.executor.admin.WorkUtility.PartitionFactory;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.orcs.data.ArtifactReadable;
/**
* @author Roberto E. Escobar
*/
public class FilteredArtifactCallable extends CancellableCallable<List<ArtifactReadable>> implements PartitionFactory<ArtifactReadable, ArtifactReadable> {
private static final String FILTER_WORKER_ID = "artifact.filter.workers";
private final ExecutorAdmin executorAdmin;
private final ArtifactFilter filter;
private final Iterable<ArtifactReadable> artifacts;
public FilteredArtifactCallable(ExecutorAdmin executorAdmin, ArtifactFilter filter, Iterable<ArtifactReadable> artifacts) {
super();
this.executorAdmin = executorAdmin;
this.filter = filter;
this.artifacts = artifacts;
}
@Override
public List<ArtifactReadable> call() throws Exception {
List<Future<Collection<ArtifactReadable>>> futures =
WorkUtility.partitionAndScheduleWork(executorAdmin, FILTER_WORKER_ID, this, artifacts);
final List<ArtifactReadable> results = new LinkedList<ArtifactReadable>();
for (Future<Collection<ArtifactReadable>> future : futures) {
checkForCancelled();
results.addAll(future.get());
}
return results;
}
@Override
public Callable<Collection<ArtifactReadable>> createWorker(final Collection<ArtifactReadable> toProcess) {
return new CancellableCallable<Collection<ArtifactReadable>>() {
@Override
public Collection<ArtifactReadable> call() throws Exception {
checkForCancelled();
Collections.filter(toProcess, filter);
return toProcess;
}
};
}
}
|