# HG changeset patch # User Peter Mehlitz # Date 1427841464 25200 # Node ID a9ada67f179929176f47fc5d115e3b2da34c80a8 # Parent e15b03204dc7684f037c87ab0f17b739856ef465 moved LogConsole to .jpf.tool package diff -r e15b03204dc7 -r a9ada67f1799 .hgignore --- a/.hgignore Mon Mar 23 12:54:20 2015 -0700 +++ b/.hgignore Tue Mar 31 15:37:44 2015 -0700 @@ -3,6 +3,8 @@ local.properties .version .idea/workspace.xml +.idea/fileColors.xml +.idea/uiDesigner.xml nbproject/private/* build/* dist/* diff -r e15b03204dc7 -r a9ada67f1799 .idea/misc.xml --- a/.idea/misc.xml Mon Mar 23 12:54:20 2015 -0700 +++ b/.idea/misc.xml Tue Mar 31 15:37:44 2015 -0700 @@ -38,33 +38,6 @@ - - - - - - - - - @@ -78,118 +51,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - localhost - 5050 - - diff -r e15b03204dc7 -r a9ada67f1799 src/main/gov/nasa/jpf/tool/LogConsole.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/gov/nasa/jpf/tool/LogConsole.java Tue Mar 31 15:37:44 2015 -0700 @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2014, United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The Java Pathfinder core (jpf-core) platform is licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package gov.nasa.jpf.tool; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * simple logging facility that listens on a socket (e.g. for log output display) + */ +public class LogConsole { + + static int DEF_PORT = 20000; // keep this in sync with the gov.nasa.jpf.util.LogHandler + + class ShutdownHook implements Runnable { + @Override + public void run () { + if (running) { + // not very threadsafe, but worst thing that can happen is we close twice + killed = true; + System.out.println("\nLogConsole killed, shutting down"); + } + try { + cs.close(); + ss.close(); + } catch (Throwable t) { + // not much we can do here anyway + } + } + } + + + boolean running; + + int port; + boolean autoclose; + boolean killed; + + ServerSocket ss; + Socket cs; + + public void run () { + running = true; + Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook())); + + if (port == 0) { + port = DEF_PORT; + } + + try { + ss = new ServerSocket(port); + + try { + do { + System.out.println("LogConsole listening on port: " + port); + + cs = ss.accept(); + BufferedReader in = new BufferedReader( new InputStreamReader(cs.getInputStream())); + String msg; + + System.out.println("LogConsole connected"); + System.out.println("--------------------------------------------------------------------------------"); + try { + + while ((msg = in.readLine()) != null) { + System.out.println(msg); + } + + System.out.println("--------------------------------------------------------------------------------"); + System.out.println("LogConsole disconnected"); + } catch (IOException iox) { + System.err.println(iox); + } + + in.close(); + cs.close(); + } while (!autoclose); + + System.out.println("LogConsole closing"); + + } catch (IOException iox) { + if (!killed) { + System.err.println("Error: LogConsole accept failed on port: " + port); + } + } + + } catch (IOException iox) { + System.err.println("Error: LogConsole cannot listen on port: " + port); + } + + running = false; + } + + public void showUsage () { + System.out.println("LogConsole: socket based console logger"); + System.out.println(" usage: java gov.nasa.jpf.tools.LogConsole {flags} []"); + System.out.println(" args: -help show this message"); + System.out.println(" -autoclose close the application upon disconnect"); + System.out.println(" optional port number, default: " + DEF_PORT); + } + + boolean processArgs (String[] args) { + for (int i=0; i