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 *
019 * @author Mark Underwood Copyright (C) 2011
020 */
021class VSDecoderManagerThread extends Thread {
022
023    private volatile static VSDecoderManagerThread instance = null;
024    private static VSDecoderManager manager = null;
025    boolean is_running;
026
027    private VSDecoderManagerThread() {
028        super();
029        is_running = false;
030    }
031
032    public static VSDecoderManagerThread instance(Boolean create) {
033        manager = new VSDecoderManager();
034        return instance();
035    }
036
037    public static VSDecoderManagerThread instance() {
038        if (instance == null) {
039            VSDecoderManagerThread temp = new VSDecoderManagerThread();
040            temp.setName("VSDecoderManagerThread");
041            temp.start();
042            instance = temp; // don't allow escape of VSDecoderManagerThread object until running
043        }
044        return instance;
045    }
046
047    public static VSDecoderManager manager() {
048        return VSDecoderManagerThread.manager;
049    }
050
051    @Override
052    public void run() {
053        is_running = true;
054        while (is_running) {
055            // just nap.
056            try {
057                sleep(20);
058            } catch (InterruptedException e) {
059                Thread.currentThread().interrupt();
060                break;
061            }
062        }
063        // all done.
064    }
065
066    public void kill() {
067        is_running = false;
068    }
069}