Package org.apache.archiva.redback.components.taskqueue

Examples of org.apache.archiva.redback.components.taskqueue.BuildProjectTask


    private Logger logger = LoggerFactory.getLogger( getClass() );

    public void executeTask( Task task0 )
        throws TaskExecutionException
    {
        BuildProjectTask task = (BuildProjectTask) task0;

        task.start();

        logger.info( "Task:{} cancelled: {}; done: {}", task, task.isCancelled(), task.isDone() );

        long time = System.currentTimeMillis();

        long endTime = task.getExecutionTime() + time;

        for ( long timeToSleep = endTime - time; timeToSleep > 0; timeToSleep = endTime - System.currentTimeMillis() )
        {
            try
            {
                logger.info( "Sleeping {} ms (interrupts ignored: {} )", timeToSleep, task.ignoreInterrupts() );
                Thread.sleep( timeToSleep );

                task.done();

                logger.info( "Task completed normally: {} cancelled: {}; done: {}", task, task.isCancelled(),
                             task.isDone() );
            }
            catch ( InterruptedException e )
            {
                if ( !task.ignoreInterrupts() )
                {
                    task.cancel();

                    logger.info( "Task cancelled: {} cancelled: {} ; done: {}", task, task.isCancelled(),
                                 task.isDone() );

                    throw new TaskExecutionException( "Never interrupt sleeping threads! :)", e );
                }
                else
                {
View Full Code Here


    @Test
    public void testTimeoutWithInterrupts()
        throws TaskQueueException, InterruptedException
    {
        BuildProjectTask task = putTask( 2 * 1000, false );

        waitForExpectedTaskEnd( task );

        assertTrue( task.isCancelled() );
        assertFalse( task.isDone() );
    }
View Full Code Here

    @Test
    public void testTimeoutWithoutInterrupts()
        throws TaskQueueException, InterruptedException
    {
        BuildProjectTask task = putTask( 2 * 1000, true );

        waitForExpectedTaskEnd( task );

        // the thread is killed so the task is neither done nor cancelled
        assertFalse( task.isCancelled() );
        assertFalse( task.isDone() );
    }
View Full Code Here

    }

    private BuildProjectTask putTask( int executionTime, boolean ignoreInterrupts )
        throws TaskQueueException
    {
        BuildProjectTask task = new BuildProjectTask( 100 );
        task.setMaxExecutionTime( executionTime );
        task.setExecutionTime( 10 * executionTime );
        task.setIgnoreInterrupts( ignoreInterrupts );

        taskQueue.put( task );
        return task;
    }
View Full Code Here

TOP

Related Classes of org.apache.archiva.redback.components.taskqueue.BuildProjectTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.