001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
003 * agreements. See the NOTICE file distributed with this work for additional information regarding
004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
005 * "License"); you may not use this file except in compliance with the License. You may obtain a
006 * copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License
011 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing permissions and limitations under
013 * the License.
014 */
015
016package org.apache.maven.lifecycle.internal.stub;
017
018import org.apache.maven.lifecycle.internal.ProjectSegment;
019
020import java.util.ArrayList;
021import java.util.Collections;
022import java.util.List;
023import java.util.concurrent.Callable;
024import java.util.concurrent.CompletionService;
025import java.util.concurrent.Future;
026import java.util.concurrent.FutureTask;
027import java.util.concurrent.TimeUnit;
028
029/**
030 * @author Kristian Rosenvold
031 */
032public class CompletionServiceStub
033    implements CompletionService<ProjectSegment>
034{
035    List<FutureTask<ProjectSegment>> projectBuildFutureTasks =
036        Collections.synchronizedList( new ArrayList<FutureTask<ProjectSegment>>() );
037
038    final boolean finishImmediately;
039
040
041    public int size()
042    {
043        return projectBuildFutureTasks.size();
044    }
045
046    public CompletionServiceStub( boolean finishImmediately )
047    {
048        this.finishImmediately = finishImmediately;
049    }
050
051    public Future<ProjectSegment> submit( Callable<ProjectSegment> task )
052    {
053        FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<ProjectSegment>( task );
054        projectBuildFutureTasks.add( projectBuildFutureTask );
055        if ( finishImmediately )
056        {
057            projectBuildFutureTask.run();
058        }
059        return projectBuildFutureTask;
060    }
061
062    public Future<ProjectSegment> submit( Runnable task, ProjectSegment result )
063    {
064        FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<ProjectSegment>( task, result );
065        projectBuildFutureTasks.add( projectBuildFutureTask );
066        if ( finishImmediately )
067        {
068            projectBuildFutureTask.run();
069        }
070        return projectBuildFutureTask;
071    }
072
073    public Future<ProjectSegment> take()
074        throws InterruptedException
075    {
076        return null;
077    }
078
079    public Future<ProjectSegment> poll()
080    {
081        return null;
082    }
083
084    public Future<ProjectSegment> poll( long timeout, TimeUnit unit )
085        throws InterruptedException
086    {
087        return null;
088    }
089}