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   * @author Kristian Rosenvold
34   */
35  public class CompletionServiceStub implements CompletionService<ProjectSegment> {
36      List<FutureTask<ProjectSegment>> projectBuildFutureTasks =
37              Collections.synchronizedList(new ArrayList<FutureTask<ProjectSegment>>());
38  
39      final boolean finishImmediately;
40  
41      public int size() {
42          return projectBuildFutureTasks.size();
43      }
44  
45      public CompletionServiceStub(boolean finishImmediately) {
46          this.finishImmediately = finishImmediately;
47      }
48  
49      public Future<ProjectSegment> submit(Callable<ProjectSegment> task) {
50          FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<>(task);
51          projectBuildFutureTasks.add(projectBuildFutureTask);
52          if (finishImmediately) {
53              projectBuildFutureTask.run();
54          }
55          return projectBuildFutureTask;
56      }
57  
58      public Future<ProjectSegment> submit(Runnable task, ProjectSegment result) {
59          FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<>(task, result);
60          projectBuildFutureTasks.add(projectBuildFutureTask);
61          if (finishImmediately) {
62              projectBuildFutureTask.run();
63          }
64          return projectBuildFutureTask;
65      }
66  
67      public Future<ProjectSegment> take() throws InterruptedException {
68          return null;
69      }
70  
71      public Future<ProjectSegment> poll() {
72          return null;
73      }
74  
75      public Future<ProjectSegment> poll(long timeout, TimeUnit unit) throws InterruptedException {
76          return null;
77      }
78  }