Skip to content

Commit

Permalink
Only check the availability of the Server using the Management API af…
Browse files Browse the repository at this point in the history
…ter the Socket is verified open. This avoids the ~5 sec delay on Managed Container boot waiting for the Management API timeout to happen
  • Loading branch information
aslakknutsen authored and n1hility committed Sep 22, 2011
1 parent 3dbf698 commit c4072b4
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ protected void startInternal() throws LifecycleException {
ManagedContainerConfiguration config = getContainerConfiguration();

if (!config.isAllowConnectingToRunningServer()) {
verifyNoRunningServer();
if(isServerRunning()) {
throw new LifecycleException(
"The server is already running! " +
"Managed containers does not support connecting to running server instances due to the " +
"possible harmful effect of connecting to the wrong server. Please stop server before running or " +
"change to another type of container.\n" +
"To disable this check and allow Arquillian to connect to a running server, " +
"set allowConnectingToRunningServer to true in the container configuration"
);
}
}

try {
Expand Down Expand Up @@ -132,8 +141,11 @@ public void run() {
long startupTimeout = getContainerConfiguration().getStartupTimeoutInSeconds();
long timeout = startupTimeout * 1000;
boolean serverAvailable = false;
boolean serverIsRunning = false;
while (timeout > 0 && serverAvailable == false) {
serverAvailable = getManagementClient().isServerInRunningState();
// check to see the server is running before we check if it's available
serverIsRunning = serverIsRunning ? true:isServerRunning();
serverAvailable = serverIsRunning ? getManagementClient().isServerInRunningState():false;
if (!serverAvailable) {
Thread.sleep(100);
timeout -= 100;
Expand Down Expand Up @@ -166,14 +178,14 @@ protected void stopInternal() throws LifecycleException {
}
}

private void verifyNoRunningServer() throws LifecycleException {
private boolean isServerRunning() throws LifecycleException {
Socket socket = null;
try {
socket = new Socket(
getContainerConfiguration().getManagementAddress(),
getContainerConfiguration().getManagementPort());
} catch (Exception ignored) { // nothing is running on defined ports
return;
return false;
} finally {
if (socket != null) {
try {
Expand All @@ -183,14 +195,7 @@ private void verifyNoRunningServer() throws LifecycleException {
}
}
}
throw new LifecycleException(
"The server is already running! " +
"Managed containers does not support connecting to running server instances due to the " +
"possible harmful effect of connecting to the wrong server. Please stop server before running or " +
"change to another type of container.\n" +
"To disable this check and allow Arquillian to connect to a running server, " +
"set allowConnectingToRunningServer to true in the container configuration"
);
return true;
}

private int destroyProcess() {
Expand Down Expand Up @@ -227,6 +232,5 @@ public void run() {
} catch (IOException e) {
}
}

}
}

0 comments on commit c4072b4

Please sign in to comment.