Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2013-05-15 04:37:17 -0400
committerMarkus Tiede2013-05-15 04:37:17 -0400
commit5dfc89c8b75acfabc520721bfa06e37e105e9011 (patch)
treef47e5ba40f6bf23a1e984f0ebd197900e523c3ba /org.eclipse.jubula.autagent
parenta920dbf230c01c8d67dc81942a419be022245ae2 (diff)
downloadorg.eclipse.jubula.core-5dfc89c8b75acfabc520721bfa06e37e105e9011.tar.gz
org.eclipse.jubula.core-5dfc89c8b75acfabc520721bfa06e37e105e9011.tar.xz
org.eclipse.jubula.core-5dfc89c8b75acfabc520721bfa06e37e105e9011.zip
Sprint task - allow restart AUT after shutdown - part 2: general internal infrastructure and fix for 131.
Diffstat (limited to 'org.eclipse.jubula.autagent')
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java42
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/IRestartAutHandler.java10
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutAutRun.java4
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutConfiguration.java23
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/RestartAutCommand.java7
-rw-r--r--org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StopAUTServerCommand.java2
6 files changed, 56 insertions, 32 deletions
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java
index 1a40c48ef..7de2f37f0 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/AutAgent.java
@@ -41,6 +41,7 @@ import org.eclipse.jubula.tools.exception.CommunicationException;
import org.eclipse.jubula.tools.exception.JBVersionException;
import org.eclipse.jubula.tools.registration.AutIdentifier;
import org.eclipse.jubula.tools.utils.StringParsing;
+import org.eclipse.jubula.tools.utils.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -270,7 +271,7 @@ public class AutAgent {
if (!registeredAutSetWasModified && m_killDuplicateAuts) {
try {
- m_autCommunicator.send(new PrepareForShutdownMessage());
+ m_autCommunicator.send(new PrepareForShutdownMessage(true));
} catch (CommunicationException e) {
// As a result of not being able to send the message,
// the AUT will end with a different exit code. This
@@ -440,7 +441,9 @@ public class AutAgent {
/**
* Removes the given AUT from the collection of registered AUTs.
- * @param autId The ID of the AUT to deregister.
+ *
+ * @param autId
+ * The ID of the AUT to deregister.
*/
private void removeAut(AutIdentifier autId) {
boolean wasSetChanged = false;
@@ -450,7 +453,8 @@ public class AutAgent {
Communicator autCommunicator = m_auts.remove(autId);
if (autCommunicator != null) {
try {
- autCommunicator.send(new PrepareForShutdownMessage());
+ autCommunicator.send(
+ new PrepareForShutdownMessage(true));
} catch (CommunicationException e) {
// As a result of not being able to send the message,
// the AUT will end with a different exit code. This
@@ -569,29 +573,45 @@ public class AutAgent {
/**
* Stops the given AUT.
*
- * @param autId The ID of the Running AUT to stop.
+ * @param autId
+ * The ID of the Running AUT to stop.
+ * @param force
+ * indicates whether the AUT should be forced to quit or whether
+ * the AUT will terminate by itself
*/
- public void stopAut(AutIdentifier autId) {
+ public void stopAut(AutIdentifier autId, boolean force) {
synchronized (m_auts) {
Communicator autCommunicator = m_auts.get(autId);
if (autCommunicator != null) {
- removeAut(autId);
- autCommunicator.close();
+ if (force) {
+ removeAut(autId);
+ }
}
}
+ if (!force) {
+ while (m_auts.containsKey(autId)) {
+ TimeUtil.delay(250);
+ }
+ // The AUT has just unregistered itself - which must not be exactly
+ // the same as terminated - therefore we wait for another moment of time
+ TimeUtil.delay(2000);
+ }
}
/**
* Restarts the AUT with the given ID.
*
- * @param autId The ID of the Running AUT to restart.
+ * @param autId
+ * The ID of the Running AUT to restart.
+ * @param force
+ * indicates whether the AUT should be forced to quit or whether
+ * the AUT will terminate by itself
*/
- public void restartAut(AutIdentifier autId) {
+ public void restartAut(AutIdentifier autId, boolean force) {
// cache the start method
final IRestartAutHandler message = m_autIdToRestartHandler.get(autId);
- message.restartAut(this);
-
+ message.restartAut(this, force);
}
/**
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/IRestartAutHandler.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/IRestartAutHandler.java
index 6b80d9c68..58fe05ce3 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/IRestartAutHandler.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/IRestartAutHandler.java
@@ -21,9 +21,13 @@ public interface IRestartAutHandler {
/**
*
- * @param agent The AUT Agent with which the AUT to be restarted is
- * registered. This may be used, for example, to stop the AUT.
+ * @param agent
+ * The AUT Agent with which the AUT to be restarted is
+ * registered. This may be used, for example, to stop the AUT.
+ * @param force
+ * indicates whether the AUT should be forced to quit or whether
+ * the AUT will terminate by itself
*/
- public void restartAut(AutAgent agent);
+ public void restartAut(AutAgent agent, boolean force);
}
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutAutRun.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutAutRun.java
index a2cbc1e55..335bc0dae 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutAutRun.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutAutRun.java
@@ -60,7 +60,7 @@ public class RestartAutAutRun implements IRestartAutHandler {
/**
* {@inheritDoc}
*/
- public void restartAut(AutAgent agent) {
+ public void restartAut(AutAgent agent, boolean force) {
try {
PrintWriter writer = new PrintWriter(
m_autrunSocket.getOutputStream(), true);
@@ -68,7 +68,7 @@ public class RestartAutAutRun implements IRestartAutHandler {
writer.println(RestartAutProtocol.REQ_PREPARE_FOR_RESTART);
m_socketReader.readLine();
- agent.stopAut(m_autId);
+ agent.stopAut(m_autId, force);
writer.println(RestartAutProtocol.REQ_RESTART);
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutConfiguration.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutConfiguration.java
index b059613a8..2924e6617 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutConfiguration.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/agent/RestartAutConfiguration.java
@@ -14,10 +14,9 @@ import org.eclipse.jubula.autagent.commands.StartAUTServerCommand;
import org.eclipse.jubula.communication.message.StartAUTServerMessage;
import org.eclipse.jubula.tools.registration.AutIdentifier;
-
/**
* Restarts an AUT that was started via an AUT Configuration.
- *
+ *
* @author BREDEX GmbH
* @created Mar 26, 2010
*/
@@ -25,31 +24,29 @@ public class RestartAutConfiguration implements IRestartAutHandler {
/** the message used to start the AUT */
private StartAUTServerMessage m_startAutMessage;
-
+
/** the ID of the the started AUT */
private AutIdentifier m_autId;
/**
* Constructor
*
- * @param autId The ID of the started AUT.
- * @param startAutMessage The message used to start the AUT.
+ * @param autId
+ * The ID of the started AUT.
+ * @param startAutMessage
+ * The message used to start the AUT.
*/
- public RestartAutConfiguration(AutIdentifier autId,
+ public RestartAutConfiguration(AutIdentifier autId,
StartAUTServerMessage startAutMessage) {
m_startAutMessage = startAutMessage;
m_autId = autId;
}
- /**
- * {@inheritDoc}
- */
- public void restartAut(AutAgent agent) {
-
- agent.stopAut(m_autId);
+ /** {@inheritDoc} */
+ public void restartAut(AutAgent agent, boolean force) {
+ agent.stopAut(m_autId, force);
StartAUTServerCommand startCommand = new StartAUTServerCommand();
startCommand.setMessage(m_startAutMessage);
startCommand.execute();
}
-
}
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/RestartAutCommand.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/RestartAutCommand.java
index 8f7e4ba9d..3176353eb 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/RestartAutCommand.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/RestartAutCommand.java
@@ -18,6 +18,7 @@ import org.eclipse.jubula.communication.ICommand;
import org.eclipse.jubula.communication.message.Message;
import org.eclipse.jubula.communication.message.RestartAutMessage;
import org.eclipse.jubula.tools.constants.AutConfigConstants;
+import org.eclipse.jubula.tools.registration.AutIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@@ -38,13 +39,15 @@ public class RestartAutCommand implements ICommand {
* {@inheritDoc}
*/
public Message execute() {
+ AutIdentifier autId = m_message.getAutId();
String monitoringId = m_cm.getConfigValue(
- m_message.getAutId().getExecutableName(),
+ autId.getExecutableName(),
AutConfigConstants.MONITORING_AGENT_ID);
if (!StringUtils.isEmpty(monitoringId)) {
invokeMonitoringRestartMethod();
}
- AutStarter.getInstance().getAgent().restartAut(m_message.getAutId());
+ AutStarter.getInstance().getAgent()
+ .restartAut(autId, m_message.isForceAUTTermination());
return null;
}
/**
diff --git a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StopAUTServerCommand.java b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StopAUTServerCommand.java
index 54de4bbd6..10007c1fe 100644
--- a/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StopAUTServerCommand.java
+++ b/org.eclipse.jubula.autagent/src/org/eclipse/jubula/autagent/commands/StopAUTServerCommand.java
@@ -79,7 +79,7 @@ public class StopAUTServerCommand implements ICommand {
final AutAgent agent = AutStarter.getInstance().getAgent();
if (agent != null) {
- agent.stopAut(m_message.getAutId());
+ agent.stopAut(m_message.getAutId(), true);
return new StopAUTServerStateMessage();
}

Back to the top