Commit 28e69f5f authored by Gergo Ujhelyi's avatar Gergo Ujhelyi
Browse files

fixed waiting bug in batchmode


Signed-off-by: Gergo Ujhelyi's avatarGergo Ujhelyi <ujhelyi.gergo@ericsson.com>
parent 0627dfda
...@@ -14,6 +14,7 @@ import java.io.InputStreamReader; ...@@ -14,6 +14,7 @@ import java.io.InputStreamReader;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.titan.runtime.core.TTCN_Runtime; import org.eclipse.titan.runtime.core.TTCN_Runtime;
...@@ -59,7 +60,9 @@ public class Cli extends UserInterface { ...@@ -59,7 +60,9 @@ public class Cli extends UserInterface {
private final ConfigData mycfg = new ConfigData(); private final ConfigData mycfg = new ConfigData();
private int executeListIndex; private int executeListIndex;
private final ReentrantLock mutex; private final ReentrantLock mutex;
private final Condition wakeup_condition;
private MainController mainController; private MainController mainController;
private File config_file;
public Cli() { public Cli() {
loggingEnabled = true; loggingEnabled = true;
...@@ -67,6 +70,8 @@ public class Cli extends UserInterface { ...@@ -67,6 +70,8 @@ public class Cli extends UserInterface {
waitState = waitStateEnum.WAIT_NOTHING; waitState = waitStateEnum.WAIT_NOTHING;
executeListIndex = 0; executeListIndex = 0;
mutex = new ReentrantLock(); mutex = new ReentrantLock();
wakeup_condition = mutex.newCondition();
config_file = null;
} }
public void setMainController(final MainController mainController) { public void setMainController(final MainController mainController) {
...@@ -88,7 +93,7 @@ public class Cli extends UserInterface { ...@@ -88,7 +93,7 @@ public class Cli extends UserInterface {
printWelcome(); printWelcome();
if (args.length == 1) { if (args.length == 1) {
final File config_file = new File(args[0]); config_file = new File(args[0]);
System.out.printf("Using configuration file: %s\n", config_file.getName()); System.out.printf("Using configuration file: %s\n", config_file.getName());
final CfgAnalyzer cfgAnalyzer = new CfgAnalyzer(); final CfgAnalyzer cfgAnalyzer = new CfgAnalyzer();
...@@ -98,7 +103,8 @@ public class Cli extends UserInterface { ...@@ -98,7 +103,8 @@ public class Cli extends UserInterface {
//cleanup? //cleanup?
return 1; return 1;
} else { } else {
mycfg.set_log_file(args[0]); //TODO: its the config file, not the log file
//mycfg.set_log_file(args[0]);
final MCSectionHandler mcSectionHandler = cfgAnalyzer.getMcSectionHandler(); final MCSectionHandler mcSectionHandler = cfgAnalyzer.getMcSectionHandler();
final ExecuteSectionHandler executeSectionHandler = cfgAnalyzer.getExecuteSectionHandler(); final ExecuteSectionHandler executeSectionHandler = cfgAnalyzer.getExecuteSectionHandler();
...@@ -153,6 +159,7 @@ public class Cli extends UserInterface { ...@@ -153,6 +159,7 @@ public class Cli extends UserInterface {
try { try {
if (waitState != waitStateEnum.WAIT_NOTHING && conditionHolds(waitState)) { if (waitState != waitStateEnum.WAIT_NOTHING && conditionHolds(waitState)) {
waitState = waitStateEnum.WAIT_NOTHING; waitState = waitStateEnum.WAIT_NOTHING;
signal();
} }
} finally { } finally {
mutex.unlock(); mutex.unlock();
...@@ -168,7 +175,7 @@ public class Cli extends UserInterface { ...@@ -168,7 +175,7 @@ public class Cli extends UserInterface {
@Override @Override
public void notify(final Timeval timestamp, final String source, final int severity, final String message) { public void notify(final Timeval timestamp, final String source, final int severity, final String message) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.printf("%s: %s\n", source, message);
} }
@Override @Override
...@@ -327,9 +334,10 @@ public class Cli extends UserInterface { ...@@ -327,9 +334,10 @@ public class Cli extends UserInterface {
waitMCState(waitStateEnum.WAIT_HC_CONNECTED); waitMCState(waitStateEnum.WAIT_HC_CONNECTED);
// download config file // download config file
//FIXME incorrect we need to send the processed contents not the name of the file. //FIXME incorrect we need to send the processed contents not the name of the file.
mainController.configure(mycfg.getLog_file_name()); mainController.configure(ConfigData.getConfigFileContent(config_file));
waitMCState(waitStateEnum.WAIT_ACTIVE); waitMCState(waitStateEnum.WAIT_ACTIVE);
if (mainController.get_state() != mcStateEnum.MC_ACTIVE) { if (mainController.get_state() != mcStateEnum.MC_ACTIVE) {
System.out.println(mainController.get_state());
System.out.println("Error during initialization. Cannot continue in batch mode."); System.out.println("Error during initialization. Cannot continue in batch mode.");
error_flag = true; error_flag = true;
} }
...@@ -431,16 +439,42 @@ public class Cli extends UserInterface { ...@@ -431,16 +439,42 @@ public class Cli extends UserInterface {
} }
private void waitMCState(final waitStateEnum newWaitState) { private void waitMCState(final waitStateEnum newWaitState) {
mutex.lock();
if (newWaitState != waitStateEnum.WAIT_NOTHING) { if (newWaitState != waitStateEnum.WAIT_NOTHING) {
if (conditionHolds(newWaitState) == true) { if (conditionHolds(newWaitState)) {
waitState = waitStateEnum.WAIT_NOTHING; waitState = waitStateEnum.WAIT_NOTHING;
} else { } else {
waitState = newWaitState; waitState = newWaitState;
await();
} }
} else { } else {
System.err.println("Cli.waitMCState: invalid argument"); System.err.println("Cli.waitMCState: invalid argument");
mutex.unlock();
return; return;
} }
mutex.unlock();
}
private void lock() {
mutex.lock();
}
private void unlock() {
mutex.unlock();
}
private void signal() {
wakeup_condition.signal();
}
private void await() {
try {
wakeup_condition.await();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.err.println(e.getMessage());
e.printStackTrace();
}
} }
/** /**
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.titan.runtime.core.mctr; package org.eclipse.titan.runtime.core.mctr;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.List; import java.util.List;
...@@ -125,4 +129,24 @@ public class ConfigData { ...@@ -125,4 +129,24 @@ public class ConfigData {
public void setKill_timer(final Double kill_timer) { public void setKill_timer(final Double kill_timer) {
this.kill_timer = kill_timer; this.kill_timer = kill_timer;
} }
//Package-private
static String getConfigFileContent(File config_file) {
StringBuilder contentBuilder = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(config_file)))
{
String currentLine;
while ((currentLine = br.readLine()) != null)
{
contentBuilder.append(currentLine).append("\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
return contentBuilder.toString();
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment