Search in sources :

Example 1 with QuietShutDownTask

use of jmri.implementation.QuietShutDownTask in project JMRI by JMRI.

the class Server method enable.

public void enable() {
    if (socketListener == null) {
        socketListener = new Thread(new ClientListener());
        socketListener.setDaemon(true);
        socketListener.setName("DCCppOverTcpServer");
        log.info("Starting new DCCppOverTcpServer listener on port " + portNumber);
        socketListener.start();
        updateServerStateListener();
        // advertise over Zeroconf/Bonjour
        if (this.service == null) {
            this.service = ZeroConfService.create("_dccppovertcpserver._tcp.local.", portNumber);
        }
        log.info("Starting ZeroConfService _dccppovertcpserver._tcp.local for DCCppOverTCP Server");
        this.service.publish();
        if (this.shutDownTask == null) {
            this.shutDownTask = new QuietShutDownTask("DCCppOverTcpServer") {

                @Override
                public boolean execute() {
                    Server.getInstance().disable();
                    return true;
                }
            };
        }
        if (this.shutDownTask != null && InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
            InstanceManager.getDefault(jmri.ShutDownManager.class).register(this.shutDownTask);
        }
    }
}
Also used : QuietShutDownTask(jmri.implementation.QuietShutDownTask)

Example 2 with QuietShutDownTask

use of jmri.implementation.QuietShutDownTask in project JMRI by JMRI.

the class DefaultShutDownManagerTest method testDeregister.

@Test
public void testDeregister() {
    DefaultShutDownManager dsdm = new DefaultShutDownManager();
    List tasks = this.exposeTasks(dsdm);
    Assert.assertEquals(0, tasks.size());
    ShutDownTask task = new QuietShutDownTask("task") {

        @Override
        public boolean execute() {
            return true;
        }
    };
    dsdm.register(task);
    Assert.assertEquals(1, tasks.size());
    Assert.assertTrue(tasks.contains(task));
    dsdm.deregister(task);
    Assert.assertEquals(0, tasks.size());
}
Also used : ShutDownTask(jmri.ShutDownTask) QuietShutDownTask(jmri.implementation.QuietShutDownTask) QuietShutDownTask(jmri.implementation.QuietShutDownTask) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 3 with QuietShutDownTask

use of jmri.implementation.QuietShutDownTask in project JMRI by JMRI.

the class DefaultAudioManager method init.

/**
     * Method used to initialise the manager
     */
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
// OK to write to static variables as we only do so if not initialised
@Override
public synchronized void init() {
    if (!initialised) {
        //            // First try to initialise LWJGL
        //            activeAudioFactory = new LWJGLAudioFactory();
        //            log.debug("Try to initialise LWJGLAudioFactory");
        //
        //            // If LWJGL fails, fall-back to JOAL
        //            if (!activeAudioFactory.init()) {
        activeAudioFactory = new JoalAudioFactory();
        log.debug("Try to initialise JoalAudioFactory");
        // If JOAL fails, fall-back to JavaSound
        if (!activeAudioFactory.init()) {
            activeAudioFactory = new JavaSoundAudioFactory();
            log.debug("Try to initialise JavaSoundAudioFactory");
            // Finally, if JavaSound fails, fall-back to a Null sound system
            if (!activeAudioFactory.init()) {
                activeAudioFactory = new NullAudioFactory();
                log.debug("Try to initialise NullAudioFactory");
                activeAudioFactory.init();
            }
        }
        // Create default Listener and save in map
        try {
            Audio s = createNewAudio("IAL$", "Default Audio Listener");
            register(s);
        } catch (AudioException ex) {
            log.error("Error creating Default Audio Listener: " + ex);
        }
        // Finally, create and register a shutdown task to ensure clean exit
        if (audioShutDownTask == null) {
            audioShutDownTask = new QuietShutDownTask("AudioFactory Shutdown") {

                @Override
                public boolean execute() {
                    InstanceManager.getDefault(jmri.AudioManager.class).cleanUp();
                    return true;
                }
            };
        }
        if (InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
            InstanceManager.getDefault(jmri.ShutDownManager.class).register(audioShutDownTask);
        }
        initialised = true;
        if (log.isDebugEnabled()) {
            log.debug("Initialised AudioFactory type: " + activeAudioFactory.getClass().getSimpleName());
        }
    }
}
Also used : AudioException(jmri.AudioException) QuietShutDownTask(jmri.implementation.QuietShutDownTask) Audio(jmri.Audio) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with QuietShutDownTask

use of jmri.implementation.QuietShutDownTask in project JMRI by JMRI.

the class EcosLocoAddressManager method loadData.

private void loadData() {
    tc.addEcosListener(this);
    Roster.getDefault().addPropertyChangeListener(this);
    EcosMessage m = new EcosMessage("request(10, view)");
    tc.sendWaitMessage(m, this);
    /*m = new EcosMessage("queryObjects(10)");
         tc.sendWaitMessage(m, this);*/
    m = new EcosMessage("queryObjects(10, addr, name, protocol)");
    tc.sendEcosMessage(m, this);
    if (ecosLocoShutDownTask == null) {
        ecosLocoShutDownTask = new QuietShutDownTask("Ecos Loco Database Shutdown") {

            @Override
            public boolean execute() {
                return shutdownDispose();
            }
        };
    }
    if (jmri.InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
        jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).register(ecosLocoShutDownTask);
    }
}
Also used : QuietShutDownTask(jmri.implementation.QuietShutDownTask)

Example 5 with QuietShutDownTask

use of jmri.implementation.QuietShutDownTask in project JMRI by JMRI.

the class LnTcpServer method enable.

public void enable() {
    if (socketListener == null) {
        socketListener = new Thread(new ClientListener());
        socketListener.setDaemon(true);
        socketListener.setName("LocoNetOverTcpServer");
        log.info("Starting new LocoNetOverTcpServer listener on port " + portNumber);
        socketListener.start();
        updateServerStateListeners();
        // advertise over Zeroconf/Bonjour
        if (this.service == null) {
            this.service = ZeroConfService.create("_loconetovertcpserver._tcp.local.", portNumber);
        }
        log.info("Starting ZeroConfService _loconetovertcpserver._tcp.local for LocoNetOverTCP Server");
        this.service.publish();
        if (this.shutDownTask == null) {
            this.shutDownTask = new QuietShutDownTask("LocoNetOverTcpServer") {

                @Override
                public boolean execute() {
                    LnTcpServer.this.disable();
                    return true;
                }
            };
        }
        InstanceManager.getOptionalDefault(jmri.ShutDownManager.class).ifPresent((manager) -> {
            manager.register(this.shutDownTask);
        });
    }
}
Also used : QuietShutDownTask(jmri.implementation.QuietShutDownTask) ShutDownManager(jmri.ShutDownManager)

Aggregations

QuietShutDownTask (jmri.implementation.QuietShutDownTask)6 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ShutDownTask (jmri.ShutDownTask)2 Test (org.junit.Test)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Audio (jmri.Audio)1 AudioException (jmri.AudioException)1 ShutDownManager (jmri.ShutDownManager)1