001package jmri.implementation;
002
003import jmri.TurnoutOperator;
004
005/**
006 * Concrete subclass of TurnoutOperator for a turnout that has no feedback.
007 *
008 * @author John Harper Copyright 2005
009 */
010public class NoFeedbackTurnoutOperator extends TurnoutOperator {
011
012    long interval;
013    int maxTries;
014    int tries = 0;
015
016    public NoFeedbackTurnoutOperator(AbstractTurnout t, long i, int mt) {
017        super(t);
018        interval = i;
019        maxTries = mt;
020    }
021
022    /**
023     * Do the automation for a turnout with no feedback. This means try maxTries
024     * times at an interval of interval. Note the call to operatorCheck each
025     * time we're about to actually do something - if we're no longer the
026     * current operator this throws TurnoutOperatorException which just
027     * terminates the thread.
028     */
029    @Override
030    public void run() {
031        try {
032            operatorCheck();
033            myTurnout.forwardCommandChangeToLayout();
034            while (++tries < maxTries) {
035                try {
036                    Thread.sleep(interval);
037                } catch (InterruptedException e) {
038                    Thread.currentThread().interrupt(); // retain if needed later
039                }
040                operatorCheck();
041                myTurnout.forwardCommandChangeToLayout();
042            }
043            myTurnout.setKnownStateToCommanded();
044        } catch (TurnoutOperatorException e) {
045        }
046    }
047
048}