Skip to content

Commit

Permalink
Improves performance of testing the jboss server connection
Browse files Browse the repository at this point in the history
* Testing the connection of both teiid and its parent jboss server is a
  very frequent occurrence and as such needs to do as little as possible.
  The current implementation generates at least 2 thread runnables to
  return the jboss server name, which is never used. It is also slow,
  taking on average 1.5 - 3 seconds, with the possibility of using much
  needed memory / threads and other resources. Given the frequency of the
  operation, this is incredibly wasteful.

* Scales back the connection test to determine the availability of the
  jboss management port on the jboss host. Each connection has a timeout of
  a second so a failure is returned quickly. Should this become as issue
  in the future then this timeout could be included as a preference. The
  socket is always closed and nulled to ensure it is garbage collected.
  • Loading branch information
Paul Richardson committed Jul 29, 2013
1 parent cc36fed commit ef7c747
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Expand Up @@ -45,7 +45,6 @@ public abstract class JBoss7ServerUtil extends JBossServerUtil {

private static final String PORT = ModelDescriptionConstants.PORT;


/**
* @param server
* @param jboss7Server
Expand All @@ -72,18 +71,10 @@ public static boolean isJBossServerConnected(IServer parentServer, JBoss7Server
if (! serverStarted(jboss7Server.getServer()))
return false;

// Request that finds the name of the server
ModelNode request = new ModelNode();
request.get(OP).set(READ_ATTRIBUTE_OPERATION);
request.get(NAME).set(NAME);

try {
executeRequest(parentServer, jboss7Server, request);
return true;
} catch (Exception ex) {
// No need to log the exception
return false;
}
String host = jboss7Server.getHost();
int port = jboss7Server.getManagementPort();

return isHostConnected(host, port);
}

/**
Expand Down
Expand Up @@ -8,9 +8,12 @@
package org.teiid.designer.runtime.adapter;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
import org.teiid.designer.runtime.DqpPlugin;

/**
*
Expand All @@ -30,18 +33,37 @@ public static boolean isJBossServerConnected(IServer parentServer, JBossServer j
if (!serverStarted(parentServer))
return false;

return isHostConnected(jbossServer.getHost(), jbossServer.getJBossWebPort());
}

/**
* @param jbossServer
* @return
*/
protected static boolean isHostConnected(String host, int port) {
Socket socket = null;
InetSocketAddress endPoint = new InetSocketAddress(host, port);

if (endPoint.isUnresolved()) {
DqpPlugin.Util.log(IStatus.WARNING, DqpPlugin.Util.getString("jbossServerConnectionFailureMessage", endPoint)); //$NON-NLS-1$
return false;
}

try {
socket = new Socket(jbossServer.getHost(), jbossServer.getJBossWebPort());
socket = new Socket();
socket.connect(endPoint, 1024);

return true;
} catch (Exception ex) {
// Connection failed - no need to log exception
return false;

} finally {
if (socket != null) {
if (socket != null && socket.isConnected()) {
try {
socket.close();
} catch (IOException e) {
socket = null;
} catch (IOException ex) {
DqpPlugin.Util.log(IStatus.WARNING, ex, DqpPlugin.Util.getString("jbossServerConnectionFailureMessage", endPoint)); //$NON-NLS-1$
}
}
}
Expand Down

0 comments on commit ef7c747

Please sign in to comment.