View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.lifecycle.internal.stub;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.concurrent.Callable;
25  import java.util.concurrent.CompletionService;
26  import java.util.concurrent.Future;
27  import java.util.concurrent.FutureTask;
28  import java.util.concurrent.TimeUnit;
29  
30  import org.apache.maven.lifecycle.internal.ProjectSegment;
31  
32  /**
33   */
34  public class CompletionServiceStub implements CompletionService<ProjectSegment> {
35      List<FutureTask<ProjectSegment>> projectBuildFutureTasks = Collections.synchronizedList(new ArrayList<>());
36  
37      final boolean finishImmediately;
38  
39      public int size() {
40          return projectBuildFutureTasks.size();
41      }
42  
43      public CompletionServiceStub(boolean finishImmediately) {
44          this.finishImmediately = finishImmediately;
45      }
46  
47      public Future<ProjectSegment> submit(Callable<ProjectSegment> task) {
48          FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<>(task);
49          projectBuildFutureTasks.add(projectBuildFutureTask);
50          if (finishImmediately) {
51              projectBuildFutureTask.run();
52          }
53          return projectBuildFutureTask;
54      }
55  
56      public Future<ProjectSegment> submit(Runnable task, ProjectSegment result) {
57          FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<>(task, result);
58          projectBuildFutureTasks.add(projectBuildFutureTask);
59          if (finishImmediately) {
60              projectBuildFutureTask.run();
61          }
62          return projectBuildFutureTask;
63      }
64  
65      public Future<ProjectSegment> take() throws InterruptedException {
66          return null;
67      }
68  
69      public Future<ProjectSegment> poll() {
70          return null;
71      }
72  
73      public Future<ProjectSegment> poll(long timeout, TimeUnit unit) throws InterruptedException {
74          return null;
75      }
76  }