<commit_before>/**
 * Copyright (C) 2010-12 Brookhaven National Laboratory
 * All rights reserved. Use is subject to license terms.
 */
package org.epics.pvmanager;

import org.epics.pvmanager.expression.DesiredRateExpression;
import java.util.concurrent.Executor;
import org.epics.pvmanager.util.Executors;
import org.epics.util.time.TimeDuration;

/**
 * An expression used to set the final parameters on how the pv expression
 * should be monitored.
 * 
 * @param <T> the type of the expression
 * @author carcassi
 */
public class PVReaderConfiguration<T> extends CommonConfiguration {

    @Override
    public PVReaderConfiguration<T> from(DataSource dataSource) {
        super.from(dataSource);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> notifyOn(Executor onThread) {
        super.notifyOn(onThread);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> timeout(TimeDuration timeout) {
        super.timeout(timeout);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> timeout(TimeDuration timeout, String timeoutMessage) {
        super.timeout(timeout, timeoutMessage);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> timeout(org.epics.pvmanager.util.TimeDuration timeout) {
        super.timeout(timeout);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> timeout(org.epics.pvmanager.util.TimeDuration timeout, String timeoutMessage) {
        super.timeout(timeout, timeoutMessage);
        return this;
    }
    
    
    
    private DesiredRateExpression<T> aggregatedPVExpression;
    private ExceptionHandler exceptionHandler;

    PVReaderConfiguration(DesiredRateExpression<T> aggregatedPVExpression) {
        this.aggregatedPVExpression = aggregatedPVExpression;
    }

    /**
     * Forwards exception to the given exception handler. No thread switch
     * is done, so the handler is notified on the thread where the exception
     * was thrown.
     * <p>
     * Giving a custom exception handler will disable the default handler,
     * so {@link PVReader#lastException() } is no longer set and no notification
     * is done.
     *
     * @param exceptionHandler an exception handler
     * @return this
     */
    public PVReaderConfiguration<T> routeExceptionsTo(ExceptionHandler exceptionHandler) {
        if (this.exceptionHandler != null) {
            throw new IllegalArgumentException("Exception handler already set");
        }
        this.exceptionHandler = ExceptionHandler.safeHandler(exceptionHandler);
        return this;
    }
    
    /**
     * Sets the rate of scan of the expression and creates the actual {@link PVReader}
     * object that can be monitored through listeners.
     * 
     * @param period the minimum time distance (i.e. the maximum rate) between two different notifications
     * @return the PVReader
     */
    public PVReader<T> maxRate(TimeDuration rate) {
        return every(org.epics.pvmanager.util.TimeDuration.durationOf(rate));
    }

    /**
     * Sets the rate of scan of the expression and creates the actual {@link PVReader}
     * object that can be monitored through listeners.
     * 
     * @param period the minimum time distance (i.e. the maximum rate) at which notifications should be sent
     * @return the PVReader
     */
    public PVReader<T> every(org.epics.pvmanager.util.TimeDuration period) {
        //int scanPeriodMs = (int) (period.getNanoSec() / 1000000);
        
        if (period.getNanoSec() < 5000000) {
            throw new IllegalArgumentException("Current implementation limits the rate to >5ms or <200Hz (requested " + (period.getNanoSec() / 1000000) + "ms)");
        }

        checkDataSourceAndThreadSwitch();

        // Create PVReader and connect
        PVReaderImpl<T> pv = new PVReaderImpl<T>(aggregatedPVExpression.getName(), Executors.localThread() == notificationExecutor);
        DataRecipe dataRecipe = aggregatedPVExpression.getDataRecipe();
        if (exceptionHandler == null) {
            dataRecipe = dataRecipe.withExceptionHandler(ExceptionHandler.createDefaultExceptionHanderl(pv, notificationExecutor));
        } else {
            dataRecipe = dataRecipe.withExceptionHandler(exceptionHandler);
        }
        Function<T> aggregatedFunction = aggregatedPVExpression.getFunction();
        Notifier<T> notifier = new Notifier<T>(pv, aggregatedFunction, PVManager.getReadScannerExecutorService(), notificationExecutor, dataRecipe.getExceptionHandler());
        notifier.startScan(period);
        if (timeout != null) {
            if (timeoutMessage == null)
                timeoutMessage = "Read timeout";
            notifier.timeout(org.epics.pvmanager.util.TimeDuration.durationOf(timeout), timeoutMessage);
        }
        try {
            source.connect(dataRecipe);
        } catch (RuntimeException ex) {
            dataRecipe.getExceptionHandler().handleException(ex);
        }
        PVRecipe recipe = new PVRecipe(dataRecipe, source, notifier);
        notifier.setPvRecipe(recipe);
        return pv;
    }
}<commit_msg>Deprecated call now redirect on new calls.<commit_after>/**
 * Copyright (C) 2010-12 Brookhaven National Laboratory
 * All rights reserved. Use is subject to license terms.
 */
package org.epics.pvmanager;

import org.epics.pvmanager.expression.DesiredRateExpression;
import java.util.concurrent.Executor;
import org.epics.pvmanager.util.Executors;
import org.epics.util.time.TimeDuration;

/**
 * An expression used to set the final parameters on how the pv expression
 * should be monitored.
 * 
 * @param <T> the type of the expression
 * @author carcassi
 */
public class PVReaderConfiguration<T> extends CommonConfiguration {

    @Override
    public PVReaderConfiguration<T> from(DataSource dataSource) {
        super.from(dataSource);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> notifyOn(Executor onThread) {
        super.notifyOn(onThread);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> timeout(TimeDuration timeout) {
        super.timeout(timeout);
        return this;
    }

    @Override
    public PVReaderConfiguration<T> timeout(TimeDuration timeout, String timeoutMessage) {
        super.timeout(timeout, timeoutMessage);
        return this;
    }

    @Override
    @Deprecated
    public PVReaderConfiguration<T> timeout(org.epics.pvmanager.util.TimeDuration timeout) {
        super.timeout(timeout);
        return this;
    }

    @Override
    @Deprecated
    public PVReaderConfiguration<T> timeout(org.epics.pvmanager.util.TimeDuration timeout, String timeoutMessage) {
        super.timeout(timeout, timeoutMessage);
        return this;
    }
    
    
    
    private DesiredRateExpression<T> aggregatedPVExpression;
    private ExceptionHandler exceptionHandler;

    PVReaderConfiguration(DesiredRateExpression<T> aggregatedPVExpression) {
        this.aggregatedPVExpression = aggregatedPVExpression;
    }

    /**
     * Forwards exception to the given exception handler. No thread switch
     * is done, so the handler is notified on the thread where the exception
     * was thrown.
     * <p>
     * Giving a custom exception handler will disable the default handler,
     * so {@link PVReader#lastException() } is no longer set and no notification
     * is done.
     *
     * @param exceptionHandler an exception handler
     * @return this
     */
    public PVReaderConfiguration<T> routeExceptionsTo(ExceptionHandler exceptionHandler) {
        if (this.exceptionHandler != null) {
            throw new IllegalArgumentException("Exception handler already set");
        }
        this.exceptionHandler = ExceptionHandler.safeHandler(exceptionHandler);
        return this;
    }
    
    /**
     * Sets the rate of scan of the expression and creates the actual {@link PVReader}
     * object that can be monitored through listeners.
     * 
     * @param period the minimum time distance (i.e. the maximum rate) between two different notifications
     * @return the PVReader
     */
    public PVReader<T> maxRate(TimeDuration rate) {
        //int scanPeriodMs = (int) (period.getNanoSec() / 1000000);
        
        if (rate.getSec() < 0 && rate.getNanoSec() < 5000000) {
            throw new IllegalArgumentException("Current implementation limits the rate to >5ms or <200Hz (requested " + rate + "s)");
        }

        checkDataSourceAndThreadSwitch();

        // Create PVReader and connect
        PVReaderImpl<T> pv = new PVReaderImpl<T>(aggregatedPVExpression.getName(), Executors.localThread() == notificationExecutor);
        DataRecipe dataRecipe = aggregatedPVExpression.getDataRecipe();
        if (exceptionHandler == null) {
            dataRecipe = dataRecipe.withExceptionHandler(ExceptionHandler.createDefaultExceptionHanderl(pv, notificationExecutor));
        } else {
            dataRecipe = dataRecipe.withExceptionHandler(exceptionHandler);
        }
        Function<T> aggregatedFunction = aggregatedPVExpression.getFunction();
        Notifier<T> notifier = new Notifier<T>(pv, aggregatedFunction, PVManager.getReadScannerExecutorService(), notificationExecutor, dataRecipe.getExceptionHandler());
        notifier.startScan(org.epics.pvmanager.util.TimeDuration.durationOf(rate));
        if (timeout != null) {
            if (timeoutMessage == null)
                timeoutMessage = "Read timeout";
            notifier.timeout(org.epics.pvmanager.util.TimeDuration.durationOf(timeout), timeoutMessage);
        }
        try {
            source.connect(dataRecipe);
        } catch (RuntimeException ex) {
            dataRecipe.getExceptionHandler().handleException(ex);
        }
        PVRecipe recipe = new PVRecipe(dataRecipe, source, notifier);
        notifier.setPvRecipe(recipe);
        return pv;
    }

    /**
     * Sets the rate of scan of the expression and creates the actual {@link PVReader}
     * object that can be monitored through listeners.
     * 
     * @param period the minimum time distance (i.e. the maximum rate) at which notifications should be sent
     * @return the PVReader
     */
    @Deprecated
    public PVReader<T> every(org.epics.pvmanager.util.TimeDuration period) {
        return maxRate(org.epics.pvmanager.util.TimeDuration.asTimeDuration(period));
    }
}
{'fraction_non_alphanumeric': 0.08663461538461538, 'fraction_numerical': 0.005384615384615384, 'mean_word_length': 3.0423630003886513, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4333946', 'n_tokens_mistral': 2825, 'n_tokens_neox': 2645, 'n_words': 738}