All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enonic.xp.task.TaskProgressReporterContext Maven / Gradle / Ivy

There is a newer version: 7.14.4
Show newest version
package com.enonic.xp.task;

import com.enonic.xp.annotation.PublicApi;

@PublicApi
public final class TaskProgressReporterContext
{
    private static final ThreadLocal CURRENT = new ThreadLocal<>();

    public static ProgressReporter current()
    {
        return CURRENT.get();
    }

    private static void set( final ProgressReporter req )
    {
        if ( req == null )
        {
            CURRENT.remove();
        }
        else
        {
            CURRENT.set( req );
        }
    }

    public static RunnableTask withContext( final RunnableTask runnableTask )
    {
        return ( id, progressReporter ) ->
        {
            final ProgressReporter old = current();
            set( progressReporter );

            try
            {
                runnableTask.run( id, progressReporter );
            }
            finally
            {
                set( old );
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy