001/**
002 * Copyright 2013 John Ericksen
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a 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
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.androidtransfuse.processor;
017
018import org.androidtransfuse.adapter.ASTType;
019import org.androidtransfuse.analysis.module.ModuleTransactionWorker;
020import org.androidtransfuse.transaction.TransactionProcessor;
021import org.androidtransfuse.transaction.TransactionProcessorBuilder;
022import org.androidtransfuse.transaction.TransactionProcessorPool;
023
024import javax.inject.Inject;
025import javax.inject.Provider;
026
027/**
028 * @author John Ericksen
029 */
030public class ModuleProcessorBuilder implements TransactionProcessorBuilder<Provider<ASTType>, Void> {
031
032    private final ScopedTransactionFactory scopedTransactionFactory;
033    private final TransactionProcessorPool<Provider<ASTType>, Void> transactionProcessor;
034    private final Provider<ModuleTransactionWorker> workerProvider;
035
036    @Inject
037    public ModuleProcessorBuilder(
038            Provider<ModuleTransactionWorker> workerProvider,
039            ScopedTransactionFactory scopedTransactionFactory) {
040        this.scopedTransactionFactory = scopedTransactionFactory;
041        this.transactionProcessor = new TransactionProcessorPool<Provider<ASTType>, Void>();
042        this.workerProvider = workerProvider;
043    }
044
045    @Override
046    public void submit(Provider<ASTType> astTypeProvider) {
047        transactionProcessor.submit(scopedTransactionFactory.buildTransaction(astTypeProvider, workerProvider));
048    }
049
050    @Override
051    public TransactionProcessor<Provider<ASTType>, Void> getTransactionProcessor() {
052        return transactionProcessor;
053    }
054}