001package jmri.jmrit.dispatcher; 002 003import java.util.Collections; 004import jmri.InstanceManager; 005import jmri.implementation.AbstractShutDownTask; 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009public class DispatcherShutDownTask extends AbstractShutDownTask { 010 011 public DispatcherShutDownTask(String name) { 012 super(name); 013 } 014 015 /** 016 * {@inheritDoc} 017 */ 018 @Override 019 public void run() { 020 try { 021 DispatcherFrame df = InstanceManager.getDefault(DispatcherFrame.class); 022 var atList = Collections.unmodifiableCollection(df.getActiveTrainsList()); 023 for (ActiveTrain at : atList) { 024 if (at.getAutoActiveTrain() != null) { 025 at.getAutoActiveTrain().initiateWorking(); 026 } 027 } 028 } catch (Exception ex) { 029 log.error("Failed to stop all autotrains", ex); 030 } 031 } 032 033 private static final Logger log = LoggerFactory.getLogger(DispatcherShutDownTask.class); 034 035}