From b8ca6891d252d38d39288d9712e641125df42e0a Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 13 Apr 2012 15:12:35 +0000 Subject: [PATCH] refs #8 Some more fixups. --- src/eva2/client/EvAClient.java | 2001 +++++++++-------- src/eva2/server/EvAServer.java | 240 +- .../constraint/AbstractConstraint.java | 10 +- src/eva2/tools/jproxy/XThread.java | 68 +- 4 files changed, 1143 insertions(+), 1176 deletions(-) diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index a7872421..9102e2c0 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -1,18 +1,12 @@ package eva2.client; /* - * Title: EvA2 - * Description: The main client class of the EvA framework. - * Copyright: Copyright (c) 2008 - * Company: University of Tuebingen, Computer Architecture - * @author Holger Ulmer, Felix Streichert, Hannes Planatscher - * @version: $Revision: 322 $ - * $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007) $ - * $Author: mkron $ + * Title: EvA2 Description: The main client class of the EvA framework. + * Copyright: Copyright (c) 2008 Company: University of Tuebingen, Computer + * Architecture @author Holger Ulmer, Felix Streichert, Hannes Planatscher + * @version: $Revision: 322 $ $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec + * 2007) $ $Author: mkron $ */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Event; @@ -82,846 +76,882 @@ import eva2.tools.jproxy.RemoteStateListener; * */ public class EvAClient implements RemoteStateListener, Serializable { - /** - * Generated serial version identifier. - */ - private static final long serialVersionUID = 8232856334379977970L; - private final int splashScreenTime = 1500; - private final int maxWindowMenuLength = 30; - private boolean clientInited = false; - - public static boolean TRACE = false; - - public JEFrame m_Frame; - Runnable initRnbl = null; - - private EvAComAdapter m_ComAdapter; - private transient JMenuBar m_barMenu; - private transient JExtMenu m_mnuAbout; - private transient JExtMenu m_mnuSelHosts; - private transient JExtMenu m_mnuModule; - private transient JExtMenu m_mnuWindow; - private transient JExtMenu m_mnuOptions; - private transient JProgressBar m_ProgressBar; + /** + * Generated serial version identifier. + */ + private static final long serialVersionUID = 8232856334379977970L; + private final int splashScreenTime = 1500; + private final int maxWindowMenuLength = 30; + private boolean clientInited = false; + public JEFrame m_Frame; + private Runnable initRnbl = null; + private EvAComAdapter m_ComAdapter; + private transient JMenuBar m_barMenu; + private transient JExtMenu m_mnuAbout; + private transient JExtMenu m_mnuSelHosts; + private transient JExtMenu m_mnuModule; + private transient JExtMenu m_mnuWindow; + private transient JExtMenu m_mnuOptions; + private transient JProgressBar m_ProgressBar; // public ArrayList m_ModulGUIContainer = new ArrayList(); - // LogPanel - private LogPanel m_LogPanel; - - // Module: - private ExtAction m_actModuleLoad; - // GUI: - - // Hosts: - private ExtAction m_actHost; - private ExtAction m_actAvailableHost; - private ExtAction m_actKillHost; - private ExtAction m_actKillAllHosts; - private ModuleAdapter currentModuleAdapter = null; - // About: - private ExtAction m_actAbout; - private ExtAction m_actLicense; - + // LogPanel + private LogPanel m_LogPanel; + // Module: + private ExtAction m_actModuleLoad; + // GUI: + // Hosts: + private ExtAction m_actHost; + private ExtAction m_actAvailableHost; + private ExtAction m_actKillHost; + private ExtAction m_actKillAllHosts; + private ModuleAdapter currentModuleAdapter = null; + // About: + private ExtAction m_actAbout; + private ExtAction m_actLicense; // private JPanel m_panelTool; // private FrameCloseListener m_frameCloseListener; // private JFileChooser m_FileChooser; - // if not null, the module is loaded automatically and no other can be selected - private String useDefaultModule = null;//"Genetic_Optimization"; - private boolean showLoadModules = false; - private boolean localMode = false; - // This variable says whether, if running locally, a local server should be addressed by RMI. - // False should be preferred here to avoid overhead - private boolean useLocalRMI = false; - // measuring optimization runtime - private long startTime = 0; - // remember the module in use - private transient String currentModule = null; + private String useDefaultModule = null;//"Genetic_Optimization"; + private boolean showLoadModules = false; + private boolean localMode = false; + // This variable says whether, if running locally, a local server should be addressed by RMI. + // False should be preferred here to avoid overhead + private boolean useLocalRMI = false; + // measuring optimization runtime + private long startTime = 0; + // remember the module in use + private transient String currentModule = null; + Vector superListenerList = null; + private boolean withGUI = true; + private boolean withTreeView = false; + private EvATabbedFrameMaker frameMaker = null; - Vector superListenerList = null; - private boolean withGUI = true; - private boolean withTreeView = false; - private EvATabbedFrameMaker frmMkr = null; - - public void addRemoteStateListener(RemoteStateListener l) { - if (superListenerList == null) superListenerList = new Vector(); - superListenerList.add(l); - } - - public boolean removeRemoteStateListener(RemoteStateListener l) { - if (superListenerList != null) { - return superListenerList.remove(l); - } else return false; - } + public void addRemoteStateListener(RemoteStateListener l) { + if (superListenerList == null) { + superListenerList = new Vector(); + } + superListenerList.add(l); + } - /** - * Constructor of GUI of EvA2. - * Works as client for the EvA2 server. - * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} - * to await full initialization if necessary. - * - */ - public EvAClient(final String hostName) { - this(hostName, null, false, false); - } - - /** - * A constructor. Splash screen is optional, Gui is activated, no parent window. - * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} - * to await full initialization if necessary. - * - * @see #EvAClient(String, Window, String, boolean, boolean, boolean) - * @param hostName - * @param paramsFile - * @param autorun - * @param nosplash - */ - public EvAClient(final String hostName, final String paramsFile, boolean autorun, boolean nosplash) { - this(hostName, null, paramsFile, null, autorun, nosplash, false, false); - } - - /** - * A constructor with optional spash screen. - * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} - * to await full initialization if necessary. - * @see #EvAClient(String, String, boolean, boolean) - * - * @param hostName - * @param autorun - * @param nosplash - */ - public EvAClient(final String hostName, boolean autorun, boolean nosplash) { - this(hostName, null, autorun, nosplash); - } - - /** - * A constructor with optional splash screen. - * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} - * to await full initialization if necessary. - * - * @see #EvAClient(String, String, boolean, boolean) - * @param hostName - * @param paramsFile - * @param autorun - * @param noSplash - * @param noGui - */ - public EvAClient(final String hostName, String paramsFile, boolean autorun, boolean noSplash, boolean noGui, boolean withTreeView) { - this(hostName, null, paramsFile, null, autorun, noSplash, noGui, withTreeView); - } - - /** - * A constructor with optional splash screen. - * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} - * to await full initialization if necessary. - * - * @see #EvAClient(String, String, boolean, boolean) - * - * @param hostName - * @param paramsFile - * @param autorun - * @param noSplash - * @param noGui - */ - public EvAClient(final String hostName, InterfaceGOParameters goParams, boolean autorun, boolean noSplash, boolean noGui) { - this(hostName, null, null, goParams, autorun, noSplash, noGui, false); - } - - /** - * Do not use the tree view by default. - * - * @param hostName - * @param parent - * @param paramsFile - * @param goParams - * @param autorun - * @param noSplash - * @param noGui - */ - public EvAClient(final String hostName, final Window parent, final String paramsFile, final InterfaceGOParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui) { - this(hostName, parent, paramsFile, goParams, autorun, noSplash, noGui, false); - } - - /** - * Main constructor of the EvA2 client GUI. Works as standalone verson locally or - * as client for the EvA2 server. GO parameters may be - * loaded from a file (paramsFile) or given directly as a java instance. Both may be null - * to start with standard parameters. If both are non null, the java instance has the - * higher priority. - * Note that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} - * to await full initialization if necessary. - * - * @param hostName - * @param parent - * @param paramsFile - * @param autorun - * @param noSplash - * @param noGui - */ - public EvAClient(final String hostName, final Window parent, final String paramsFile, final InterfaceGOParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui, final boolean showTreeView) { - clientInited = false; - final SplashScreenShell fSplashScreen = new SplashScreenShell(EvAInfo.splashLocation); + public boolean removeRemoteStateListener(RemoteStateListener l) { + if (superListenerList != null) { + return superListenerList.remove(l); + } else { + return false; + } + } - // preload some classes (into system cache) in a parallel thread - preloadClasses(); + /** + * Constructor of GUI of EvA2. Works as client for the EvA2 server. Note + * that the EvAClient initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. + * + */ + public EvAClient(final String hostName) { + this(hostName, null, false, false); + } - withGUI = !noGui; - withTreeView = showTreeView; - // activate the splash screen (show later using SwingUtilities) - if (!noSplash && withGUI) { - try { - fSplashScreen.splash(); - } catch(HeadlessException e) { - System.err.println("Error: no xserver present - deactivating GUI."); - withGUI=false; - } - } - - currentModule = null; - - m_ComAdapter = EvAComAdapter.getInstance(); + /** + * A constructor. Splash screen is optional, Gui is activated, no parent + * window. Note that the EvAClient initialized multi-threaded for + * efficiency. Use {@link #awaitGuiInitialized()} to await full + * initialization if necessary. + * + * @see #EvAClient(String, Window, String, boolean, boolean, boolean) + * @param hostName + * @param paramsFile + * @param autorun + * @param nosplash + */ + public EvAClient(final String hostName, final String paramsFile, boolean autorun, boolean nosplash) { + this(hostName, null, paramsFile, null, autorun, nosplash, false, false); + } - SwingUtilities.invokeLater( initRnbl = new Runnable() { - public void run(){ - synchronized (this) { - long startTime = System.currentTimeMillis(); - init(hostName, paramsFile, goParams, parent); // this takes a bit + /** + * A constructor with optional spash screen. Note that the EvAClient is + * initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. + * + * @see #EvAClient(String, String, boolean, boolean) + * + * @param hostName + * @param autorun + * @param nosplash + */ + public EvAClient(final String hostName, boolean autorun, boolean nosplash) { + this(hostName, null, autorun, nosplash); + } - long wait = System.currentTimeMillis() - startTime; - if (!autorun) { - if (!noSplash) try { - // if splashScreenTime has not passed, sleep some more - if (wait < splashScreenTime) Thread.sleep(splashScreenTime - wait); - } catch (Exception e) {} - } else { - if (!withGUI && (currentModuleAdapter instanceof GenericModuleAdapter)) { - // do not save new parameters for an autorun without GUI - they werent changed manually anyways. - ((GenericModuleAdapter) currentModuleAdapter).getStatistics().setSaveParams(false); - System.out.println("Autorun without GUI - not saving statistics parameters..."); - } - if (withGUI) frmMkr.onUserStart(); - else currentModuleAdapter.startOpt(); - } - // close splash screen - if (!noSplash && withGUI) fSplashScreen.dispose(); - clientInited = true; - notify(); - } - } - }); - } - - /** - * Since the constructor runs multi-threaded for efficiency, this method - * may be called to await the full initialization of a client instance. - * As soon as it returns, the EvAClient GUI is fully initialized. - */ - public void awaitClientInitialized() { - if (initRnbl!=null) { - synchronized (initRnbl) { - if (!clientInited) { - try { - initRnbl.wait(); - initRnbl=null; - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - } - - private void preloadClasses() { - ClassPreloader cp = new ClassPreloader( "eva2.server.go.strategies.InterfaceOptimizer", "eva2.server.go.problems.InterfaceOptimizationProblem", "eva2.server.go.InterfaceTerminator"); - new Thread(cp).start(); - } - - /** - * Try to start the optimization with current parameters on the loaded module. - * Return true on success, otherwise false. - * - * @return - */ - public boolean startOptimization() { - if (currentModuleAdapter != null) { - currentModuleAdapter.startOpt(); - return true; - } else return false; - } - - /** - * Add a window listener to the EvA2 JFrame instance. - * - * @param l - */ - public void addWindowListener(WindowListener l) { - if (m_Frame != null) { - m_Frame.addWindowListener(l); - } else { - System.err.println("Error, no JFrame existent in " - + this.getClass().getSimpleName()); - } - } - - /** - * Remove a window listener to the EvA2 JFrame instance. - * - * @param l - */ - public void removeWindowListener(WindowListener l) { - if (m_Frame != null) { - m_Frame.removeWindowListener(l); - } else { - System.err.println("Error, no JFrame existent in " - + this.getClass().getSimpleName()); - } - } - - /** - * Sets given hostname and tries to load GOParamsters from given file if non null. - */ - private void init(String hostName, String paramsFile, InterfaceGOParameters goParams, final Window parent) { - //EVA_EDITOR_PROPERTIES - useDefaultModule = EvAInfo.propDefaultModule(); - - if (useDefaultModule != null) { - useDefaultModule = useDefaultModule.trim(); - if (useDefaultModule.length() < 1) useDefaultModule = null; - } - - if (withGUI ) { - m_Frame = new JEFrame(EvAInfo.productName + " workbench"); - m_Frame.setCloseAllOnClosed(true); - m_Frame.setName(this.getClass().getSimpleName()); // the name is set to recognize the client window - - BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); - m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); + /** + * A constructor with optional splash screen. Note that the EvAClient + * initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. + * + * @see #EvAClient(String, String, boolean, boolean) + * @param hostName + * @param paramsFile + * @param autorun + * @param noSplash + * @param noGui + */ + public EvAClient(final String hostName, String paramsFile, boolean autorun, boolean noSplash, boolean noGui, boolean withTreeView) { + this(hostName, null, paramsFile, null, autorun, noSplash, noGui, withTreeView); + } + + /** + * A constructor with optional splash screen. Note that the EvAClient + * initialized multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} + * to await full initialization if necessary. + * + * @see #EvAClient(String, String, boolean, boolean) + * + * @param hostName + * @param paramsFile + * @param autorun + * @param noSplash + * @param noGui + */ + public EvAClient(final String hostName, InterfaceGOParameters goParams, boolean autorun, boolean noSplash, boolean noGui) { + this(hostName, null, null, goParams, autorun, noSplash, noGui, false); + } + + /** + * Do not use the tree view by default. + * + * @param hostName + * @param parent + * @param paramsFile + * @param goParams + * @param autorun + * @param noSplash + * @param noGui + */ + public EvAClient(final String hostName, final Window parent, final String paramsFile, final InterfaceGOParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui) { + this(hostName, parent, paramsFile, goParams, autorun, noSplash, noGui, false); + } + + /** + * Main constructor of the EvA2 client GUI. Works as standalone verson + * locally or as client for the EvA2 server. GO parameters may be loaded + * from a file (paramsFile) or given directly as a java instance. Both may + * be null to start with standard parameters. If both are non null, the java + * instance has the higher priority. Note that the EvAClient initialized + * multi-threaded for efficiency. Use {@link #awaitGuiInitialized()} to + * await full initialization if necessary. + * + * @param hostName + * @param parent + * @param paramsFile + * @param autorun + * @param noSplash + * @param noGui + */ + public EvAClient(final String hostName, final Window parent, final String paramsFile, final InterfaceGOParameters goParams, final boolean autorun, final boolean noSplash, final boolean noGui, final boolean showTreeView) { + clientInited = false; + final SplashScreenShell fSplashScreen = new SplashScreenShell(EvAInfo.splashLocation); + + // preload some classes (into system cache) in a parallel thread + preloadClasses(); + + withGUI = !noGui; + withTreeView = showTreeView; + // activate the splash screen (show later using SwingUtilities) + if (!noSplash && withGUI) { + try { + fSplashScreen.splash(); + } catch (HeadlessException e) { + System.err.println("Error: no xserver present - deactivating GUI."); + withGUI = false; + } + } + + currentModule = null; + + m_ComAdapter = EvAComAdapter.getInstance(); + + SwingUtilities.invokeLater(initRnbl = new Runnable() { + + public void run() { + synchronized (this) { + long startTime = System.currentTimeMillis(); + init(hostName, paramsFile, goParams, parent); // this takes a bit + + long wait = System.currentTimeMillis() - startTime; + if (!autorun) { + if (!noSplash) { + try { + // if splashScreenTime has not passed, sleep some more + if (wait < splashScreenTime) { + Thread.sleep(splashScreenTime - wait); + } + } catch (Exception e) { + } + } + } else { + if (!withGUI && (currentModuleAdapter instanceof GenericModuleAdapter)) { + // do not save new parameters for an autorun without GUI - they werent changed manually anyways. + ((GenericModuleAdapter) currentModuleAdapter).getStatistics().setSaveParams(false); + System.out.println("Autorun without GUI - not saving statistics parameters..."); + } + if (withGUI) { + frameMaker.onUserStart(); + } else { + currentModuleAdapter.startOpt(); + } + } + // close splash screen + if (!noSplash && withGUI) { + fSplashScreen.dispose(); + } + clientInited = true; + notify(); + } + } + }); + } + + /** + * Since the constructor runs multi-threaded for efficiency, this method may + * be called to await the full initialization of a client instance. As soon + * as it returns, the EvAClient GUI is fully initialized. + */ + public void awaitClientInitialized() { + if (initRnbl != null) { + synchronized (initRnbl) { + if (!clientInited) { + try { + initRnbl.wait(); + initRnbl = null; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + private void preloadClasses() { + ClassPreloader cp = new ClassPreloader("eva2.server.go.strategies.InterfaceOptimizer", "eva2.server.go.problems.InterfaceOptimizationProblem", "eva2.server.go.InterfaceTerminator"); + new Thread(cp).start(); + } + + /** + * Try to start the optimization with current parameters on the loaded + * module. Return true on success, otherwise false. + * + * @return + */ + public boolean startOptimization() { + if (currentModuleAdapter != null) { + currentModuleAdapter.startOpt(); + return true; + } else { + return false; + } + } + + /** + * Add a window listener to the EvA2 JFrame instance. + * + * @param l + */ + public void addWindowListener(WindowListener l) { + if (m_Frame != null) { + m_Frame.addWindowListener(l); + } else { + System.err.println("Error, no JFrame existent in " + + this.getClass().getSimpleName()); + } + } + + /** + * Remove a window listener to the EvA2 JFrame instance. + * + * @param l + */ + public void removeWindowListener(WindowListener l) { + if (m_Frame != null) { + m_Frame.removeWindowListener(l); + } else { + System.err.println("Error, no JFrame existent in " + + this.getClass().getSimpleName()); + } + } + + /** + * Sets given hostname and tries to load GOParamsters from given file if non + * null. + */ + private void init(String hostName, String paramsFile, InterfaceGOParameters goParams, final Window parent) { + //EVA_EDITOR_PROPERTIES + useDefaultModule = EvAInfo.propDefaultModule(); + + if (useDefaultModule != null) { + useDefaultModule = useDefaultModule.trim(); + if (useDefaultModule.length() < 1) { + useDefaultModule = null; + } + } + + if (withGUI) { + m_Frame = new JEFrame(EvAInfo.productName + " workbench"); + m_Frame.setCloseAllOnClosed(true); + m_Frame.setName(this.getClass().getSimpleName()); // the name is set to recognize the client window + + BasicResourceLoader loader = BasicResourceLoader.instance(); + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); // m_Frame.setTitle(EvAInfo.productName + " workbench"); - try { - Thread.sleep(200); - } catch (Exception e) { - System.out.println("Error" + e.getMessage()); - } + try { + Thread.sleep(200); + } catch (Exception e) { + System.out.println("Error" + e.getMessage()); + } - m_Frame.getContentPane().setLayout(new BorderLayout()); - m_LogPanel = new LogPanel(); - m_Frame.getContentPane().add(m_LogPanel, BorderLayout.CENTER); - m_ProgressBar = new JProgressBar(); - m_Frame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH); + m_Frame.getContentPane().setLayout(new BorderLayout()); + m_LogPanel = new LogPanel(); + m_Frame.getContentPane().add(m_LogPanel, BorderLayout.CENTER); + m_ProgressBar = new JProgressBar(); + m_Frame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH); - if (EvAInfo.propShowModules() != null) showLoadModules = true; - else showLoadModules = false; // may be set to true again if default module couldnt be loaded + if (EvAInfo.propShowModules() != null) { + showLoadModules = true; + } else { + showLoadModules = false; // may be set to true again if default module couldnt be loaded + } + createActions(); + } + if (useDefaultModule != null) { + // if goParams are not defined and a params file is defined + // try to load parameters from file + if (goParams == null && (paramsFile != null && (paramsFile.length() > 0))) { + goParams = GOParameters.getInstance(paramsFile, false); + } + loadModuleFromServer(useDefaultModule, goParams);//loadSpecificModule + } - createActions(); - } - if (useDefaultModule != null) { - // if goParams are not defined and a params file is defined - // try to load parameters from file - if (goParams==null && (paramsFile!=null && (paramsFile.length()>0))) goParams = GOParameters.getInstance(paramsFile, false); - loadModuleFromServer(useDefaultModule, goParams);//loadSpecificModule - } - - if (withGUI) { - buildMenu(); - m_Frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.out.println("Closing EvA2 Client. Bye!"); - m_Frame.dispose(); - Set keys = System.getenv().keySet(); - if (keys.contains("MATLAB")) { - System.out.println("Seems like Ive been started from Matlab: not killing JVM"); - } else { - if (parent == null) System.exit(1); - } - } - }); - } - - if (m_ComAdapter != null) { - if (hostName != null) selectHost(hostName); - m_ComAdapter.setLogPanel(m_LogPanel); - logMessage("Selected Host: " + m_ComAdapter.getHostName()); - } + if (withGUI) { + buildMenu(); + m_Frame.addWindowListener(new WindowAdapter() { + + public void windowClosing(WindowEvent e) { + System.out.println("Closing EvA2 Client. Bye!"); + m_Frame.dispose(); + Set keys = System.getenv().keySet(); + if (keys.contains("MATLAB")) { + System.out.println("Seems like Ive been started from Matlab: not killing JVM"); + } else { + if (parent == null) { + System.exit(1); + } + } + } + }); + } + + if (m_ComAdapter != null) { + if (hostName != null) { + selectHost(hostName); + } + m_ComAdapter.setLogPanel(m_LogPanel); + logMessage("Selected Host: " + m_ComAdapter.getHostName()); + } // m_mnuModule.setText("Select module"); // m_mnuModule.repaint(); - - if (withGUI) { - m_LogPanel.logMessage("Working directory is: " + System.getProperty("user.dir")); - m_LogPanel.logMessage("Class path is: " + System.getProperty("java.class.path",".")); - if (!(m_Frame.isVisible())) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - m_Frame.setLocation((int)((screenSize.width-m_Frame.getWidth())/2), (int)((screenSize.height-m_Frame.getHeight())/2.5)); - m_Frame.pack(); - m_Frame.setVisible(true); - } - m_LogPanel.logMessage("EvA2 ready"); // if this message is omitted, the stupid scroll pane runs to the end of the last line which is ugly for a long class path - } - } - - /** - * Refresh the parameter panels (if settings have been changed outside - * of the GUI which should be updated in the GUI. - * - */ - public void refreshMainPanels() { - frmMkr.refreshPanels(); - } - - /** - * The one and only main of the client program. Possible arguments: - * --autorun immediately starts the optimization (with parameters loaded from current - * directory if available. - * --hostname HOST: sets the hostname for the EvAClient to HOST - * --nosplash: skip the splash screen. - * --params PFILE: load the optimization parameter from the serialized file PFILE - * - * @param args command line parameters - */ - public static void main(String[] args) { - if (TRACE) { - System.out.println(EVAHELP.getSystemPropertyString()); - } + if (withGUI) { + m_LogPanel.logMessage("Working directory is: " + System.getProperty("user.dir")); + m_LogPanel.logMessage("Class path is: " + System.getProperty("java.class.path", ".")); - String[] keys= new String[]{"--help", "--autorun", "--nosplash", "--nogui", "--remotehost", "--params", "--treeView"}; - int[] arities = new int[]{0, 0, 0, 0, 1, 1, 0}; - Object[] values = new Object[keys.length]; - - Integer[] unknownArgs = StringTools.parseArguments(args, keys, arities, values, true); - - if (unknownArgs.length>0) { - System.err.println("Unrecognized command line options: "); - for (int i=0; i 0) { + System.err.println("Unrecognized command line options: "); + for (int i = 0; i < unknownArgs.length; i++) { + System.err.println(" " + args[unknownArgs[i]]); + } + if (values[0] == null) { + System.err.println("Try --help as argument."); + } + } + + if (values[0] != null) { + System.out.println(usage()); + } else { + boolean autorun = (values[1] != null); + boolean nosplash = (values[2] != null); + boolean nogui = (values[3] != null); + boolean treeView = (values[6] != null); + String hostName = StringTools.checkSingleStringArg(keys[4], values[4], arities[4] - 1); + String paramsFile = StringTools.checkSingleStringArg(keys[5], values[5], arities[5] - 1); + + new EvAClient(hostName, paramsFile, autorun, nosplash, nogui, treeView); + } + } + + /** + * Initialize the client GUI with given parameters and set listeners. This + * will return as soon as the GUI is visible and ready. + * + * @param goParams optimization parameters + * @param statisticsListener statistics listener receiving data during + * optimization + * @param windowListener additional window listener for client frame + */ + public static EvAClient initClientGUI(GOParameters goParams, + InterfaceStatisticsListener statisticsListener, + WindowListener windowListener, final Window parent) { + EvAClient evaClient; + + evaClient = new EvAClient(null, parent, null, goParams, + false, true, false, false); // initializes GUI in the background + // important: wait for GUI initialization before accessing any internal + // settings: + evaClient.awaitClientInitialized(); // this returns as soon as the + // GUI is ready + evaClient.addWindowListener(windowListener); + // modify initial settings: + evaClient.getStatistics().getStatisticsParameter().setOutputAllFieldsAsText(true); // activate output of all data + // fields + // add a data listener instance: + evaClient.getStatistics().addDataListener(statisticsListener); + + evaClient.refreshMainPanels(); // GUI update due to the changes made through the API - /** - * Initialize the client GUI with given parameters and set - * listeners. This will return as soon as the GUI is visible and ready. - * - * @param goParams optimization parameters - * @param statisticsListener statistics listener receiving data during optimization - * @param windowListener additional window listener for client frame - */ - public static EvAClient initClientGUI(GOParameters goParams, - InterfaceStatisticsListener statisticsListener, - WindowListener windowListener, final Window parent) { - EvAClient evaClient; - - evaClient = new EvAClient(null, parent, null, goParams, - false, true, false, false); // initializes GUI in the background - // important: wait for GUI initialization before accessing any internal - // settings: - evaClient.awaitClientInitialized(); // this returns as soon as the - // GUI is ready - evaClient.addWindowListener(windowListener); - // modify initial settings: - evaClient.getStatistics().getStatisticsParameter().setOutputAllFieldsAsText(true); // activate output of all data - // fields - // add a data listener instance: - evaClient.getStatistics().addDataListener(statisticsListener); + return evaClient; + } - evaClient.refreshMainPanels(); // GUI update due to the changes made through the API + public static String usage() { + StringBuffer sbuf = new StringBuffer(); + sbuf.append(EvAInfo.productName); + sbuf.append(" - "); + sbuf.append(EvAInfo.productLongName); + sbuf.append(" - Version "); + sbuf.append(EvAInfo.getVersion()); + sbuf.append("\n"); + sbuf.append("License: "); + sbuf.append(EvAInfo.LGPLFile); + sbuf.append("\n"); + sbuf.append("Homepage: "); + sbuf.append(EvAInfo.url); + sbuf.append("\n"); + sbuf.append("Command-line arguments:\n"); + sbuf.append(" --help: Show this text and exit\n"); + sbuf.append(" --nosplash: Deactivate splash screen\n"); + sbuf.append(" --nogui: Deactivate GUI (makes most sense with autorun and params set)\n"); + sbuf.append(" --autorun: Start an optimization immediately and exit after execution\n"); + sbuf.append(" --params PARAMFILE: Load the (serialized) parameters file on start\n"); + sbuf.append(" --remotehost HOSTNAME: Try to load a module from a (remote) server\n"); - - return evaClient; - } - - public static String usage() { - StringBuffer sbuf = new StringBuffer(); - sbuf.append(EvAInfo.productName); - sbuf.append(" - "); - sbuf.append(EvAInfo.productLongName); - sbuf.append(" - Version "); - sbuf.append(EvAInfo.getVersion()); - sbuf.append("\n"); - sbuf.append("License: "); - sbuf.append(EvAInfo.LGPLFile); - sbuf.append("\n"); - sbuf.append("Homepage: "); - sbuf.append(EvAInfo.url); - sbuf.append("\n"); - sbuf.append("Command-line arguments:\n"); - sbuf.append(" --help: Show this text and exit\n"); - sbuf.append(" --nosplash: Deactivate splash screen\n"); - sbuf.append(" --nogui: Deactivate GUI (makes most sense with autorun and params set)\n"); - sbuf.append(" --autorun: Start an optimization immediately and exit after execution\n"); - sbuf.append(" --params PARAMFILE: Load the (serialized) parameters file on start\n"); - sbuf.append(" --remotehost HOSTNAME: Try to load a module from a (remote) server\n"); - - return sbuf.toString(); - } + return sbuf.toString(); + } - /** - * - */ - private void createActions() { - ////////////////////////////////////////////////////////////// - // Module: - ///////////////////////////////////////////////////////////// - m_actModuleLoad = new ExtAction("&Load", "Load Module", - KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) { - public void actionPerformed(ActionEvent e) { - loadModuleFromServer(null, null); - } - }; + /** + * + */ + private void createActions() { + ////////////////////////////////////////////////////////////// + // Module: + ///////////////////////////////////////////////////////////// + m_actModuleLoad = new ExtAction("&Load", "Load Module", + KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) { - m_actAbout = new ExtAction("&About...", "Product Information", - KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) { - public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); - showAboutDialog(); - } - }; - m_actLicense = new ExtAction("&License...", "View License", - KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) { - public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); - showLicense(); - } - }; - m_actHost = new ExtAction("&List of all servers", "All servers in list", - KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) { - public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); - selectAvailableHost(m_ComAdapter.getHostNameList()); - } - }; - m_actAvailableHost = new ExtAction("Available &Server", "Available server", - KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK)) { - public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); - showPleaseWaitDialog(); - Thread xx = new Thread() { - public void run() { - selectAvailableHost(m_ComAdapter.getAvailableHostNameList()); - } - }; - xx.start(); - } - }; - m_actKillHost = new ExtAction("&Kill server", "Kill server process on selected host", - KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) { - public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); - showPleaseWaitDialog(); - Thread xx = new Thread() { - public void run() { - selectAvailableHostToKill(m_ComAdapter.getAvailableHostNameList()); - } - }; - xx.start(); - } - }; - m_actKillAllHosts = new ExtAction("Kill &all servers", "Kill all servers", - KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) { - public void actionPerformed(ActionEvent e) { - logMessage(e.getActionCommand()); - showPleaseWaitDialog(); - Thread xx = new Thread() { - public void run() { - selectAllAvailableHostToKill(m_ComAdapter.getAvailableHostNameList()); - } - }; - xx.start(); - } - }; - /* m_actStartServerManager = new ExtAction("Start &Server Manager", "Start &Server Manager", - KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK)){ - public void actionPerformed(ActionEvent e){ - m_LogPanel.logMessage(e.getActionCommand()); - ServerStartFrame sm = new ServerStartFrame(m_ComAdapter.getHostNameList()); - } - }; - */ - } + public void actionPerformed(ActionEvent e) { + loadModuleFromServer(null, null); + } + }; - private void buildMenu() { - m_barMenu = new JMenuBar(); - m_Frame.setJMenuBar(m_barMenu); - m_mnuModule = new JExtMenu("&Module"); - m_mnuModule.add(m_actModuleLoad); + m_actAbout = new ExtAction("&About...", "Product Information", + KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) { - //////////////////////////////////////////////////////////////// + public void actionPerformed(ActionEvent e) { + logMessage(e.getActionCommand()); + showAboutDialog(); + } + }; + m_actLicense = new ExtAction("&License...", "View License", + KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) { - m_mnuWindow = new JExtMenu("&Window"); - m_mnuWindow.addMenuListener(new MenuListener() { - public void menuSelected(MenuEvent e) { - // System.out.println("Selected"); - m_mnuWindow.removeAll(); - JExtMenu curMenu = m_mnuWindow; + public void actionPerformed(ActionEvent e) { + logMessage(e.getActionCommand()); + showLicense(); + } + }; + m_actHost = new ExtAction("&List of all servers", "All servers in list", + KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) { + + public void actionPerformed(ActionEvent e) { + logMessage(e.getActionCommand()); + selectAvailableHost(m_ComAdapter.getHostNameList()); + } + }; + m_actAvailableHost = new ExtAction("Available &Server", "Available server", + KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK)) { + + public void actionPerformed(ActionEvent e) { + logMessage(e.getActionCommand()); + showPleaseWaitDialog(); + Thread xx = new Thread() { + + public void run() { + selectAvailableHost(m_ComAdapter.getAvailableHostNameList()); + } + }; + xx.start(); + } + }; + m_actKillHost = new ExtAction("&Kill server", "Kill server process on selected host", + KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) { + + public void actionPerformed(ActionEvent e) { + logMessage(e.getActionCommand()); + showPleaseWaitDialog(); + Thread xx = new Thread() { + + public void run() { + selectAvailableHostToKill(m_ComAdapter.getAvailableHostNameList()); + } + }; + xx.start(); + } + }; + m_actKillAllHosts = new ExtAction("Kill &all servers", "Kill all servers", + KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) { + + public void actionPerformed(ActionEvent e) { + logMessage(e.getActionCommand()); + showPleaseWaitDialog(); + Thread xx = new Thread() { + + public void run() { + selectAllAvailableHostToKill(m_ComAdapter.getAvailableHostNameList()); + } + }; + xx.start(); + } + }; + /* + * m_actStartServerManager = new ExtAction("Start &Server Manager", + * "Start &Server Manager", KeyStroke.getKeyStroke(KeyEvent.VK_S, + * Event.CTRL_MASK)){ public void actionPerformed(ActionEvent e){ + * m_LogPanel.logMessage(e.getActionCommand()); ServerStartFrame sm = + * new ServerStartFrame(m_ComAdapter.getHostNameList()); } }; + */ + } + + private void buildMenu() { + m_barMenu = new JMenuBar(); + m_Frame.setJMenuBar(m_barMenu); + m_mnuModule = new JExtMenu("&Module"); + m_mnuModule.add(m_actModuleLoad); + + //////////////////////////////////////////////////////////////// + + m_mnuWindow = new JExtMenu("&Window"); + m_mnuWindow.addMenuListener(new MenuListener() { + + public void menuSelected(MenuEvent e) { + // System.out.println("Selected"); + m_mnuWindow.removeAll(); + JExtMenu curMenu = m_mnuWindow; // JScrollPane jsp = new JScrollPane(); - Object[] framelist = JEFrameRegister.getFrameList(); - for (int i = 0; i < framelist.length; i++) { - JMenuItem act = new JMenuItem((i + 1) + ". " + ((JEFrame) framelist[i]).getTitle()); - final JFrame x = ((JEFrame) framelist[i]); - - act.addActionListener((new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (!x.isActive()) { - x.setExtendedState(JFrame.NORMAL); - x.setVisible(false); - x.setVisible(true); // it seems to be quite a fuss to bring something to the front and actually mean it... - x.toFront(); // this seems useless - x.requestFocus(); // this seems useless too - } - } - })); - if (curMenu.getItemCount()>=maxWindowMenuLength) { - JExtMenu subMenu = new JExtMenu("&More..."); - curMenu.add(new JSeparator()); - curMenu.add(subMenu); - curMenu=subMenu; - } - curMenu.add(act); - } - String[] commonPrefixes = JEFrameRegister.getCommonPrefixes(10); - if (commonPrefixes.length > 0) m_mnuWindow.add(new JSeparator()); - for (int i=0; i= maxWindowMenuLength) { + JExtMenu subMenu = new JExtMenu("&More..."); + curMenu.add(new JSeparator()); + curMenu.add(subMenu); + curMenu = subMenu; + } + curMenu.add(act); + } + String[] commonPrefixes = JEFrameRegister.getCommonPrefixes(10); + if (commonPrefixes.length > 0) { + m_mnuWindow.add(new JSeparator()); + } + for (int i = 0; i < commonPrefixes.length; i++) { + final String prefix = commonPrefixes[i]; + JMenuItem act = new JMenuItem("Close all of " + prefix + "..."); + act.addActionListener((new ActionListener() { + + public void actionPerformed(ActionEvent e) { + JEFrameRegister.closeAllByPrefix(prefix); + } + })); + m_mnuWindow.add(act); + } + + } + + public void menuCanceled(MenuEvent e) { + } + + public void menuDeselected(MenuEvent e) { + } + }); + + //////////////////////////////////////////////////////////////// + m_mnuSelHosts = new JExtMenu("&Select Hosts"); + m_mnuSelHosts.setToolTipText("Select a host for the server application"); + //if (EvAClient.LITE_VERSION == false) + m_mnuSelHosts.add(m_actHost); + m_mnuSelHosts.add(m_actAvailableHost); + m_mnuSelHosts.addSeparator(); + m_mnuSelHosts.add(m_actKillHost); + m_mnuSelHosts.add(m_actKillAllHosts); // m_mnuOptions.add(m_actStartServerManager); - //////////////////////////////////////////////////////////////// - m_mnuAbout = new JExtMenu("&About"); - m_mnuAbout.add(m_actAbout); - m_mnuAbout.add(m_actLicense); - ////////////////////////////////////////////////////////////// - // m_barMenu.add(m_Desktop.getWindowMenu()); - - m_mnuOptions = new JExtMenu("&Options"); - m_mnuOptions.add(m_mnuSelHosts); - //m_barMenu.add(m_mnuSelHosts); - // this is accessible if no default module is given - if (showLoadModules) { - m_barMenu.add(m_mnuModule); - } + //////////////////////////////////////////////////////////////// + m_mnuAbout = new JExtMenu("&About"); + m_mnuAbout.add(m_actAbout); + m_mnuAbout.add(m_actLicense); + ////////////////////////////////////////////////////////////// + // m_barMenu.add(m_Desktop.getWindowMenu()); - m_barMenu.add(m_mnuOptions); - m_barMenu.add(m_mnuWindow); - m_barMenu.add(m_mnuAbout); + m_mnuOptions = new JExtMenu("&Options"); + m_mnuOptions.add(m_mnuSelHosts); + //m_barMenu.add(m_mnuSelHosts); + // this is accessible if no default module is given + if (showLoadModules) { + m_barMenu.add(m_mnuModule); + } - } - - public static String getProductName() { - return EvAInfo.productName; - } - - protected void logMessage(String msg) { - if (TRACE || m_LogPanel == null) System.out.println(msg); - if (m_LogPanel != null) m_LogPanel.logMessage(msg); - } + m_barMenu.add(m_mnuOptions); + m_barMenu.add(m_mnuWindow); + m_barMenu.add(m_mnuAbout); - /** - * - */ - private void loadModuleFromServer(String selectedModule, InterfaceGOParameters goParams) { - if (m_ComAdapter.getHostName() == null) { - System.err.println("error in loadModuleFromServer!"); - return; - } - if (m_ComAdapter.getHostName().equals("localhost")) { - localMode = true; - if (useLocalRMI) { - EvAServer Server = new EvAServer(true, false); - m_ComAdapter.setLocalRMIServer(Server.getRMIServer()); - logMessage("Local EvAServer started"); - m_ComAdapter.setRunLocally(false); // this is not quite true but should have the desired effect - } else { - logMessage("Working locally"); - m_ComAdapter.setLocalRMIServer(null); - m_ComAdapter.setRunLocally(true); - } - } else { - localMode = false; - if (TRACE) logMessage("Using RMI on m_ComAdapter.getHostName()"); - m_ComAdapter.setRunLocally(false); - } - if (selectedModule == null) { // show a dialog and ask for a module - String[] ModuleNameList = m_ComAdapter.getModuleNameList(); - if (ModuleNameList == null) { - JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No modules available on " + m_ComAdapter.getHostName(), EvAInfo.infoTitle, 1); - } else { - String LastModuleName = Serializer.loadString("lastmodule.ser"); - if (LastModuleName == null) LastModuleName = ModuleNameList[0]; - selectedModule = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), - "Which module do you want \n to load on host: " + m_ComAdapter.getHostName() + " ?", "Load optimization module on host", - JOptionPane.QUESTION_MESSAGE, - null, - ModuleNameList, - LastModuleName); - } - } - if (selectedModule == null) { - System.err.println("not loading any module"); - } else { - Serializer.storeString("lastmodule.ser", selectedModule); + } - loadSpecificModule(selectedModule, goParams); + public static String getProductName() { + return EvAInfo.productName; + } - if (withGUI) { - m_actHost.setEnabled(true); - m_actAvailableHost.setEnabled(true); - } - logMessage("Selected Module: " + selectedModule); + protected void logMessage(String msg) { + if (m_LogPanel != null) { + m_LogPanel.logMessage(msg); + } + } + + /** + * + */ + private void loadModuleFromServer(String selectedModule, InterfaceGOParameters goParams) { + if (m_ComAdapter.getHostName() == null) { + System.err.println("error in loadModuleFromServer!"); + return; + } + if (m_ComAdapter.getHostName().equals("localhost")) { + localMode = true; + if (useLocalRMI) { + EvAServer Server = new EvAServer(true, false); + m_ComAdapter.setLocalRMIServer(Server.getRMIServer()); + logMessage("Local EvAServer started"); + m_ComAdapter.setRunLocally(false); // this is not quite true but should have the desired effect + } else { + logMessage("Working locally"); + m_ComAdapter.setLocalRMIServer(null); + m_ComAdapter.setRunLocally(true); + } + } else { + localMode = false; + m_ComAdapter.setRunLocally(false); + } + if (selectedModule == null) { // show a dialog and ask for a module + String[] ModuleNameList = m_ComAdapter.getModuleNameList(); + if (ModuleNameList == null) { + JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No modules available on " + m_ComAdapter.getHostName(), EvAInfo.infoTitle, 1); + } else { + String LastModuleName = Serializer.loadString("lastmodule.ser"); + if (LastModuleName == null) { + LastModuleName = ModuleNameList[0]; + } + selectedModule = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), + "Which module do you want \n to load on host: " + m_ComAdapter.getHostName() + " ?", "Load optimization module on host", + JOptionPane.QUESTION_MESSAGE, + null, + ModuleNameList, + LastModuleName); + } + } + if (selectedModule == null) { + System.err.println("not loading any module"); + } else { + Serializer.storeString("lastmodule.ser", selectedModule); + + loadSpecificModule(selectedModule, goParams); + + if (withGUI) { + m_actHost.setEnabled(true); + m_actAvailableHost.setEnabled(true); + } + logMessage("Selected Module: " + selectedModule); // m_LogPanel.statusMessage("Selected Module: " + selectedModule); - } - } - - /** - * Retrieve the GOParamters of a loaded module. Return null if no module is loaded. - * - * @return - */ - public InterfaceGOParameters getGOParameters() { - if (currentModuleAdapter != null) { - if (currentModuleAdapter instanceof AbstractModuleAdapter) { - return ((AbstractModuleAdapter) currentModuleAdapter).getGOParameters(); - } - } - return null; - } - - public AbstractStatistics getStatistics() { - return ((GenericModuleAdapter) currentModuleAdapter).getStatistics(); - } - - public InterfaceStatisticsParameter getStatsParams() { - return ((GenericModuleAdapter) currentModuleAdapter).getStatistics().getStatisticsParameter(); - } - - /** - * Check if there is an optimization currently running. - * - * @return - */ - public boolean isOptRunning() { - if ((currentModuleAdapter != null) && (currentModuleAdapter instanceof AbstractModuleAdapter)) { - return ((AbstractModuleAdapter) currentModuleAdapter).isOptRunning(); - } else return false; - } + } + } - private void loadSpecificModule(String selectedModule, InterfaceGOParameters goParams) { - ModuleAdapter newModuleAdapter = null; - // - try { - newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2"); - } catch (Exception e) { - logMessage("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); - e.printStackTrace(); - EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); - } - if (newModuleAdapter == null) { - // When launching a Java Web Start application, baseDir will always be null! - URL baseDir = getClass().getClassLoader().getResource(""); - String cp = System.getProperty("java.class.path","."); - String dir = (baseDir == null) ? System.getProperty("user.dir") : baseDir.getPath(); - // System.err.println("Working dir: " + dir); - if (baseDir == null) { - throw new RuntimeException("Cannot launch EvA2 due to an access restriction. If you are using Java Web Start, please download the application and try again."); - } - if (!cp.contains(dir)) { - // this was added due to matlab not adding base dir to base path... - System.err.println("classpath does not contain base directory!"); - System.err.println("adding base dir and trying again..."); - System.setProperty("java.class.path", cp + System.getProperty("path.separator") + dir); - ReflectPackage.resetDynCP(); - m_ComAdapter.updateLocalMainAdapter(); - loadSpecificModule(selectedModule, goParams); // end recursive call! handle with care! - return; - } - showLoadModules = true; - } - else { - newModuleAdapter.setConnection(!localMode); - if (m_ComAdapter.isRunLocally()) { - // TODO in rmi-mode this doesnt work yet! meaning e.g. that theres no content in the info log - newModuleAdapter.addRemoteStateListener((RemoteStateListener)this); - } - try { - if (withGUI) { - // this (or rather: EvAModuleButtonPanelMaker) is where the start button etc come from! - frmMkr = newModuleAdapter.getModuleFrame(); + /** + * Retrieve the GOParamters of a loaded module. Return null if no module is + * loaded. + * + * @return + */ + public InterfaceGOParameters getGOParameters() { + if (currentModuleAdapter != null) { + if (currentModuleAdapter instanceof AbstractModuleAdapter) { + return ((AbstractModuleAdapter) currentModuleAdapter).getGOParameters(); + } + } + return null; + } + + public AbstractStatistics getStatistics() { + return ((GenericModuleAdapter) currentModuleAdapter).getStatistics(); + } + + public InterfaceStatisticsParameter getStatsParams() { + return ((GenericModuleAdapter) currentModuleAdapter).getStatistics().getStatisticsParameter(); + } + + /** + * Check if there is an optimization currently running. + * + * @return + */ + public boolean isOptRunning() { + if ((currentModuleAdapter != null) && (currentModuleAdapter instanceof AbstractModuleAdapter)) { + return ((AbstractModuleAdapter) currentModuleAdapter).isOptRunning(); + } else { + return false; + } + } + + private void loadSpecificModule(String selectedModule, InterfaceGOParameters goParams) { + ModuleAdapter newModuleAdapter = null; + // + try { + newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2"); + } catch (Exception e) { + logMessage("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); + e.printStackTrace(); + EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); + } + if (newModuleAdapter == null) { + // When launching a Java Web Start application, baseDir will always be null! + URL baseDir = getClass().getClassLoader().getResource(""); + String cp = System.getProperty("java.class.path", "."); + String dir = (baseDir == null) ? System.getProperty("user.dir") : baseDir.getPath(); + // System.err.println("Working dir: " + dir); + if (baseDir == null) { + throw new RuntimeException("Cannot launch EvA2 due to an access restriction. If you are using Java Web Start, please download the application and try again."); + } + if (!cp.contains(dir)) { + // this was added due to matlab not adding base dir to base path... + System.err.println("classpath does not contain base directory!"); + System.err.println("adding base dir and trying again..."); + System.setProperty("java.class.path", cp + System.getProperty("path.separator") + dir); + ReflectPackage.resetDynCP(); + m_ComAdapter.updateLocalMainAdapter(); + loadSpecificModule(selectedModule, goParams); // end recursive call! handle with care! + return; + } + showLoadModules = true; + } else { + newModuleAdapter.setConnection(!localMode); + if (m_ComAdapter.isRunLocally()) { + // TODO in rmi-mode this doesnt work yet! meaning e.g. that theres no content in the info log + newModuleAdapter.addRemoteStateListener((RemoteStateListener) this); + } + try { + if (withGUI) { + // this (or rather: EvAModuleButtonPanelMaker) is where the start button etc come from! + frameMaker = newModuleAdapter.getModuleFrame(); // newModuleAdapter.setLogPanel(m_LogPanel); - JPanel moduleContainer = frmMkr.makePanel(); // MK the main frame is actually painted in here + JPanel moduleContainer = frameMaker.makePanel(); // MK the main frame is actually painted in here - boolean wasVisible = m_Frame.isVisible(); - m_Frame.setVisible(false); - m_Frame.getContentPane().removeAll(); - - // nested info-panel so that we can stay with simple borderlayouts - JPanel infoPanel = new JPanel(); - infoPanel.setLayout(new BorderLayout()); - infoPanel.add(m_ProgressBar, BorderLayout.SOUTH); - infoPanel.add(m_LogPanel, BorderLayout.NORTH); - JComponent tree=null; - - if (withTreeView && (newModuleAdapter instanceof AbstractModuleAdapter)) { - tree = getEvATreeView(frmMkr.getGOPanel(), "GOParameters", ((AbstractModuleAdapter)newModuleAdapter).getGOParameters()); - m_Frame.add(tree, BorderLayout.WEST); - } - m_Frame.add(frmMkr.getToolBar(), BorderLayout.NORTH); - m_Frame.add(moduleContainer, BorderLayout.CENTER); - //m_Frame.add(m_ProgressBar, BorderLayout.CENTER); - //m_Frame.add(m_LogPanel, BorderLayout.SOUTH); - m_Frame.add(infoPanel, BorderLayout.SOUTH); - - m_Frame.pack(); - m_Frame.setVisible(wasVisible); - } - - currentModule = selectedModule; - // m_ModulGUIContainer.add(Temp); - } catch (Exception e) { - currentModule = null; - e.printStackTrace(); - logMessage("Error while newModulAdapter.getModulFrame(): " + e.getMessage()); - EVAERROR.EXIT("Error while newModulAdapter.getModulFrame(): " + e.getMessage()); - } + boolean wasVisible = m_Frame.isVisible(); + m_Frame.setVisible(false); + m_Frame.getContentPane().removeAll(); + + // nested info-panel so that we can stay with simple borderlayouts + JPanel infoPanel = new JPanel(); + infoPanel.setLayout(new BorderLayout()); + infoPanel.add(m_ProgressBar, BorderLayout.SOUTH); + infoPanel.add(m_LogPanel, BorderLayout.NORTH); + JComponent tree = null; + + if (withTreeView && (newModuleAdapter instanceof AbstractModuleAdapter)) { + tree = getEvATreeView(frameMaker.getGOPanel(), "GOParameters", ((AbstractModuleAdapter) newModuleAdapter).getGOParameters()); + m_Frame.add(tree, BorderLayout.WEST); + } + m_Frame.add(frameMaker.getToolBar(), BorderLayout.NORTH); + m_Frame.add(moduleContainer, BorderLayout.CENTER); + //m_Frame.add(m_ProgressBar, BorderLayout.CENTER); + //m_Frame.add(m_LogPanel, BorderLayout.SOUTH); + m_Frame.add(infoPanel, BorderLayout.SOUTH); + + m_Frame.pack(); + m_Frame.setVisible(wasVisible); + } + + currentModule = selectedModule; + // m_ModulGUIContainer.add(Temp); + } catch (Exception e) { + currentModule = null; + e.printStackTrace(); + logMessage("Error while newModulAdapter.getModulFrame(): " + e.getMessage()); + EVAERROR.EXIT("Error while newModulAdapter.getModulFrame(): " + e.getMessage()); + } // try { TODO whats this? // newModuleAdapter.setConnection(true); // } catch (Exception e) { @@ -929,151 +959,160 @@ public class EvAClient implements RemoteStateListener, Serializable { // m_LogPanel.logMessage("Error while m_ComAdapter.AddRMIPlotListener Host: " + e.getMessage()); // EVAERROR.EXIT("Error while m_ComAdapter.AddRMIPlotListener: " + e.getMessage()); // } - // set mode (rmi or not) + // set mode (rmi or not) - // ModuladapterListe adden + // ModuladapterListe adden // m_ModuleAdapterList.add(newModuleAdapter); - currentModuleAdapter = newModuleAdapter; - } - } + currentModuleAdapter = newModuleAdapter; + } + } - /** - * Create a tree view of an object based on EvATreeNode. It is encapsulated - * in a JScrollPane. - * - * @see EvATreeNode - * @param title - * @param object - * @return - */ - public JComponent getEvATreeView(JParaPanel goPanel, String title, Object object) { - EvATreeNode root = new EvATreeNode(title, object); // the root of the tree - JTree jtree = new JTree(root); - JScrollPane treeView = new JScrollPane(jtree); + /** + * Create a tree view of an object based on EvATreeNode. It is encapsulated + * in a JScrollPane. + * + * @see EvATreeNode + * @param title + * @param object + * @return + */ + public JComponent getEvATreeView(JParaPanel goPanel, String title, Object object) { + EvATreeNode root = new EvATreeNode(title, object); // the root of the tree + JTree jtree = new JTree(root); + JScrollPane treeView = new JScrollPane(jtree); - EvATreeSelectionListener treeListener = new EvATreeSelectionListener(root, goPanel.getEditor(), jtree); - // hooks itself up as the tree listener. It reacts both to changes in the selection - // state of the tree (to update the parameter panel) and to changes in the - // parameters to update the tree - return treeView; - } - /** - * - */ - private void selectAvailableHost(String[] HostNames) { - if (TRACE) System.out.println("SelectAvailableHost"); - if (HostNames == null || HostNames.length == 0) { - showNoHostFoundDialog(); - } else { - String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), - "Which active host do you want to connect to?", "Host", JOptionPane.QUESTION_MESSAGE, null, - HostNames, m_ComAdapter.getHostName()); - if (HostName != null) selectHost(HostName); - } - } - - private void selectHost(String hostName) { - m_ComAdapter.setHostName(hostName); - logMessage("Selected Host: " + hostName); - if (currentModule != null) { - logMessage("Reloading module from server..."); - loadModuleFromServer(currentModule, null); - } - -// m_mnuModule.setText("Select module"); -// m_mnuModule.repaint(); - // System.out.println(HostName + " selected"); - } - - private void showPleaseWaitDialog() { - JOptionPane.showMessageDialog(m_Frame.getContentPane(), "Please wait one moment.", EvAInfo.infoTitle, 1); - } - - private void showAboutDialog() { - JOptionPane.showMessageDialog - (m_Frame, - EvAInfo.productName + " - " + EvAInfo.productLongName + - "\nUniversity of Tuebingen, T\u00FCbingen, Germany\nChair for Cognitive Systems\n" + - "Dr. M. Kronfeld, H. Planatscher, M. de Paly, Dr. A. Dr\u00E4ger,\n" + - "Dr. F. Streichert, Dr. H. Ulmer, and Prof. Dr. A. Zell \nCoypright \u00A9 " + - EvAInfo.copyrightYear + "\nVersion " + EvAInfo.getVersion()+ - "\nSee: " + EvAInfo.url, EvAInfo.infoTitle, 1); - } - - private void showLicense() { - HtmlDemo lgpl = new HtmlDemo(EvAInfo.LGPLFile); - HtmlDemo gpl = new HtmlDemo(EvAInfo.GPLFile); + EvATreeSelectionListener treeListener = new EvATreeSelectionListener(root, goPanel.getEditor(), jtree); + // hooks itself up as the tree listener. It reacts both to changes in the selection + // state of the tree (to update the parameter panel) and to changes in the + // parameters to update the tree + return treeView; + } + + /** + * + */ + private void selectAvailableHost(String[] HostNames) { + if (HostNames == null || HostNames.length == 0) { + showNoHostFoundDialog(); + } else { + String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), + "Which active host do you want to connect to?", "Host", JOptionPane.QUESTION_MESSAGE, null, + HostNames, m_ComAdapter.getHostName()); + if (HostName != null) { + selectHost(HostName); + } + } + } + + private void selectHost(String hostName) { + m_ComAdapter.setHostName(hostName); + logMessage("Selected Host: " + hostName); + if (currentModule != null) { + logMessage("Reloading module from server..."); + loadModuleFromServer(currentModule, null); + } + } + + private void showPleaseWaitDialog() { + JOptionPane.showMessageDialog(m_Frame.getContentPane(), "Please wait one moment.", EvAInfo.infoTitle, 1); + } + + private void showAboutDialog() { + JOptionPane.showMessageDialog(m_Frame, + EvAInfo.productName + " - " + EvAInfo.productLongName + + "\nUniversity of Tuebingen, T\u00FCbingen, Germany\nChair for Cognitive Systems\n" + + "Dr. M. Kronfeld, H. Planatscher, M. de Paly, Dr. A. Dr\u00E4ger,\n" + + "Dr. F. Streichert, Dr. H. Ulmer, and Prof. Dr. A. Zell \nCoypright \u00A9 " + + EvAInfo.copyrightYear + "\nVersion " + EvAInfo.getVersion() + + "\nSee: " + EvAInfo.url, EvAInfo.infoTitle, 1); + } + + private void showLicense() { + HtmlDemo lgpl = new HtmlDemo(EvAInfo.LGPLFile); + HtmlDemo gpl = new HtmlDemo(EvAInfo.GPLFile); gpl.show(); lgpl.show(); - } - - private void showNoHostFoundDialog() { - JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No host with running EVASERVER found. Please start one or \nadd the correct address to the properties list.", EvAInfo.infoTitle, 1); - } + } - private void selectAvailableHostToKill(String[] HostNames) { - if (TRACE) System.out.println("SelectAvailableHostToKill"); - if (HostNames == null || HostNames.length == 0) { - showNoHostFoundDialog(); - return; - } - String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), - "Which server do you want to be killed ?", "Host", JOptionPane.QUESTION_MESSAGE, null, - HostNames, m_ComAdapter.getHostName()); - if (HostName == null) - return; - logMessage("Kill host process on = " + HostName); - m_ComAdapter.killServer(HostName); + private void showNoHostFoundDialog() { + JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No host with running EVASERVER found. Please start one or \nadd the correct address to the properties list.", EvAInfo.infoTitle, 1); + } + + private void selectAvailableHostToKill(String[] HostNames) { + if (HostNames == null || HostNames.length == 0) { + showNoHostFoundDialog(); + return; + } + String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), + "Which server do you want to be killed ?", "Host", JOptionPane.QUESTION_MESSAGE, null, + HostNames, m_ComAdapter.getHostName()); + if (HostName == null) { + return; + } + logMessage("Kill host process on = " + HostName); + m_ComAdapter.killServer(HostName); // m_LogPanel.statusMessage(""); - } + } - private void selectAllAvailableHostToKill(String[] HostNames) { - System.out.println("SelectAllAvailableHostToKill"); - if (HostNames == null || HostNames.length == 0) { - System.out.println("no host is running"); - return; - } - m_ComAdapter.killAllServers(); - } + private void selectAllAvailableHostToKill(String[] HostNames) { + System.out.println("SelectAllAvailableHostToKill"); + if (HostNames == null || HostNames.length == 0) { + System.out.println("no host is running"); + return; + } + m_ComAdapter.killAllServers(); + } - public void performedRestart(String infoString) { - if (superListenerList != null) for (RemoteStateListener l : superListenerList) { - l.performedRestart(infoString); - } - logMessage("Restarted processing " + infoString); - startTime = System.currentTimeMillis(); - } + public void performedRestart(String infoString) { + if (superListenerList != null) { + for (RemoteStateListener l : superListenerList) { + l.performedRestart(infoString); + } + } + logMessage("Restarted processing " + infoString); + startTime = System.currentTimeMillis(); + } - public void performedStart(String infoString) { - if (superListenerList != null) for (RemoteStateListener l : superListenerList) { - l.performedStart(infoString); - } - logMessage("Started processing " + infoString); - startTime = System.currentTimeMillis(); - } + public void performedStart(String infoString) { + if (superListenerList != null) { + for (RemoteStateListener l : superListenerList) { + l.performedStart(infoString); + } + } + logMessage("Started processing " + infoString); + startTime = System.currentTimeMillis(); + } + + public void performedStop() { + if (superListenerList != null) { + for (RemoteStateListener l : superListenerList) { + l.performedStop(); + } + } + long t = (System.currentTimeMillis() - startTime); + logMessage(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000))); + if (!withGUI) { + System.exit(0); + } + } - public void performedStop() { - if (superListenerList != null) for (RemoteStateListener l : superListenerList) { - l.performedStop(); - } - long t = (System.currentTimeMillis() - startTime); - logMessage(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000))); - if (!withGUI) System.exit(0); - } - /** - * When the worker needs to update the GUI we do so by queuing - * a Runnable for the event dispatching thread with - * SwingUtilities.invokeLater(). In this case we're just - * changing the progress bars value. + * When the worker needs to update the GUI we do so by queuing a Runnable + * for the event dispatching thread with SwingUtilities.invokeLater(). In + * this case we're just changing the progress bars value. */ - public void updateProgress(final int percent, String msg) { - if (superListenerList != null) for (RemoteStateListener l : superListenerList) { - l.updateProgress(percent, msg); - } - if (msg != null) logMessage(msg); + public void updateProgress(final int percent, String msg) { + if (superListenerList != null) { + for (RemoteStateListener l : superListenerList) { + l.updateProgress(percent, msg); + } + } + if (msg != null) { + logMessage(msg); + } if (this.m_ProgressBar != null) { Runnable doSetProgressBarValue = new Runnable() { + public void run() { m_ProgressBar.setValue(percent); } @@ -1084,53 +1123,55 @@ public class EvAClient implements RemoteStateListener, Serializable { } final class SplashScreenShell { - SplashScreen splScr = null; - String imgLoc = null; - - public SplashScreenShell(String imageLoc) { - imgLoc = imageLoc; - } - - public void splash() { - splScr = new SplashScreen(imgLoc); - splScr.splash(); - } - - public void dispose() { - if (splScr!=null) { - splScr.dispose(); - splScr=null; - } - } + + SplashScreen splScr = null; + String imgLoc = null; + + public SplashScreenShell(String imageLoc) { + imgLoc = imageLoc; + } + + public void splash() { + splScr = new SplashScreen(imgLoc); + splScr.splash(); + } + + public void dispose() { + if (splScr != null) { + splScr.dispose(); + splScr = null; + } + } } class SplashScreen extends Frame { - private static final long serialVersionUID = 1281793825850423095L; - String imgLocation; - public SplashScreen(String imgLoc) { - imgLocation = imgLoc; - } + private static final long serialVersionUID = 1281793825850423095L; + String imgLocation; - /** - * Show the splash screen to the end user. - * - *

Once this method returns, the splash screen is realized, which means - * that almost all work on the splash screen should proceed through the event - * dispatch thread. In particular, any call to dispose for the - * splash screen must be performed in the event dispatch thread. - */ - public void splash(){ - JWindow splashWindow = new JWindow(this); - BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true); - ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)); - JLabel splashLabel = new JLabel(ii); - splashWindow.add(splashLabel); - splashWindow.pack(); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2); - splashWindow.setVisible(true); - } + public SplashScreen(String imgLoc) { + imgLocation = imgLoc; + } + /** + * Show the splash screen to the end user. + * + *

Once this method returns, the splash screen is realized, which means + * that almost all work on the splash screen should proceed through the + * event dispatch thread. In particular, any call to + * dispose for the splash screen must be performed in the event + * dispatch thread. + */ + public void splash() { + JWindow splashWindow = new JWindow(this); + BasicResourceLoader loader = BasicResourceLoader.instance(); + byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true); + ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)); + JLabel splashLabel = new JLabel(ii); + splashWindow.add(splashLabel); + splashWindow.pack(); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2); + splashWindow.setVisible(true); + } } \ No newline at end of file diff --git a/src/eva2/server/EvAServer.java b/src/eva2/server/EvAServer.java index a739cd57..7f636f79 100644 --- a/src/eva2/server/EvAServer.java +++ b/src/eva2/server/EvAServer.java @@ -1,142 +1,138 @@ package eva2.server; /* - * Title: EvA2 - * Description: - * Copyright: Copyright (c) 2003 - * Company: University of Tuebingen, Computer Architecture - * @author Holger Ulmer, Felix Streichert, Hannes Planatscher - * @version: $Revision: 320 $ - * $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $ - * $Author: mkron $ + * Title: EvA2 Description: Copyright: Copyright (c) 2003 Company: University of + * Tuebingen, Computer Architecture @author Holger Ulmer, Felix Streichert, + * Hannes Planatscher @version: $Revision: 320 $ $Date: 2007-12-06 16:05:11 + * +0100 (Thu, 06 Dec 2007) $ $Author: mkron $ */ -/*==========================================================================* - * IMPORTS - *==========================================================================*/ -import java.io.BufferedReader; -import java.io.FileOutputStream; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.net.InetAddress; import eva2.EvAInfo; +import java.io.*; +import java.net.InetAddress; +import java.net.UnknownHostException; /** * */ public class EvAServer { - public static boolean TRACE = false; - /* MainAdapterImp object. This is need for the first - connection between the server and the client program. */ - public EvAMainAdapter m_MainRemoteObject; - //private EvAComAdapter m_ComAdapter; - public static String m_UserName; - public static int m_NumberOfVM =0; - private RMIServerEvA m_RMIServer; - /** - * Constructor of EvAServer. - * Calls RMIConnection(). - */ - public EvAServer(boolean insideClient, boolean Restart) { - System.out.println ("Number of CPUs :" +Runtime.getRuntime().availableProcessors()); -// m_InsideClient = insideClient; -// m_Restart = Restart; - System.out.println ("*******************************************************************************"); - System.out.println ("This is EvA Server Version: "+ EvAInfo.getVersion()); - //System.out.println ("Java Version: " + System.getProperty("java.version") ); - System.out.println ("*******************************************************************************"); - m_UserName = System.getProperty("user.name"); + /* + * MainAdapterImp object. This is need for the first connection between the + * server and the client program. + */ + public EvAMainAdapter m_MainRemoteObject; + //private EvAComAdapter m_ComAdapter; + public static String m_UserName; + public static int m_NumberOfVM = 0; + private RMIServerEvA m_RMIServer; + + /** + * Constructor of EvAServer. Calls RMIConnection(). + */ + public EvAServer(boolean insideClient, boolean Restart) { + System.out.println("Number of CPUs :" + Runtime.getRuntime().availableProcessors()); + System.out.println("*******************************************************************************"); + System.out.println("This is EvA Server Version: " + EvAInfo.getVersion()); + //System.out.println ("Java Version: " + System.getProperty("java.version") ); + System.out.println("*******************************************************************************"); + m_UserName = System.getProperty("user.name"); // RMIConnection(); // m_ComAdapter = new EvAComAdapter(); // RMIProxyRemote.setComAdaper(m_ComAdapter); - m_RMIServer = RMIServerEvA.getInstance(); - } - /** - * Main method of this class. - * Is the starting point of the server application. - */ - static public void main ( String[] args ){ - boolean Restart = false; - boolean nomulti = false; - for (int i=0;i started not inside the client, solo server + /** + * Main method of this class. Is the starting point of the server + * application. + */ + static public void main(String[] args) { + boolean restart = false; + boolean noMulti = false; + for (int i = 0; i < args.length; i++) { + System.out.println("args = " + args[i]); + if (args[i].equals("restart")) { + restart = true; + } + if (args[i].equals("nomulti")) { + noMulti = true; + } + + } + //Runtime.getRuntime().addShutdownHook(new ExitThread()); + if (restart == true) { + String hostName = "Host"; + try { + hostName = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + System.out.println("ERROR getting HostName (EvAServer.main) " + e.getMessage()); + } + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + System.out.println("Error in sleep of ExitThread"); + } + + try { + System.setOut(new PrintStream( + new FileOutputStream(hostName + "_server.txt"))); + } catch (FileNotFoundException e) { + System.out.println("System.setOut" + e.getMessage()); + } + } + EvAServer evaServer = new EvAServer(false, restart); // false => started not inside the client, solo server // if (nomulti==false) -// Application.multiServers(1); +// evaServer.multiServers(1); - } - /** - * - */ - public void multiServers(int size) { - for (int i =0;i= MAXinstances) { -// // if (i>200) -// // System.out.println(i+ " waiting "+m_instances+ " on "+x.hashCode()+ " m "+m.getName()+" m_MAXinstances " +MAXinstances); -// // pleasewait(); -// try { -// Thread.sleep(i); -// i=2*i; //System.out.println(""+i); -// } catch (Exception e) { -// System.out.println("Error in sleep of XThread"); -// } -// } -// instup();//m_instances++; -// if ( -// XThread ret = new XThread(x, m, Para); -// // m_ThreadContainer.add(ret); -// return ret; - } /** * */ public static XThread getXThread(Object x, String m, Object[] Para, int MAXinstances) { - if (TRACE) System.out.println("getXThread1 CALLLED"); -// while (m_instances >= MAXinstances) { -// //System.out.println("waiting "+m_instances); -// //pleasewait(); -// try { -// Thread.sleep(50); -// } catch (Exception e) { -// System.out.println("Error in sleep of XThread"); -// } -// } -// instup(); //m_instances++; -// //System.out.println("XThread ++"+m_instances+" m_MAXinstances " +m_MAXinstances); -// XThread ret = new XThread(x, Method, Para); -// // m_ThreadContainer.add(ret); -// return ret; XThread ret = null; if (m_Instances == null) init(MAXinstances); @@ -169,27 +132,10 @@ public class XThread extends Thread implements Serializable { } - /** - * - */ -// public static synchronized void pleasewait() { -// for (int i = 0; i < m_ThreadContainer.size(); i++) { -// try { -// if (((Thread) m_ThreadContainer.get(i)).isAlive()==false) -// m_ThreadContainer.remove(i); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// System.out.println("Error"); -// } -// } -// } - private void removemyself() { for (int i = 0; i < m_Instances.length; i++) { -// if (TRACE) System.out.println("TRYING TO REMOVE"); if (this.m_Instances[i] == this) { this.m_Instances[i] = null; - if (TRACE) System.out.println("REMOVED THREAD"); return; } } @@ -199,7 +145,6 @@ public class XThread extends Thread implements Serializable { * */ private XThread(Object object, Method method, Object[] Para) { - if (TRACE) System.out.println("XTHREAD INSTANZIERT"); m_Object = object; m_Para = Para; m_Method = method; @@ -210,7 +155,6 @@ public class XThread extends Thread implements Serializable { * */ private XThread(Object x, String method, Object[] Para) { - if (TRACE) System.out.println("XTHREAD INSTANZIERT"); m_Object = x; m_Para = Para; try { @@ -232,18 +176,10 @@ public class XThread extends Thread implements Serializable { * */ public void run() { - if (TRACE) System.out.println("XTHREAD CALLED RUN on " + this); if (m_Method != null) { //setPriority(Thread.MAX_PRIORITY); try { - if (TRACE) System.out.println("XTHREAD calling m_Method "+m_Method.getName()); - //System.out.print("--->"); - //this.setPriority(Thread.MAX_PRIORITY); m_Method.invoke(m_Object, m_Para); - - //instdown(); //m_instances--; - //System.out.println("<--"); - //System.out.println("XThread --"+m_instances+" m_MAXinstances " +m_MAXinstances); } catch (Exception e) { System.err.println("ERROR +" + e.getMessage()); e.printStackTrace();