Search in sources :

Example 1 with BatchProcessWorkerAdaptor

use of org.alfresco.repo.batch.BatchProcessor.BatchProcessWorkerAdaptor in project alfresco-repository by Alfresco.

the class RenameUser method execute.

/*
     * (non-Javadoc)
     * @see org.alfresco.tools.Tool#execute()
     */
@Override
protected int execute() throws ToolException {
    // Used for ability to be final and have a set
    final AtomicInteger status = new AtomicInteger(0);
    BatchProcessWorker<User> worker = new BatchProcessWorkerAdaptor<User>() {

        public void process(final User user) throws Throwable {
            RunAsWork<Void> runAsWork = new RunAsWork<Void>() {

                @Override
                public Void doWork() throws Exception {
                    try {
                        renameUser(user.getOldUsername(), user.getNewUsername());
                    } catch (Throwable t) {
                        status.set(handleError(t));
                    }
                    return null;
                }
            };
            AuthenticationUtil.runAs(runAsWork, context.getUsername());
        }
    };
    // Use 2 threads, 20 User objects per transaction. Log every 100 entries.
    BatchProcessor<User> processor = new BatchProcessor<User>("HomeFolderProviderSynchronizer", getServiceRegistry().getTransactionService().getRetryingTransactionHelper(), new WorkProvider(context), 2, 20, null, logger, 100);
    processor.process(worker, true);
    return status.get();
}
Also used : BatchProcessor(org.alfresco.repo.batch.BatchProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) BatchProcessWorkerAdaptor(org.alfresco.repo.batch.BatchProcessor.BatchProcessWorkerAdaptor) BatchProcessWorkProvider(org.alfresco.repo.batch.BatchProcessWorkProvider)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BatchProcessWorkProvider (org.alfresco.repo.batch.BatchProcessWorkProvider)1 BatchProcessor (org.alfresco.repo.batch.BatchProcessor)1 BatchProcessWorkerAdaptor (org.alfresco.repo.batch.BatchProcessor.BatchProcessWorkerAdaptor)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1