001package jmri.jmrit.vsdecoder;
002
003/**
004 * Main thread of VSDecoder.
005 *
006 * <hr>
007 * This file is part of JMRI.
008 * <p>
009 * JMRI is free software; you can redistribute it and/or modify it under 
010 * the terms of version 2 of the GNU General Public License as published 
011 * by the Free Software Foundation. See the "COPYING" file for a copy
012 * of this license.
013 * <p>
014 * JMRI is distributed in the hope that it will be useful, but WITHOUT 
015 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
016 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
017 * for more details.
018 * <p>
019 *
020 * @author Mark Underwood Copyright (C) 2011
021 */
022class VSDecoderManagerThread extends Thread {
023
024    private volatile static VSDecoderManagerThread instance = null;
025    private static VSDecoderManager manager = null;
026    boolean is_running;
027
028    private VSDecoderManagerThread() {
029        super();
030        is_running = false;
031    }
032
033    public static VSDecoderManagerThread instance(Boolean create) {
034        manager = new VSDecoderManager();
035        return instance();
036    }
037
038    public static VSDecoderManagerThread instance() {
039        if (instance == null) {
040            VSDecoderManagerThread temp = new VSDecoderManagerThread();
041            temp.setName("VSDecoderManagerThread");
042            temp.start();
043            instance = temp; // don't allow escape of VSDecoderManagerThread object until running
044        }
045        return instance;
046    }
047
048    public static VSDecoderManager manager() {
049        return VSDecoderManagerThread.manager;
050    }
051
052    @Override
053    public void run() {
054        is_running = true;
055        while (is_running) {
056            // just nap.
057            try {
058                sleep(20);
059            } catch (InterruptedException e) {
060            }
061        }
062        // all done.
063    }
064
065    public void kill() {
066        is_running = false;
067    }
068}