Logging is now completely implemented for EvA2Client class.
This commit is contained in:
Fabian Becker 2012-04-15 22:45:31 +00:00
parent e721e06e11
commit 454ddbc20f
4 changed files with 323 additions and 292 deletions

View File

@ -99,6 +99,8 @@ public class EvAInfo {
public static final String infoTitle = productName+" Information";
public static final String copyrightYear = "2010-2012";
public static final String defaultLogger = "EvA2";
////////////// Property handling...
private static Properties evaProperties;

View File

@ -442,8 +442,6 @@ public class EvAClient implements RemoteStateListener, Serializable {
}
});
logger.info("EvAClient Loggin enabled");
logger.warning("Logging could still die.");
m_ProgressBar = new JProgressBar();
evaFrame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH);
@ -469,7 +467,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
evaFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("Closing EvA2 Client. Bye!");
logger.info("Closing EvA2 Client. Bye!");
evaFrame.dispose();
Set<String> keys = System.getenv().keySet();
if (keys.contains("MATLAB")) {
@ -488,14 +486,14 @@ public class EvAClient implements RemoteStateListener, Serializable {
selectHost(hostName);
}
m_ComAdapter.setLogPanel(logPanel);
logMessage("Selected Host: " + m_ComAdapter.getHostName());
logger.log(Level.INFO, "Selected Host: {0}", m_ComAdapter.getHostName());
}
// m_mnuModule.setText("Select module");
// m_mnuModule.repaint();
if (withGUI) {
logPanel.logMessage("Working directory is: " + System.getProperty("user.dir"));
logPanel.logMessage("Class path is: " + System.getProperty("java.class.path", "."));
logger.log(Level.INFO, "Working directory is: {0}", System.getProperty("user.dir"));
logger.log(Level.INFO, "Class path is: {0}", System.getProperty("java.class.path", "."));
if (!(evaFrame.isVisible())) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
@ -503,7 +501,9 @@ public class EvAClient implements RemoteStateListener, Serializable {
evaFrame.pack();
evaFrame.setVisible(true);
}
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
// 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
logger.info("EvA2 ready");
}
}
@ -635,7 +635,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
@Override
public void actionPerformed(ActionEvent e) {
logMessage(e.getActionCommand());
logger.info(e.getActionCommand());
showAboutDialog();
}
};
@ -644,7 +644,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
@Override
public void actionPerformed(ActionEvent e) {
logMessage(e.getActionCommand());
logger.info(e.getActionCommand());
showLicense();
}
};
@ -653,7 +653,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
@Override
public void actionPerformed(ActionEvent e) {
logMessage(e.getActionCommand());
logger.info(e.getActionCommand());
selectAvailableHost(m_ComAdapter.getHostNameList());
}
};
@ -662,7 +662,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
@Override
public void actionPerformed(ActionEvent e) {
logMessage(e.getActionCommand());
logger.info(e.getActionCommand());
showPleaseWaitDialog();
Thread xx = new Thread() {
@ -679,7 +679,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
@Override
public void actionPerformed(ActionEvent e) {
logMessage(e.getActionCommand());
logger.info(e.getActionCommand());
showPleaseWaitDialog();
Thread xx = new Thread() {
@ -695,7 +695,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
@Override
public void actionPerformed(ActionEvent e) {
logMessage(e.getActionCommand());
logger.info(e.getActionCommand());
showPleaseWaitDialog();
Thread xx = new Thread() {
@ -835,10 +835,10 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (useLocalRMI) {
EvAServer Server = new EvAServer(true, false);
m_ComAdapter.setLocalRMIServer(Server.getRMIServer());
logMessage("Local EvAServer started");
logger.info("Local EvAServer started");
m_ComAdapter.setRunLocally(false); // this is not quite true but should have the desired effect
} else {
logMessage("Working locally");
logger.info("Working locally");
m_ComAdapter.setLocalRMIServer(null);
m_ComAdapter.setRunLocally(true);
}
@ -874,7 +874,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
m_actHost.setEnabled(true);
m_actAvailableHost.setEnabled(true);
}
logMessage("Selected Module: " + selectedModule);
logger.info("Selected Module: " + selectedModule);
// m_LogPanel.statusMessage("Selected Module: " + selectedModule);
}
}
@ -921,8 +921,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
try {
newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2");
} catch (Exception e) {
logMessage("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage());
e.printStackTrace();
logger.log(Level.SEVERE, "Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage(), e);
EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage());
}
if (newModuleAdapter == null) {
@ -1044,9 +1043,9 @@ public class EvAClient implements RemoteStateListener, Serializable {
private void selectHost(String hostName) {
m_ComAdapter.setHostName(hostName);
logMessage("Selected Host: " + hostName);
logger.info("Selected Host: " + hostName);
if (currentModule != null) {
logMessage("Reloading module from server...");
logger.info("Reloading module from server...");
loadModuleFromServer(currentModule, null);
}
}
@ -1094,14 +1093,14 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (HostName == null) {
return;
}
logMessage("Kill host process on = " + HostName);
logger.info("Kill host process on = " + HostName);
m_ComAdapter.killServer(HostName);
// m_LogPanel.statusMessage("");
}
private void selectAllAvailableHostToKill(String[] HostNames) {
private void selectAllAvailableHostToKill(String[] hostNames) {
System.out.println("SelectAllAvailableHostToKill");
if (HostNames == null || HostNames.length == 0) {
if (hostNames == null || hostNames.length == 0) {
System.out.println("no host is running");
return;
}
@ -1114,7 +1113,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
l.performedRestart(infoString);
}
}
logMessage("Restarted processing " + infoString);
logger.log(Level.INFO, "Restarted processing {0}", infoString);
startTime = System.currentTimeMillis();
}
@ -1124,7 +1123,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
l.performedStart(infoString);
}
}
logMessage("Started processing " + infoString);
logger.log(Level.INFO, "Started processing {0}", infoString);
startTime = System.currentTimeMillis();
}
@ -1135,7 +1134,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
}
}
long t = (System.currentTimeMillis() - startTime);
logMessage(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000)));
logger.info(String.format("Stopped after %1$d.%2$tL s", (t / 1000), (t % 1000)));
if (!withGUI) {
System.exit(0);
}
@ -1153,7 +1152,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
}
}
if (msg != null) {
logMessage(msg);
logger.info(msg);
}
if (this.m_ProgressBar != null) {
Runnable doSetProgressBarValue = new Runnable() {

View File

@ -1,5 +1,6 @@
package eva2.server.modules;
import eva2.EvAInfo;
import java.util.List;
import java.util.Vector;
@ -31,6 +32,8 @@ import eva2.tools.EVAHELP;
import eva2.tools.StringTools;
import eva2.tools.jproxy.RemoteStateListener;
import eva2.tools.math.RNG;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* The Processor may run as a thread permanently (GenericModuleAdapter) and is then stopped and started
@ -47,25 +50,24 @@ import eva2.tools.math.RNG;
*/
public class Processor extends Thread implements InterfaceProcessor, InterfacePopulationChangedEventListener {
private static final boolean TRACE=false;
private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
private volatile boolean m_optRunning;
// private volatile boolean m_doRunScript;
private InterfaceStatistics m_Statistics;
private InterfaceGOParameters goParams;
private boolean m_createInitialPopulations = true;
private boolean saveParams = true;
private RemoteStateListener m_ListenerModule;
private boolean wasRestarted = false;
// private int postProcessSteps = 0;
private int runCounter = 0;
private Population resPop = null;
private boolean userAborted = false;
// transient private String m_OutputPath = "";
// transient private BufferedWriter m_OutputFile = null;
public void addListener(RemoteStateListener module) {
if (TRACE) System.out.println("Processor: setting module as listener: " + ((module==null) ? "null" : module.toString()));
logger.log(
Level.FINEST,
"Processor: setting module as listener: " + ((module == null)
? "null" : module.toString()));
m_ListenerModule = module;
}
@ -111,9 +113,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
*/
public void startOpt() {
m_createInitialPopulations = true;
if (TRACE) System.out.println("startOpt called:");
if (isOptRunning()) {
System.err.println("ERROR: Processor is already running !!");
logger.log(Level.SEVERE, "Processor is already running.");
return;
}
resPop = null;
@ -137,9 +138,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
*/
public void restartOpt() {
m_createInitialPopulations = false;
if (TRACE) System.out.println("restartOpt called:");
if (isOptRunning()) {
System.err.println("ERROR: Processor is already running !!");
logger.log(Level.SEVERE, "Processor is already running.");
return;
}
userAborted = false;
@ -151,9 +151,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
*
*/
public void stopOpt() { // this means user break
if (TRACE) System.out.println("called StopOpt");
setOptRunning(false);
if (TRACE) System.out.println("m_doRunScript = false ");
}
/**
@ -188,13 +186,17 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
}
} catch (Exception e) {
String errMsg = e.toString();
if ((errMsg == null) || (errMsg.length() == 0)) errMsg="check console output for error messages.";
if ((errMsg == null) || (errMsg.length() == 0)) {
errMsg = "check console output for error messages.";
}
errMsg = "Exception in Processor: " + errMsg;
System.err.println(errMsg);
e.printStackTrace();
try {
JOptionPane.showMessageDialog(null, StringTools.wrapLine(errMsg, 60, 0.2), "Error in Optimization", JOptionPane.ERROR_MESSAGE);
} catch (Exception ex) {} catch(Error er) {};
} catch (Exception ex) {
} catch (Error er) {
};
//m_Statistics.stopOptPerformed(false);
setOptRunning(false); // normal finish
if (m_ListenerModule != null) {
@ -220,8 +222,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
RNG.setRandomSeed(goParams.getSeed());
if (m_ListenerModule != null) {
if (wasRestarted) m_ListenerModule.performedRestart(getInfoString());
else m_ListenerModule.performedStart(getInfoString());
if (wasRestarted) {
m_ListenerModule.performedRestart(getInfoString());
} else {
m_ListenerModule.performedStart(getInfoString());
}
}
goParams.getOptimizer().addPopulationChangedEventListener(this);
@ -236,11 +241,17 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
this.goParams.getOptimizer().SetProblem(this.goParams.getProblem());
this.goParams.getTerminator().init(this.goParams.getProblem());
maybeInitParamCtrl(goParams);
if (this.m_createInitialPopulations) this.goParams.getOptimizer().init();
if (this.m_createInitialPopulations) {
this.goParams.getOptimizer().init();
}
//m_Statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null);
if (popLog != null) EVAHELP.clearLog(popLog);
if (m_ListenerModule != null) {
m_ListenerModule.updateProgress(getStatusPercent(goParams.getOptimizer().getPopulation(), runCounter, m_Statistics.getStatisticsParameter().getMultiRuns()), null);
}
if (popLog != null) {
EVAHELP.clearLog(popLog);
}
do { // main loop
maybeUpdateParamCtrl(goParams);
@ -248,7 +259,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
this.goParams.getOptimizer().optimize();
// registerPopulationStateChanged *SHOULD* be fired by the optimizer or resp. the population
// as we are event listener
if (popLog != null) EVAHELP.logString(this.goParams.getOptimizer().getPopulation().getIndyList(), popLog);
if (popLog != null) {
EVAHELP.logString(this.goParams.getOptimizer().getPopulation().getIndyList(), popLog);
}
} while (isOptRunning() && !this.goParams.getTerminator().isTerminated(this.goParams.getOptimizer().getAllSolutions()));
runCounter++;
maybeFinishParamCtrl(goParams);
@ -262,13 +275,19 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
if (resultPop == null) { // post processing disabled, so use opt. solutions
resultPop = goParams.getOptimizer().getAllSolutions().getSolutions();
}
} else resultPop = goParams.getOptimizer().getAllSolutions().getSolutions();
} else {
resultPop = goParams.getOptimizer().getAllSolutions().getSolutions();
}
m_Statistics.postProcessingPerformed(resultPop);
}
setOptRunning(false); // normal finish
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(0, null);
if (m_ListenerModule != null) {
m_ListenerModule.performedStop(); // is only needed in client server mode
}
if (m_ListenerModule != null) {
m_ListenerModule.updateProgress(0, null);
}
goParams.getOptimizer().removePopulationChangedEventListener(this);
return resultPop;
}
@ -284,19 +303,21 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
// is called recursively.
if (controllerOrSubControllable instanceof InterfaceParameterControl) {
args[0] = instance;
if (!((InterfaceParameterControl)controllerOrSubControllable instanceof ConstantParameters))
if (!((InterfaceParameterControl) controllerOrSubControllable instanceof ConstantParameters)) {
BeanInspector.callIfAvailable((InterfaceParameterControl) controllerOrSubControllable, methodName, args);
}
} else {
args[0] = controllerOrSubControllable;
iterateParamCtrl(controllerOrSubControllable, methodName, args);
}
}
} else if (paramCtrlReturn instanceof InterfaceParameterControl) {
if (!((InterfaceParameterControl)paramCtrlReturn instanceof ConstantParameters))
if (!((InterfaceParameterControl) paramCtrlReturn instanceof ConstantParameters)) {
BeanInspector.callIfAvailable((InterfaceParameterControl) paramCtrlReturn, methodName, args);
}
}
}
}
private void maybeInitParamCtrl(InterfaceGOParameters goParams) {
iterateParamCtrl(goParams.getOptimizer(), "init", new Object[]{goParams.getOptimizer(), goParams.getOptimizer().getPopulation()});
@ -312,13 +333,15 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
Object[] args;
InterfaceTerminator terminator = goParams.getTerminator();
InterfaceOptimizer optimizer = goParams.getOptimizer();
if (terminator instanceof GenerationTerminator)
if (terminator instanceof GenerationTerminator) {
args = new Object[]{optimizer, optimizer.getPopulation(), optimizer.getPopulation().getGeneration(), ((GenerationTerminator) terminator).getGenerations()};
// ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getGeneration(), ((GenerationTerminator)terminator).getGenerations());
else if (terminator instanceof EvaluationTerminator)
} // ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getGeneration(), ((GenerationTerminator)terminator).getGenerations());
else if (terminator instanceof EvaluationTerminator) {
args = new Object[]{optimizer, optimizer.getPopulation(), optimizer.getPopulation().getFunctionCalls(), ((EvaluationTerminator) terminator).getFitnessCalls()};
// ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getFunctionCalls(), ((EvaluationTerminator)terminator).getFitnessCalls());
else args = new Object[]{optimizer};
} // ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer, optimizer.getPopulation().getFunctionCalls(), ((EvaluationTerminator)terminator).getFitnessCalls());
else {
args = new Object[]{optimizer};
}
// ((InterfaceParameterControl)paramCtrl).updateParameters(optimizer);
if (args != null) { // only if iteration counting is available
@ -346,7 +369,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
} else if (this.goParams.getTerminator() instanceof GenerationTerminator) {
double curRunPerf = pop.getGeneration() * percentPerRun / (double) ((GenerationTerminator) this.goParams.getTerminator()).getGenerations();
curProgress = (int) (currentRun * percentPerRun + curRunPerf);
} else curProgress = (int)(currentRun * percentPerRun);
} else {
curProgress = (int) (currentRun * percentPerRun);
}
return curProgress;
}
@ -377,7 +402,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
protected List<InterfaceAdditionalPopulationInformer> getInformerList() {
Vector<InterfaceAdditionalPopulationInformer> informerList = new Vector<InterfaceAdditionalPopulationInformer>(2);
informerList.add(this.goParams.getProblem());
if (this.goParams.getOptimizer() instanceof InterfaceAdditionalPopulationInformer) informerList.add((InterfaceAdditionalPopulationInformer)this.goParams.getOptimizer());
if (this.goParams.getOptimizer() instanceof InterfaceAdditionalPopulationInformer) {
informerList.add((InterfaceAdditionalPopulationInformer) this.goParams.getOptimizer());
}
return informerList;
}
@ -395,10 +422,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
// System.err.println("Problems writing to output file!");
// }
// }
public String getInfoString() {
//StringBuffer sb = new StringBuffer("processing ");
StringBuffer sb = new StringBuffer(this.goParams.getProblem().getName());
StringBuilder sb = new StringBuilder(this.goParams.getProblem().getName());
sb.append("+");
sb.append(this.goParams.getOptimizer().getName());
// commented out because the number of multi-runs can be changed after start
@ -422,9 +448,13 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
public InterfaceGOParameters getGOParams() {
return goParams;
}
public void setGOParams(InterfaceGOParameters params) {
if (params!=null) goParams= params;
else System.err.println("Setting parameters failed (parameters were null) (Processor.setGOParams)");
if (params != null) {
goParams = params;
} else {
System.err.println("Setting parameters failed (parameters were null) (Processor.setGOParams)");
}
}
/**
@ -452,7 +482,9 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
if (listener != null) {
listener.println("Post processing params: " + BeanInspector.toString(ppp));
// if textwindow was closed, check if it should be reopened for pp
if (m_Statistics instanceof StatisticsWithGUI) ((StatisticsWithGUI)m_Statistics).maybeShowProxyPrinter();
if (m_Statistics instanceof StatisticsWithGUI) {
((StatisticsWithGUI) m_Statistics).maybeShowProxyPrinter();
}
}
Population resultPop = (Population) (goParams.getOptimizer().getAllSolutions().getSolutions().clone());
if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) {
@ -473,6 +505,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
resultPop = PostProcess.postProcess(ppp, resultPop, (AbstractOptimizationProblem) goParams.getProblem(), listener);
resPop = resultPop;
return resultPop;
} else return null;
} else {
return null;
}
}
}

View File

@ -11,12 +11,7 @@ import java.util.HashMap;
* $Date: 2007-11-08 17:24:53 +0100 (Thu, 08 Nov 2007) $
* $Author: mkron $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
/**
*
*/
@ -55,6 +50,7 @@ public class EVAERROR {
static public void WARNING(String Message) {
// if (MAIL_ON_WARNING)
// EVAMail.SendMail("EvA EXIT on ERROR !! ",Message,"ulmerh@informatik.uni-tuebingen.de");
System.err.println("WARNING: "+Message);
System.out.flush();
System.err.flush();
@ -71,7 +67,7 @@ public class EVAERROR {
if (!errMap.containsKey(msg)) {
System.err.println(msg);
errMap.put(msg, new Boolean(true));
errMap.put(msg, true);
}
}