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