001/* An application that executes non-graphical 002 models specified on the command line with a 5 second timeout 003 004 Copyright (c) 2011-2014 The Regents of the University of California. 005 All rights reserved. 006 Permission is hereby granted, without written agreement and without 007 license or royalty fees, to use, copy, modify, and distribute this 008 software and its documentation for any purpose, provided that the above 009 copyright notice and the following two paragraphs appear in all copies 010 of this software. 011 012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 016 SUCH DAMAGE. 017 018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 023 ENHANCEMENTS, OR MODIFICATIONS. 024 025 PT_COPYRIGHT_VERSION_2 026 COPYRIGHTENDKEY 027 028 */ 029package ptolemy.moml; 030 031/////////////////////////////////////////////////////////////////// 032//// MoMLSimpleTimeoutApplication 033 034/** 035 * A simple application that reads in a .xml file as a command line argument, 036 * runs it and terminates the run after a time out. 037 * 038 * @author Christopher Brooks 039 * @version $Id: MoMLSimpleTimeoutApplication.java 61755 2011-08-08 20:17:11Z 040 * cxh $ 041 * @since Ptolemy II 10.0 042 * @Pt.ProposedRating Red (cxh) 043 * @Pt.AcceptedRating Red (eal) 044 */ 045public class MoMLSimpleTimeoutApplication extends MoMLSimpleApplication { 046 047 /** 048 * Parse the xml file and run it. After 5 seconds, call wrapup on the 049 * manager. 050 * 051 * @param xmlFileName 052 * A string that refers to an MoML file that contains a Ptolemy 053 * II model. The string should be a relative pathname. 054 * @exception Throwable 055 * If there was a problem parsing or running the model. 056 */ 057 public MoMLSimpleTimeoutApplication(String xmlFileName) throws Throwable { 058 super(xmlFileName); 059 } 060 061 /////////////////////////////////////////////////////////////////// 062 // // Public methods //// 063 064 /** 065 * Wait for all executing runs to finish or 5 seconds to pass, then return. 066 */ 067 @Override 068 public synchronized void waitForFinish() { 069 long timeout = 5000; 070 try { 071 System.out 072 .print("Waiting for " + timeout / 1000.0 + " seconds. . ."); 073 wait(timeout); 074 _toplevel.getDirector().finish(); 075 _toplevel.getDirector().stopFire(); 076 077 System.out.println(" Done."); 078 } catch (InterruptedException ex) { 079 // Ignore. 080 } 081 } 082}