Author: rob.stryker(a)jboss.com
Date: 2011-11-03 02:32:53 -0400 (Thu, 03 Nov 2011)
New Revision: 36155
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7BehaviorDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/v7/management/JBoss7DeploymentState.java
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/internal/management/as7/AS7Manager.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/JBTWebLaunchableClient.java
Log:
JBDS-1762 - as7 delay for browser
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7BehaviorDelegate.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7BehaviorDelegate.java 2011-11-03
02:45:18 UTC (rev 36154)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7BehaviorDelegate.java 2011-11-03
06:32:53 UTC (rev 36155)
@@ -10,12 +10,10 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal.v7;
-import java.text.MessageFormat;
-
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.ExtensionManager;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.Messages;
import org.jboss.ide.eclipse.as.core.extensions.polling.WebPortPoller;
@@ -58,7 +56,7 @@
} catch (Exception e) {
return new Status(
IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- MessageFormat.format(Messages.JBoss7ServerBehavior_could_not_stop,
server.getName()), e);
+ NLS.bind(Messages.JBoss7ServerBehavior_could_not_stop, server.getName()), e);
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/v7/management/JBoss7DeploymentState.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/v7/management/JBoss7DeploymentState.java 2011-11-03
02:45:18 UTC (rev 36154)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/v7/management/JBoss7DeploymentState.java 2011-11-03
06:32:53 UTC (rev 36155)
@@ -18,5 +18,6 @@
*/
public enum JBoss7DeploymentState {
STARTED ,
- STOPPED;
+ STOPPED,
+ NOT_FOUND;
}
\ No newline at end of file
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/internal/management/as7/AS7Manager.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/internal/management/as7/AS7Manager.java 2011-11-03
02:45:18 UTC (rev 36154)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.management.as7/src/org/jboss/ide/eclipse/as/internal/management/as7/AS7Manager.java 2011-11-03
06:32:53 UTC (rev 36155)
@@ -11,12 +11,15 @@
package org.jboss.ide.eclipse.as.internal.management.as7;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.ADDRESS;
+import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.CHILD_TYPE;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.DEPLOYMENT;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.ENABLED;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.NAME;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.OP;
+import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.OP_ADDR;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION;
+import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.READ_RESOURCE_OPERATION;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.RESULT;
import static
org.jboss.ide.eclipse.as.internal.management.as7.ModelDescriptionConstants.SERVER_STATE;
@@ -25,6 +28,10 @@
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CancellationException;
import java.util.concurrent.Future;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -127,11 +134,42 @@
}
}
+ /**
+ * Get the deployment state
+ * This API may cause additional management requests, but it prevents exceptions
+ * from being thrown on the server.
+ *
+ * @param name
+ * @return
+ * @throws JBoss7ManangerException
+ */
+ public JBoss7DeploymentState getDeploymentStateSafe(String name) throws
JBoss7ManangerException {
+ if( !getDeploymentNames().contains(name))
+ return JBoss7DeploymentState.NOT_FOUND;
+
+ return getDeploymentState(name);
+ }
+
+ /**
+ * Get the deployment state.
+ * This may cause exceptions to be thrown on the server side if the deployment has not
yet
+ * been found or started to register.
+ *
+ *
+ * @param name
+ * @return
+ * @throws JBoss7ManangerException
+ */
public JBoss7DeploymentState getDeploymentState(String name) throws
JBoss7ManangerException {
ModelNode request = new ModelNode();
request.get(OP).set(READ_RESOURCE_OPERATION);
request.get(ADDRESS).add(DEPLOYMENT, name);
- ModelNode result = execute(request);
+ ModelNode result = null;
+ try {
+ result = execute(request);
+ } catch( JBoss7ManangerException j7me ) {
+ return JBoss7DeploymentState.NOT_FOUND;
+ }
Boolean enabled = AS7ManagerUtil.getBooleanProperty(ENABLED, result);
if (enabled == null) {
@@ -225,4 +263,39 @@
throw new JBoss7ManangerException(e);
}
}
+
+ public static ModelNode getEmptyOperation(String operationName, ModelNode address) {
+ ModelNode op = new ModelNode();
+ op.get(OP).set(operationName);
+ if (address != null) {
+ op.get(OP_ADDR).set(address);
+ }
+ else {
+ // Just establish the standard structure; caller can fill in address later
+ op.get(OP_ADDR);
+ }
+ return op;
+ }
+
+ private Set<String> getDeploymentNames() throws CancellationException {
+ final ModelNode op = getEmptyOperation(READ_CHILDREN_NAMES_OPERATION, new
ModelNode());
+ op.get(CHILD_TYPE).set(DEPLOYMENT);
+ ModelNode response;
+ try {
+ response = client.execute(op);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ final ModelNode result = response.get(RESULT);
+ final Set<String> deploymentNames = new HashSet<String>();
+ if (result.isDefined()) {
+ final List<ModelNode> deploymentNodes = result.asList();
+ for (ModelNode node : deploymentNodes) {
+ deploymentNames.add(node.asString());
+ }
+ }
+ return deploymentNames;
+ }
+
+
}
\ No newline at end of file
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/JBTWebLaunchableClient.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/JBTWebLaunchableClient.java 2011-11-03
02:45:18 UTC (rev 36154)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/JBTWebLaunchableClient.java 2011-11-03
06:32:53 UTC (rev 36155)
@@ -9,11 +9,13 @@
import javax.management.ObjectName;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunch;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
@@ -26,9 +28,15 @@
import org.jboss.ide.eclipse.as.core.Messages;
import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
+import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
import
org.jboss.ide.eclipse.as.core.server.internal.JBossLaunchAdapter.JBTCustomHttpLaunchable;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.v7.JBoss7Server;
+import org.jboss.ide.eclipse.as.core.server.v7.management.IJBoss7ManagerService;
+import org.jboss.ide.eclipse.as.core.server.v7.management.JBoss7DeploymentState;
+import org.jboss.ide.eclipse.as.core.server.v7.management.JBoss7ManagerUtil;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.core.util.ServerUtil;
import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
public class JBTWebLaunchableClient extends ClientDelegate {
@@ -41,7 +49,7 @@
return (launchable instanceof JBTCustomHttpLaunchable);
}
- protected boolean shouldSuspendScanner(IServer server) {
+ protected boolean isJMXServer(IServer server) {
JBossServer jbs = ServerConverter.getJBossServer(server);
return jbs != null && server.getServerState() == IServer.STATE_STARTED
&& jbs.hasJMXProvider() &&
ExtensionManager.getDefault().getJMXRunner() != null;
@@ -75,10 +83,45 @@
}
protected void wait(final IServer server, final IModule module) {
- if( shouldSuspendScanner(server)) {
+ if( isJMXServer(server)) {
+ waitJMX(server, module);
+ } else if( ServerUtil.isJBoss7(server)) {
+ waitJBoss7(server, module);
+ }
+ }
+
+ protected void waitJBoss7(final IServer server, final IModule module) {
+ try {
+ JBoss7Server jbossServer = ServerConverter.checkedGetJBossServer(server,
JBoss7Server.class);
+ IJBoss7ManagerService service = JBoss7ManagerUtil.getService(server);
+ IPath deployPath = PublishUtil.getDeployPath(new IModule[]{module}, jbossServer);
+ long time = new Date().getTime();
+ long endTime = time + getMaxDelay();
+ while( new Date().getTime() < endTime ) {
+ JBoss7DeploymentState state = service.getDeploymentState(jbossServer.getHost(),
jbossServer.getManagementPort(),
+ deployPath.lastSegment());
+ boolean done = (state == JBoss7DeploymentState.STARTED);
+ if( done ) {
+ return;
+ }
+ try {
+ Thread.sleep(2000);
+ } catch(InterruptedException ie) {}
+ }
+ } catch (Exception e) {
+ IStatus s = new Status(
+ IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind("Could not acquire the management service for this JBoss
installation",
+ server.getName()), e);
+ JBossServerUIPlugin.log(s.getMessage(), e);
+ }
+
+ }
+
+ protected void waitJMX(final IServer server, final IModule module) {
IServerJMXRunnable r = new IServerJMXRunnable() {
public void run(MBeanServerConnection connection) throws Exception {
- waitForDeploymentStarted(server, module, connection, null);
+ jmxWaitForDeploymentStarted(server, module, connection, null);
}
};
try {
@@ -89,17 +132,16 @@
} finally {
ExtensionManager.getDefault().getJMXRunner().endTransaction(server, this);
}
- }
}
- protected void waitForDeploymentStarted(final IServer server, final IModule module,
+ protected void jmxWaitForDeploymentStarted(final IServer server, final IModule module,
final MBeanServerConnection connection, IProgressMonitor monitor) throws Exception {
monitor = monitor == null ? new NullProgressMonitor() : monitor;
monitor.beginTask("Ensuring Deployments are Loaded", 10000); //$NON-NLS-1$
long time = new Date().getTime();
- while( new Date().getTime() < (time + 20000)) {
+ long endTime = time + getMaxDelay();
+ while( new Date().getTime() < endTime ) {
boolean done = checkDeploymentStarted(server, module, connection, monitor);
- System.out.println(done);
if( done ) {
monitor.done();
return;
@@ -109,6 +151,10 @@
} catch(InterruptedException ie) {}
}
}
+
+ protected long getMaxDelay() {
+ return 20000;
+ }
protected boolean checkDeploymentStarted(final IServer server, final IModule module,
final MBeanServerConnection connection, IProgressMonitor monitor) throws Exception {