Author: rob.stryker(a)jboss.com
Date: 2007-07-20 17:09:58 -0400 (Fri, 20 Jul 2007)
New Revision: 2575
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerStatePollerType.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/ProcessTerminatedPoller.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/IServerStatePoller.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IServerPollingAttributes.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/pollers.exsd
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/preferencepages/JBossServersPreferencePage.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java
Log:
Additions of pollers and change to the preference page for servers to show the possible
pollers.
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -23,12 +23,15 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.jboss.ide.eclipse.as.core.runtime.server.IServerPollerTimeoutListener;
+import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.runtime.server.ServerStatePollerType;
/**
*
@@ -71,5 +74,46 @@
}
}
}
+
+ private HashMap pollers;
+ public void loadPollers() {
+ pollers = new HashMap();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf =
registry.getConfigurationElementsFor(JBossServerCorePlugin.PLUGIN_ID,
"pollers");
+ for( int i = 0; i < cf.length; i++ ) {
+ pollers.put(cf[i].getAttribute("id"), new ServerStatePollerType(cf[i]));
+ }
+ }
+ public ServerStatePollerType getPollerType(String id) {
+ if( pollers == null )
+ loadPollers();
+ return (ServerStatePollerType)pollers.get(id);
+ }
+ public ServerStatePollerType[] getStartupPollers() {
+ if( pollers == null )
+ loadPollers();
+ ArrayList list = new ArrayList();
+ Iterator i = pollers.values().iterator();
+ ServerStatePollerType type;
+ while(i.hasNext()) {
+ type = (ServerStatePollerType)i.next();
+ if( type.supportsStartup())
+ list.add(type);
+ }
+ return (ServerStatePollerType[]) list.toArray(new ServerStatePollerType[list.size()]);
+ }
+ public ServerStatePollerType[] getShutdownPollers() {
+ if( pollers == null )
+ loadPollers();
+ ArrayList list = new ArrayList();
+ Iterator i = pollers.values().iterator();
+ ServerStatePollerType type;
+ while(i.hasNext()) {
+ type = (ServerStatePollerType)i.next();
+ if( type.supportsShutdown() )
+ list.add(type);
+ }
+ return (ServerStatePollerType[]) list.toArray(new ServerStatePollerType[list.size()]);
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/IServerStatePoller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/IServerStatePoller.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/IServerStatePoller.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -39,9 +39,6 @@
public void cancel(int type); // cancel the polling
public void cleanup(); // clean up any resources / processes. Will ALWAYS be called
- public boolean supportsStartup();
- public boolean supportsShutdown();
-
public class PollingException extends Exception {
public PollingException(String message) {super(message);}
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerStatePollerType.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerStatePollerType.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/ServerStatePollerType.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -0,0 +1,29 @@
+package org.jboss.ide.eclipse.as.core.runtime.server;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+
+public class ServerStatePollerType {
+ private IConfigurationElement el;
+ public ServerStatePollerType(IConfigurationElement el) {
+ this.el = el;
+ }
+ public boolean supportsStartup() {
+ return Boolean.parseBoolean(el.getAttribute("supportsStartup"));
+ }
+ public boolean supportsShutdown() {
+ return Boolean.parseBoolean(el.getAttribute("supportsShutdown"));
+ }
+ public String getName() {
+ return el.getAttribute("name");
+ }
+ public String getId() {
+ return el.getAttribute("id");
+ }
+ public IServerStatePoller createPoller() {
+ try {
+ return (IServerStatePoller)el.createExecutableExtension("class");
+ } catch( Exception e ) {
+ }
+ return null;
+ }
+}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java
(from rev 2565,
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/JMXPoller.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -0,0 +1,211 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+* This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as.core.runtime.server.polling;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.Principal;
+import java.util.Date;
+import java.util.Properties;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
+import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.server.JBossServerLaunchConfiguration;
+import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
+
+public class JMXPoller implements IServerStatePoller {
+
+ public static final String STATUS =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.status";
+
+ public static final String TYPE_TERMINATED =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.TYPE_TERMINATED";
+ public static final String TYPE_RESULT =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.TYPE_RESULT";
+
+ public static final int STATE_STARTED = 1;
+ public static final int STATE_STOPPED = 0;
+ public static final int STATE_TRANSITION = -1;
+
+ private boolean expectedState;
+ private int started;
+ private boolean canceled;
+ private boolean done;
+ private IServer server;
+ private PollingException pollingException = null;
+
+ private EventLogTreeItem event;
+ public void beginPolling(IServer server, boolean expectedState, PollThread pt) {
+ this.expectedState = expectedState;
+ this.canceled = false;
+ this.done = false;
+ this.server = server;
+ event = pt.getActiveEvent();
+ launchJMXPoller();
+ }
+
+ private class PollerRunnable implements Runnable {
+ public void run() {
+ ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader twiddleLoader = getClassLoader();
+ if( twiddleLoader != null ) {
+ int port = ServerConverter.getJBossServer(server).getJNDIPort();
+
+ Thread.currentThread().setContextClassLoader(twiddleLoader);
+ Properties props = new Properties();
+ props.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
+
props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
+ props.put("java.naming.provider.url","jnp://" +
server.getHost() + ":" + port);
+
+ setCredentials();
+
+ while( !done && !canceled ) {
+ InitialContext ic;
+ try {
+ ic = new InitialContext(props);
+ Object obj = ic.lookup("jmx/invoker/RMIAdaptor");
+ ic.close();
+ if( obj instanceof MBeanServerConnection ) {
+ MBeanServerConnection connection = (MBeanServerConnection)obj;
+ Object attInfo = connection.getAttribute(new
ObjectName("jboss.system:type=Server"), "Started");
+ boolean b = ((Boolean)attInfo).booleanValue();
+ started = b ? STATE_STARTED : STATE_TRANSITION;
+ if( b && expectedState )
+ done = true;
+ }
+ } catch( SecurityException se ) {
+ pollingException = new PollingSecurityException("Security Exception: " +
se.getMessage());
+ done = true;
+ } catch( Exception e ) {
+ started = STATE_STOPPED;
+ if( !expectedState )
+ done = true;
+ }
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } // end while
+ }
+
+ Thread.currentThread().setContextClassLoader(currentLoader);
+ }
+
+ protected void setCredentials() {
+ try {
+ ILaunchConfiguration lc = server.getLaunchConfiguration(true, new
NullProgressMonitor());
+ String twiddleArgs =
lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS
+ + JBossServerLaunchConfiguration.PRGM_ARGS_TWIDDLE_SUFFIX, (String)null);
+ String user = ArgsUtil.getValue(twiddleArgs, "-u", "--user");
+ String password = ArgsUtil.getValue(twiddleArgs, "-p",
"--password");
+
+ // get our methods
+ Class simplePrincipal =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.SimplePrincipal");
+ Class securityAssoc =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.SecurityAssociation");
+ securityAssoc.getMethods(); // force-init the methods since the class hasn't been
initialized yet.
+
+ Constructor newSimplePrincipal = simplePrincipal.getConstructor(new Class[] {
String.class });
+ Object newPrincipalInstance = newSimplePrincipal.newInstance(new Object[] {user});
+
+
+ // set the principal
+ Method setPrincipalMethod = securityAssoc.getMethod("setPrincipal", new
Class[] {Principal.class});
+ setPrincipalMethod.invoke(null, new Object[] {newPrincipalInstance});
+
+ // set the credential
+ Method setCredentialMethod = securityAssoc.getMethod("setCredential", new
Class[] {Object.class});
+ setCredentialMethod.invoke(null, new Object[] {password});
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ protected ClassLoader getClassLoader() {
+ try {
+ IRuntime rt = server.getRuntime();
+ IPath loc = rt.getLocation();
+ URL url =
loc.append("client").append("jbossall-client.jar").toFile().toURI().toURL();
+ URL url2 =
loc.append("bin").append("twiddle.jar").toFile().toURI().toURL();
+ URLClassLoader loader = new URLClassLoader(new URL[] {url, url2},
Thread.currentThread().getContextClassLoader());
+ return loader;
+ } catch( MalformedURLException murle) {
+ murle.printStackTrace();
+ }
+ return null;
+ }
+ }
+ private void launchJMXPoller() {
+ PollerRunnable run = new PollerRunnable();
+ Thread t = new Thread(run, "JMX Poller");
+ t.start();
+ }
+ public void cancel(int type) {
+ canceled = true;
+ }
+
+ public void cleanup() {
+ }
+
+ public class PollingSecurityException extends PollingException {
+ public PollingSecurityException(String msg) {super(msg);}
+ }
+
+ public boolean getState() throws PollingException {
+ if( pollingException != null ) throw pollingException;
+ if( started == 0 ) return SERVER_DOWN;
+ if( started == 1 ) return SERVER_UP;
+
+ if( !done && !canceled )
+ return !expectedState; // Not there yet.
+
+ return expectedState; // done or canceled, doesnt matter
+ }
+
+ public boolean isComplete() throws PollingException {
+ if( pollingException != null )
+ throw pollingException;
+ return done;
+ }
+
+ public class JMXPollerEvent extends EventLogTreeItem {
+ public JMXPollerEvent(SimpleTreeItem parent, String type, int status, boolean
expectedState) {
+ super(parent, PollThread.SERVER_STATE_MAJOR_TYPE, type);
+ setProperty(PollThread.EXPECTED_STATE, new Boolean(expectedState));
+ setProperty(STATUS, new Integer(status));
+ setProperty(DATE, new Long(new Date().getTime()));
+ }
+ }
+}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/PollThread.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -24,7 +24,9 @@
import java.util.Date;
import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerAttributes;
import org.eclipse.wst.server.core.internal.ServerType;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
import org.jboss.ide.eclipse.as.core.model.EventLogModel;
import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogRoot;
import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
@@ -34,6 +36,7 @@
import org.jboss.ide.eclipse.as.core.server.JBossServerBehavior;
import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.core.server.attributes.IServerPollingAttributes;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
/**
@@ -63,15 +66,24 @@
private PollThreadEvent activeEvent;
- public PollThread(String name, IServerStatePoller poller, boolean expectedState,
JBossServerBehavior behavior) {
+ public PollThread(String name, boolean expectedState, JBossServerBehavior behavior) {
super(name);
this.expectedState = expectedState;
- this.poller = poller;
this.abort = false;
this.behavior = behavior;
eventRoot = EventLogModel.getModel(behavior.getServer()).getRoot();
+
+ poller = discoverPoller(behavior, expectedState);
}
+ protected IServerStatePoller discoverPoller(JBossServerBehavior behavior, boolean
expectedState) {
+ JBossServer s = ServerConverter.getJBossServer(behavior.getServer());
+ ServerAttributeHelper helper = s.getAttributeHelper();
+ String key = expectedState == IServerStatePoller.SERVER_UP ?
IServerPollingAttributes.STARTUP_POLLER_KEY :
IServerPollingAttributes.SHUTDOWN_POLLER_KEY;
+ String pollerId = helper.getAttribute(key, IServerPollingAttributes.DEFAULT_POLLER);
+ return ExtensionManager.getDefault().getPollerType(pollerId).createPoller();
+ }
+
public void cancel() {
abort = true;
}
@@ -155,8 +167,9 @@
} else {
if( currentState == IServerStatePoller.SERVER_UP )
behavior.setServerStarted();
- else
- behavior.setServerStopped();
+ else {
+ behavior.stop(true);
+ }
if( finalAlert ) alertEventLogSuccess(currentState);
}
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/ProcessTerminatedPoller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/ProcessTerminatedPoller.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/ProcessTerminatedPoller.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -0,0 +1,39 @@
+package org.jboss.ide.eclipse.as.core.runtime.server.polling;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.server.JBossServerBehavior;
+
+/**
+ * Essentially does nothing because the process already has a listener
+ * on it that sets the server state to stopped once the process dies.
+ *
+ * It's here to make the shutdown include no polling though, thus
+ * more efficient.
+ * @author rob
+ *
+ */
+public class ProcessTerminatedPoller implements IServerStatePoller {
+
+ private JBossServerBehavior server;
+ public void beginPolling(IServer server, boolean expectedState,
+ PollThread pt) {
+ this.server = (JBossServerBehavior)server.loadAdapter(JBossServerBehavior.class, new
NullProgressMonitor());
+ }
+
+ public void cancel(int type) {
+ }
+
+ public void cleanup() {
+ }
+
+ public boolean getState() throws PollingException {
+ return !isComplete();
+ }
+
+ public boolean isComplete() throws PollingException {
+ return server.getProcess() == null || server.getProcess().isTerminated();
+ }
+
+}
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -1,245 +0,0 @@
-/**
- * JBoss, a Division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
-* This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as.core.runtime.server.polling;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.Principal;
-import java.util.Date;
-import java.util.Properties;
-
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.model.EventLogModel;
-import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
-import org.jboss.ide.eclipse.as.core.model.legacy.DescriptorModel;
-import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
-import org.jboss.ide.eclipse.as.core.server.JBossServerLaunchConfiguration;
-import org.jboss.ide.eclipse.as.core.server.TwiddleLauncher;
-import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
-
-public class TwiddlePoller implements IServerStatePoller {
-
- public static final String STATUS =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.status";
-
- public static final String TYPE_TERMINATED =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.TYPE_TERMINATED";
- public static final String TYPE_RESULT =
"org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller.TYPE_RESULT";
-
- public static final int STATE_STARTED = 1;
- public static final int STATE_STOPPED = 0;
- public static final int STATE_TRANSITION = -1;
-
- private boolean expectedState;
- private int started;
- private boolean canceled;
- private boolean done;
- private IServer server;
- private PollingException pollingException = null;
-
- private EventLogTreeItem event;
- public void beginPolling(IServer server, boolean expectedState, PollThread pt) {
- this.expectedState = expectedState;
- this.canceled = false;
- this.done = false;
- this.server = server;
- event = pt.getActiveEvent();
- launchTwiddlePoller();
- }
-
- private class PollerRunnable implements Runnable {
- private TwiddleLauncher launcher;
- public void run() {
- ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
- ClassLoader twiddleLoader = getClassLoader();
- if( twiddleLoader != null ) {
- int port = ServerConverter.getJBossServer(server).getJNDIPort();
-
- Thread.currentThread().setContextClassLoader(twiddleLoader);
- Properties props = new Properties();
- props.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
-
props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
- props.put("java.naming.provider.url","jnp://" +
server.getHost() + ":" + port);
-
- setCredentials();
-
- while( !done && !canceled ) {
- InitialContext ic;
- try {
- ic = new InitialContext(props);
- Object obj = ic.lookup("jmx/invoker/RMIAdaptor");
- ic.close();
- if( obj instanceof MBeanServerConnection ) {
- MBeanServerConnection connection = (MBeanServerConnection)obj;
- Object attInfo = connection.getAttribute(new
ObjectName("jboss.system:type=Server"), "Started");
- boolean b = ((Boolean)attInfo).booleanValue();
- started = b ? STATE_STARTED : STATE_TRANSITION;
- if( b && expectedState )
- done = true;
- }
- } catch( SecurityException se ) {
- pollingException = new PollingSecurityException("Security Exception: " +
se.getMessage());
- done = true;
- } catch( Exception e ) {
- started = STATE_STOPPED;
- if( !expectedState )
- done = true;
- }
-
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } // end while
- }
-
- Thread.currentThread().setContextClassLoader(currentLoader);
-
- }
-
- protected void setCredentials() {
- try {
- ILaunchConfiguration lc = server.getLaunchConfiguration(true, new
NullProgressMonitor());
- String twiddleArgs =
lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS
- + JBossServerLaunchConfiguration.PRGM_ARGS_TWIDDLE_SUFFIX, (String)null);
- String user = ArgsUtil.getValue(twiddleArgs, "-u", "--user");
- String password = ArgsUtil.getValue(twiddleArgs, "-p",
"--password");
-
- // get our methods
- Class simplePrincipal =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.SimplePrincipal");
- Class securityAssoc =
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.security.SecurityAssociation");
- securityAssoc.getMethods(); // force-init the methods since the class hasn't been
initialized yet.
-
- Constructor newSimplePrincipal = simplePrincipal.getConstructor(new Class[] {
String.class });
- Object newPrincipalInstance = newSimplePrincipal.newInstance(new Object[] {user});
-
-
- // set the principal
- Method setPrincipalMethod = securityAssoc.getMethod("setPrincipal", new
Class[] {Principal.class});
- setPrincipalMethod.invoke(null, new Object[] {newPrincipalInstance});
-
- // set the credential
- Method setCredentialMethod = securityAssoc.getMethod("setCredential", new
Class[] {Object.class});
- setCredentialMethod.invoke(null, new Object[] {password});
- } catch( Exception e ) {
- e.printStackTrace();
- }
- }
- protected ClassLoader getClassLoader() {
- try {
- IRuntime rt = server.getRuntime();
- IPath loc = rt.getLocation();
- URL url =
loc.append("client").append("jbossall-client.jar").toFile().toURI().toURL();
- URL url2 =
loc.append("bin").append("twiddle.jar").toFile().toURI().toURL();
- URLClassLoader loader = new URLClassLoader(new URL[] {url, url2},
Thread.currentThread().getContextClassLoader());
- return loader;
- } catch( MalformedURLException murle) {
- murle.printStackTrace();
- }
- return null;
- }
- public void setCanceled() {
- if( launcher != null ) {
- launcher.setCanceled();
- }
- }
- }
- public void eventTwiddleExecuted() {
- TwiddlePollerEvent tpe = new TwiddlePollerEvent(event, TYPE_RESULT, started,
expectedState);
- EventLogModel.markChanged(event);
- }
- public void eventAllProcessesTerminated() {
- TwiddlePollerEvent tpe = new TwiddlePollerEvent(event, TYPE_TERMINATED, started,
expectedState);
- EventLogModel.markChanged(event);
- }
-
- private void launchTwiddlePoller() {
- PollerRunnable run = new PollerRunnable();
- Thread t = new Thread(run, "Twiddle Poller");
- t.start();
- }
-
-
- public void cancel(int type) {
- canceled = true;
- }
-
- public void cleanup() {
- }
-
- public class PollingSecurityException extends PollingException {
- public PollingSecurityException(String msg) {super(msg);}
- }
-
- public boolean getState() throws PollingException {
- if( pollingException != null ) throw pollingException;
- if( started == 0 ) return SERVER_DOWN;
- if( started == 1 ) return SERVER_UP;
-
- if( !done && !canceled )
- return !expectedState; // Not there yet.
-
- return expectedState; // done or canceled, doesnt matter
- }
-
- public boolean isComplete() throws PollingException {
- if( pollingException != null )
- throw pollingException;
- return done;
- }
-
-
- public class TwiddlePollerEvent extends EventLogTreeItem {
- public TwiddlePollerEvent(SimpleTreeItem parent, String type, int status, boolean
expectedState) {
- super(parent, PollThread.SERVER_STATE_MAJOR_TYPE, type);
- setProperty(PollThread.EXPECTED_STATE, new Boolean(expectedState));
- setProperty(STATUS, new Integer(status));
- setProperty(DATE, new Long(new Date().getTime()));
- }
- }
-
- public boolean supportsShutdown() {
- return true;
- }
-
- public boolean supportsStartup() {
- return true;
- }
-
-
-
-}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -36,7 +36,7 @@
import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.runtime.server.polling.PollThread;
-import org.jboss.ide.eclipse.as.core.runtime.server.polling.TwiddlePoller;
+import org.jboss.ide.eclipse.as.core.runtime.server.polling.JMXPoller;
import org.jboss.ide.eclipse.as.core.server.stripped.DeployableServerBehavior;
public class JBossServerBehavior extends DeployableServerBehavior {
@@ -145,13 +145,15 @@
pollServer(IServerStatePoller.SERVER_DOWN);
}
+ public IProcess getProcess() {
+ return process;
+ }
-
protected void pollServer(final boolean expectedState) {
if( this.pollThread != null ) {
pollThread.cancel();
}
- this.pollThread = new PollThread("Server Poller", new TwiddlePoller(),
expectedState, this);
+ this.pollThread = new PollThread("Server Poller", expectedState, this);
pollThread.start();
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IServerPollingAttributes.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IServerPollingAttributes.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/attributes/IServerPollingAttributes.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -26,6 +26,9 @@
public static final String STOP_TIMEOUT =
"org.jboss.ide.eclipse.as.core.server.attributes.stopTimeout";
public static final String TIMEOUT_BEHAVIOR =
"org.jboss.ide.eclipse.as.core.server.attributes.timeoutBehavior";
+ public static final String STARTUP_POLLER_KEY =
"org.jboss.ide.eclipse.as.core.server.attributes.startupPollerKey";
+ public static final String SHUTDOWN_POLLER_KEY =
"org.jboss.ide.eclipse.as.core.server.attributes.shutdownPollerKey";
+ public static final String DEFAULT_POLLER =
"org.jboss.ide.eclipse.as.core.runtime.server.twiddlepoller";
public static final boolean TIMEOUT_ABORT = true;
public static final boolean TIMEOUT_IGNORE = false;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2007-07-20 18:43:09 UTC (rev
2574)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2007-07-20 21:09:58 UTC (rev
2575)
@@ -290,11 +290,22 @@
<serverPoller
class="org.jboss.ide.eclipse.as.core.runtime.server.polling.TimeoutPoller"
id="org.jboss.ide.eclipse.as.core.runtime.server.timeoutpoller"
- name="Timeout Poller"/>
+ name="Timeout Poller"
+ supportsStartup="true"
+ supportsShutdown="true"/>
<serverPoller
-
class="org.jboss.ide.eclipse.as.core.runtime.server.polling.TwiddlePoller"
- id="org.jboss.ide.eclipse.as.core.runtime.server.twiddlepoller"
- name="Twiddle Poller"/>
+
class="org.jboss.ide.eclipse.as.core.runtime.server.polling.JMXPoller"
+ id="org.jboss.ide.eclipse.as.core.runtime.server.JMXPoller"
+ name="JMX Poller"
+ supportsStartup="true"
+ supportsShutdown="true"/>
+ <serverPoller
+
class="org.jboss.ide.eclipse.as.core.runtime.server.polling.ProcessTerminatedPoller"
+
id="org.jboss.ide.eclipse.as.core.runtime.server.processTerminatedPoller"
+ name="Process Terminated Poller"
+ supportsShutdown="true"
+ supportsStartup="false">
+ </serverPoller>
</extension>
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/pollers.exsd
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/pollers.exsd 2007-07-20 18:43:09
UTC (rev 2574)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/pollers.exsd 2007-07-20 21:09:58
UTC (rev 2575)
@@ -15,7 +15,6 @@
<sequence>
<element ref="serverPoller" minOccurs="0"
maxOccurs="unbounded"/>
</sequence>
-
<attribute name="point" type="string"
use="required">
<annotation>
<documentation>
@@ -69,6 +68,20 @@
</appInfo>
</annotation>
</attribute>
+ <attribute name="supportsStartup" type="boolean"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="supportsShutdown" type="boolean"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/preferencepages/JBossServersPreferencePage.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/preferencepages/JBossServersPreferencePage.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/preferencepages/JBossServersPreferencePage.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -30,7 +30,6 @@
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -48,7 +47,9 @@
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
@@ -57,9 +58,13 @@
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.part.PageBook;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.internal.ServerType;
import org.eclipse.wst.server.ui.ServerUICore;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
+import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.runtime.server.ServerStatePollerType;
import org.jboss.ide.eclipse.as.core.server.JBossServer;
import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.core.server.attributes.IServerPollingAttributes;
@@ -70,6 +75,16 @@
public class JBossServersPreferencePage extends PreferencePage implements
IWorkbenchPreferencePage {
+ // for the main section
+ private JBossServer currentServer;
+ private Table serverTable;
+ private TableViewer serverTableViewer;
+ private HashMap workingCoppies;
+ private Group serverGroup, secondGroup;
+ private PageBook book;
+ private ServerPreferenceProvider[] groups;
+ int pageColumn = 55;
+
public JBossServersPreferencePage() {
super();
}
@@ -84,61 +99,26 @@
protected Control createContents(Composite parent) {
Composite main = new Composite(parent, SWT.BORDER);
-// main.setLayout(new GridLayout(1, false));
main.setLayout(new FormLayout());
-
createServerViewer(main);
- createTimeoutGroup(main);
+ createSecondGroup(main);
addListeners();
-
-
- // minimum width enforcer
-// Label l = new Label(main, SWT.NONE);
-// FormData lData = new FormData();
-// lData.left = new FormAttachment(0,0);
-// lData.right = new FormAttachment(0,600);
-// lData.bottom = new FormAttachment(100,0);
-// lData.top = new FormAttachment(100,0);
-// l.setLayoutData(lData);
-// main.layout();
-
-
return main;
}
- private JBossServer currentServer;
-
- private Group timeoutGroup;
- private Table serverTable;
- private TableViewer serverTableViewer;
- private Spinner stopSpinner, startSpinner;
- private Button abortOnTimeout, ignoreOnTimeout;
-
- private HashMap workingCoppies;
-
-
- // where the page fold is
- int pageColumn = 55;
-
- private Group serverGroup;
-
-
protected void createServerViewer(Composite main) {
serverGroup = new Group(main, SWT.NONE);
- // serverGroup.setLayout(new GridLayout(1, false));
FillLayout serverGroupLayout = new FillLayout();
serverGroupLayout.marginHeight = 5;
serverGroupLayout.marginWidth = 5;
serverGroup.setLayout(serverGroupLayout);
-// serverGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
serverGroup.setText("Servers");
workingCoppies = new HashMap();
serverTable = new Table(serverGroup, SWT.BORDER);
-// serverTable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
FormData lData = new FormData();
lData.left = new FormAttachment(0,5);
lData.right = new FormAttachment(100,-5);
@@ -188,96 +168,29 @@
}
- protected void createTimeoutGroup(Composite main) {
- timeoutGroup = new Group(main, SWT.NONE);
- timeoutGroup.setText(Messages.PreferencePageServerTimeouts);
-// timeoutGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
- FormData groupData = new FormData();
-
- groupData.left = new FormAttachment(0, 5);
- groupData.right = new FormAttachment(100, -5);
- groupData.top = new FormAttachment(serverGroup,5);
- timeoutGroup.setLayoutData(groupData);
+ protected void createSecondGroup(Composite main) {
+ secondGroup = new Group(main, SWT.NONE);
- timeoutGroup.setLayout(new FormLayout());
-
- // add two textboxes, two labels
- Label startTimeoutLabel, stopTimeoutLabel;
-
- startTimeoutLabel = new Label(timeoutGroup, SWT.NONE);
- stopTimeoutLabel = new Label(timeoutGroup, SWT.NONE);
-
- stopSpinner = new Spinner(timeoutGroup, SWT.BORDER);
- startSpinner = new Spinner(timeoutGroup, SWT.BORDER);
-
- FormData startTD = new FormData();
- startTD.left = new FormAttachment(0,5);
- startTD.top = new FormAttachment(0,5);
- startTimeoutLabel.setLayoutData(startTD);
- startTimeoutLabel.setText(Messages.PreferencePageStartTimeouts);
-
- FormData stopTD = new FormData();
- stopTD.left = new FormAttachment(0,5);
- stopTD.top = new FormAttachment(startSpinner,4);
- stopTimeoutLabel.setLayoutData(stopTD);
- stopTimeoutLabel.setText(Messages.PreferencePageStopTimeouts);
-
- timeoutGroup.layout();
- int startWidth = startTimeoutLabel.getSize().x;
- int stopWidth = stopTimeoutLabel.getSize().x;
-
- Label widest = startWidth > stopWidth ? startTimeoutLabel : stopTimeoutLabel;
-
- FormData startD = new FormData();
- startD.left = new FormAttachment(0,widest.getSize().x + widest.getLocation().x + 5);
- startD.right = new FormAttachment(100, -5);
- startD.top = new FormAttachment(0,5);
- startSpinner.setLayoutData(startD);
-
- FormData stopD = new FormData();
- stopD.left = new FormAttachment(0,widest.getSize().x + widest.getLocation().x + 5);
- stopD.right = new FormAttachment(100, -5);
- stopD.top = new FormAttachment(startSpinner,5);
- stopSpinner.setLayoutData(stopD);
-
-
- stopSpinner.setMinimum(0);
- startSpinner.setMinimum(0);
- stopSpinner.setIncrement(1);
- startSpinner.setIncrement(1);
- stopSpinner.setEnabled(false);
- startSpinner.setEnabled(false);
-
- Label uponTimeoutLabel = new Label(timeoutGroup, SWT.NONE);
- abortOnTimeout = new Button(timeoutGroup, SWT.RADIO);
- ignoreOnTimeout = new Button(timeoutGroup, SWT.RADIO);
-
- FormData utl = new FormData();
- utl.left = new FormAttachment(0,5);
- utl.right = new FormAttachment(100, -5);
- utl.top = new FormAttachment(stopSpinner,5);
- uponTimeoutLabel.setLayoutData(utl);
+ FormData lData = new FormData();
+ lData.left = new FormAttachment(0,5);
+ lData.right = new FormAttachment(100,-5);
+ lData.top = new FormAttachment(serverGroup,5);
+ lData.bottom = new FormAttachment(100,-5);
+ secondGroup.setLayoutData(lData);
- FormData b1D = new FormData();
- b1D.left = new FormAttachment(0,15);
- b1D.right = new FormAttachment(100, -5);
- b1D.top = new FormAttachment(uponTimeoutLabel,5);
- abortOnTimeout.setLayoutData(b1D);
- FormData b2D = new FormData();
- b2D.left = new FormAttachment(0,15);
- b2D.right = new FormAttachment(100, -5);
- b2D.top = new FormAttachment(abortOnTimeout,5);
- ignoreOnTimeout.setLayoutData(b2D);
- uponTimeoutLabel.setText(Messages.PreferencePageUponTimeout);
- abortOnTimeout.setText(Messages.PreferencePageUponTimeoutAbort);
- ignoreOnTimeout.setText(Messages.PreferencePageUponTimeoutIgnore);
- abortOnTimeout.setEnabled(false);
- ignoreOnTimeout.setEnabled(false);
-
+ secondGroup.setLayout(new FillLayout());
+ book = new PageBook(secondGroup, SWT.NONE);
+ groups = new ServerPreferenceProvider[] {
+ new TimeoutComposite(book)
+ };
+ book.showPage(groups[0]);
+ secondGroup.setText(groups[0].getName());
}
+
+
private void addListeners() {
serverTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
@@ -285,76 +198,17 @@
serverSelected(sel.getFirstElement() == null ? null :
(JBossServer)sel.getFirstElement());
}
});
-
- startSpinner.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- getSelectedWC().setAttribute(IServerPollingAttributes.START_TIMEOUT,
startSpinner.getSelection() * 1000);
- }
- });
- stopSpinner.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- getSelectedWC().setAttribute(IServerPollingAttributes.STOP_TIMEOUT,
stopSpinner.getSelection() * 1000);
- }
- });
-
- abortOnTimeout.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- if( getSelectedWC() != null )
- getSelectedWC().setAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_ABORT);
- }
- });
- ignoreOnTimeout.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- if( getSelectedWC() != null )
- getSelectedWC().setAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_IGNORE);
- }
- });
-
}
-
+
private void serverSelected(JBossServer server) {
currentServer = server;
ServerAttributeHelper wcHelper = getWCHelper(server);
-
- /* Handle spinners */
- startSpinner.setMaximum(((ServerType)server.getServer().getServerType()).getStartTimeout()
/ 1000);
- stopSpinner.setMaximum(((ServerType)server.getServer().getServerType()).getStopTimeout()
/ 1000);
- startSpinner.setSelection(getStartTimeout(wcHelper));
- stopSpinner.setSelection(getStopTimeout(wcHelper));
-
- startSpinner.setEnabled(true);
- stopSpinner.setEnabled(true);
- abortOnTimeout.setEnabled(true);
- ignoreOnTimeout.setEnabled(true);
-
- boolean currentVal = wcHelper.getAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_IGNORE);
- if( currentVal == IServerPollingAttributes.TIMEOUT_ABORT) {
- abortOnTimeout.setSelection(true);
- ignoreOnTimeout.setSelection(false);
- } else {
- abortOnTimeout.setSelection(false);
- ignoreOnTimeout.setSelection(true);
+ for( int i = 0; i < groups.length; i++ ) {
+ try {
+ groups[i].serverSelected(server, wcHelper);
+ } catch( Exception e ) {}
}
}
-
- public int getStartTimeout(ServerAttributeHelper helper) {
- int prop = helper.getAttribute(IServerPollingAttributes.START_TIMEOUT, -1);
- int max = ((ServerType)helper.getServer().getServerType()).getStartTimeout();
-
- if( prop <= 0 || prop > max ) return max / 1000;
- return prop / 1000;
- }
- public int getStopTimeout(ServerAttributeHelper helper) {
- int prop = helper.getAttribute(IServerPollingAttributes.STOP_TIMEOUT, -1);
- int max = ((ServerType)helper.getServer().getServerType()).getStopTimeout();
-
- if( prop <= 0 || prop > max ) return max / 1000;
- return prop / 1000;
- }
private ServerAttributeHelper getWCHelper(JBossServer server) {
@@ -368,28 +222,12 @@
}
private ServerAttributeHelper getSelectedWC() {
- IStructuredSelection sel = (IStructuredSelection)serverTableViewer.getSelection();
- if( sel != null && sel.getFirstElement() != null ) {
- return getWCHelper((JBossServer)sel.getFirstElement());
- }
- return null;
+ return currentServer == null ? null : getWCHelper(currentServer);
}
public void init(IWorkbench workbench) {
}
-
- public Object getFirstSelected(Viewer viewer) {
- ISelection sel = viewer.getSelection();
- if( sel instanceof IStructuredSelection) {
- Object o = ((IStructuredSelection)sel).getFirstElement();
- return o;
- }
- return null;
- }
-
-
-
-
+
public boolean performOk() {
super.performOk();
saveDirtyWorkingCoppies();
@@ -417,7 +255,275 @@
}
}
- public boolean performCancel() {
- return super.performCancel();
+ public static abstract class ServerPreferenceProvider extends Composite {
+ protected String name;
+ public ServerPreferenceProvider(Composite parent, int style,
+ String name) {
+ super(parent, style);
+ this.name = name;
+ }
+ public String getName() { return name; }
+ public abstract void serverSelected(JBossServer server, ServerAttributeHelper
helper);
}
+
+ public static class TimeoutComposite extends ServerPreferenceProvider {
+
+ private Spinner stopSpinner, startSpinner;
+ private Button abortOnTimeout, ignoreOnTimeout;
+ private JBossServer server;
+ private ServerAttributeHelper helper;
+ private Composite durations, behavior, pollers;
+
+ // polling
+ private Combo startPollerCombo, stopPollerCombo;
+ private String[] startupTypesStrings, shutdownTypesStrings;
+ ServerStatePollerType[] startupTypes, shutdownTypes;
+
+ public TimeoutComposite(Composite parent) {
+ super(parent, SWT.NONE, Messages.PreferencePageServerTimeouts);
+
+ findPossiblePollers();
+
+ setLayout(new FormLayout());
+ createTimeoutDurations();
+ createTimeoutBehavior();
+ createPollerChoices();
+
+ durations.setLayoutData(createLayoutData(null));
+ behavior.setLayoutData(createLayoutData(durations));
+ pollers.setLayoutData(createLayoutData(behavior));
+ addTimeoutListeners();
+ }
+
+ protected void findPossiblePollers() {
+ startupTypes = ExtensionManager.getDefault().getStartupPollers();
+ shutdownTypes = ExtensionManager.getDefault().getShutdownPollers();
+ startupTypesStrings = new String[startupTypes.length];
+ shutdownTypesStrings = new String[shutdownTypes.length];
+
+ for( int i = 0; i < startupTypes.length; i++ ) {
+ startupTypesStrings[i] = startupTypes[i].getName();
+ }
+ for( int i = 0; i < shutdownTypes.length; i++ ) {
+ shutdownTypesStrings[i] = shutdownTypes[i].getName();
+ }
+ }
+
+ private FormData createLayoutData(Composite top) {
+ FormData data = new FormData();
+ if( top == null ) data.top = new FormAttachment(0,5);
+ else data.top = new FormAttachment(top, 5);
+ data.left = new FormAttachment(0,5);
+ data.right = new FormAttachment(100,-5);
+ return data;
+ }
+ public void serverSelected(JBossServer server,
+ ServerAttributeHelper helper) {
+ this.server = server;
+ this.helper = helper;
+ timeoutServerSelected();
+ }
+
+ protected void createTimeoutDurations() {
+ durations = new Composite(this, SWT.NONE);
+ durations.setLayout(new FormLayout());
+
+ // add two textboxes, two labels
+ Label startTimeoutLabel, stopTimeoutLabel;
+
+ startTimeoutLabel = new Label(durations, SWT.NONE);
+ stopTimeoutLabel = new Label(durations, SWT.NONE);
+
+ stopSpinner = new Spinner(durations, SWT.BORDER);
+ startSpinner = new Spinner(durations, SWT.BORDER);
+
+ FormData startTD = new FormData();
+ startTD.left = new FormAttachment(0,5);
+ startTD.top = new FormAttachment(0,7);
+ startTimeoutLabel.setLayoutData(startTD);
+ startTimeoutLabel.setText(Messages.PreferencePageStartTimeouts);
+
+ FormData stopTD = new FormData();
+ stopTD.left = new FormAttachment(0,5);
+ stopTD.top = new FormAttachment(startSpinner,7);
+ stopTimeoutLabel.setLayoutData(stopTD);
+ stopTimeoutLabel.setText(Messages.PreferencePageStopTimeouts);
+
+ durations.layout();
+ int startWidth = startTimeoutLabel.getSize().x;
+ int stopWidth = stopTimeoutLabel.getSize().x;
+
+ Label widest = startWidth > stopWidth ? startTimeoutLabel : stopTimeoutLabel;
+
+ FormData startD = new FormData();
+ startD.left = new FormAttachment(0,widest.getSize().x + widest.getLocation().x + 5);
+ startD.right = new FormAttachment(100, -5);
+ startD.top = new FormAttachment(0,5);
+ startSpinner.setLayoutData(startD);
+
+ FormData stopD = new FormData();
+ stopD.left = new FormAttachment(0,widest.getSize().x + widest.getLocation().x + 5);
+ stopD.right = new FormAttachment(100, -5);
+ stopD.top = new FormAttachment(startSpinner,5);
+ stopSpinner.setLayoutData(stopD);
+
+
+ stopSpinner.setMinimum(0);
+ startSpinner.setMinimum(0);
+ stopSpinner.setIncrement(1);
+ startSpinner.setIncrement(1);
+ stopSpinner.setEnabled(false);
+ startSpinner.setEnabled(false);
+
+ }
+
+ protected void createTimeoutBehavior() {
+ behavior = new Composite(this, SWT.NONE);
+ behavior.setLayout(new FormLayout());
+
+ Label uponTimeoutLabel = new Label(behavior, SWT.NONE);
+ abortOnTimeout = new Button(behavior, SWT.RADIO);
+ ignoreOnTimeout = new Button(behavior, SWT.RADIO);
+
+ FormData utl = new FormData();
+ utl.left = new FormAttachment(0,5);
+ utl.right = new FormAttachment(100, -5);
+ utl.top = new FormAttachment(0,5);
+ uponTimeoutLabel.setLayoutData(utl);
+
+ FormData b1D = new FormData();
+ b1D.left = new FormAttachment(0,15);
+ b1D.right = new FormAttachment(100, -5);
+ b1D.top = new FormAttachment(uponTimeoutLabel,5);
+ abortOnTimeout.setLayoutData(b1D);
+
+ FormData b2D = new FormData();
+ b2D.left = new FormAttachment(0,15);
+ b2D.right = new FormAttachment(100, -5);
+ b2D.top = new FormAttachment(abortOnTimeout,5);
+ ignoreOnTimeout.setLayoutData(b2D);
+
+ uponTimeoutLabel.setText(Messages.PreferencePageUponTimeout);
+ abortOnTimeout.setText(Messages.PreferencePageUponTimeoutAbort);
+ ignoreOnTimeout.setText(Messages.PreferencePageUponTimeoutIgnore);
+ abortOnTimeout.setEnabled(false);
+ ignoreOnTimeout.setEnabled(false);
+
+ }
+
+ protected void createPollerChoices() {
+ pollers = new Composite(this, SWT.NONE);
+ pollers.setLayout(new GridLayout(2, false));
+
+ // create widgets
+ Label start, stop;
+ start = new Label(pollers, SWT.NONE);
+ startPollerCombo = new Combo(pollers, SWT.READ_ONLY);
+ stop = new Label(pollers, SWT.NONE);
+ stopPollerCombo = new Combo(pollers, SWT.READ_ONLY);
+
+ start.setText("Startup Poller");
+ stop.setText("Shutdown Poller");
+
+ // set items
+ startPollerCombo.setItems(startupTypesStrings);
+ stopPollerCombo.setItems(shutdownTypesStrings);
+
+ startPollerCombo.setEnabled(false);
+ stopPollerCombo.setEnabled(false);
+ }
+
+ private void addTimeoutListeners() {
+ startSpinner.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if( helper != null )
+ helper.setAttribute(IServerPollingAttributes.START_TIMEOUT,
startSpinner.getSelection() * 1000);
+ }
+ });
+ stopSpinner.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if( helper != null )
+ helper.setAttribute(IServerPollingAttributes.STOP_TIMEOUT,
stopSpinner.getSelection() * 1000);
+ }
+ });
+
+ abortOnTimeout.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if( helper != null )
+ helper.setAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_ABORT);
+ }
+ });
+ ignoreOnTimeout.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if( helper != null )
+ helper.setAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_IGNORE);
+ }
+ });
+ startPollerCombo.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if( helper != null )
+ helper.setAttribute(IServerPollingAttributes.STARTUP_POLLER_KEY,
startupTypes[startPollerCombo.getSelectionIndex()].getId());
+ }
+ });
+ stopPollerCombo.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if( helper != null )
+ helper.setAttribute(IServerPollingAttributes.SHUTDOWN_POLLER_KEY,
shutdownTypes[stopPollerCombo.getSelectionIndex()].getId());
+ }
+ });
+ }
+
+ private void timeoutServerSelected() {
+ // Handle spinners
+ startSpinner.setMaximum(((ServerType)server.getServer().getServerType()).getStartTimeout()
/ 1000);
+ stopSpinner.setMaximum(((ServerType)server.getServer().getServerType()).getStopTimeout()
/ 1000);
+ startSpinner.setSelection(getStartTimeout(helper));
+ stopSpinner.setSelection(getStopTimeout(helper));
+
+ startSpinner.setEnabled(true);
+ stopSpinner.setEnabled(true);
+ abortOnTimeout.setEnabled(true);
+ ignoreOnTimeout.setEnabled(true);
+
+ boolean currentVal = helper.getAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR,
IServerPollingAttributes.TIMEOUT_IGNORE);
+ if( currentVal == IServerPollingAttributes.TIMEOUT_ABORT) {
+ abortOnTimeout.setSelection(true);
+ ignoreOnTimeout.setSelection(false);
+ } else {
+ abortOnTimeout.setSelection(false);
+ ignoreOnTimeout.setSelection(true);
+ }
+
+ // poller
+ stopPollerCombo.setEnabled(true);
+ startPollerCombo.setEnabled(true);
+ String currentStartId =
helper.getAttribute(IServerPollingAttributes.STARTUP_POLLER_KEY,
IServerPollingAttributes.DEFAULT_POLLER);
+ String currentStopId =
helper.getAttribute(IServerPollingAttributes.SHUTDOWN_POLLER_KEY,
IServerPollingAttributes.DEFAULT_POLLER);
+ startPollerCombo.select(startPollerCombo.indexOf(ExtensionManager.getDefault().getPollerType(currentStartId).getName()));
+ stopPollerCombo.select(stopPollerCombo.indexOf(ExtensionManager.getDefault().getPollerType(currentStopId).getName()));
+ }
+
+ public int getStartTimeout(ServerAttributeHelper helper) {
+ int prop = helper.getAttribute(IServerPollingAttributes.START_TIMEOUT, -1);
+ int max = ((ServerType)helper.getServer().getServerType()).getStartTimeout();
+
+ if( prop <= 0 || prop > max ) return max / 1000;
+ return prop / 1000;
+ }
+ public int getStopTimeout(ServerAttributeHelper helper) {
+ int prop = helper.getAttribute(IServerPollingAttributes.STOP_TIMEOUT, -1);
+ int max = ((ServerType)helper.getServer().getServerType()).getStopTimeout();
+
+ if( prop <= 0 || prop > max ) return max / 1000;
+ return prop / 1000;
+ }
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java 2007-07-20
18:43:09 UTC (rev 2574)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/events/PollingLabelProvider.java 2007-07-20
21:09:58 UTC (rev 2575)
@@ -37,7 +37,7 @@
import org.jboss.ide.eclipse.as.core.model.EventLogModel.EventLogTreeItem;
import org.jboss.ide.eclipse.as.core.runtime.server.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.runtime.server.polling.PollThread;
-import org.jboss.ide.eclipse.as.core.runtime.server.polling.TwiddlePoller;
+import org.jboss.ide.eclipse.as.core.runtime.server.polling.JMXPoller;
import org.jboss.ide.eclipse.as.core.runtime.server.polling.PollThread.PollThreadEvent;
import org.jboss.ide.eclipse.as.core.server.JBossServerBehavior;
import org.jboss.ide.eclipse.as.ui.views.server.extensions.IEventLogLabelProvider;
@@ -59,8 +59,8 @@
supported.add(PollThread.POLL_THREAD_TIMEOUT);
supported.add(PollThread.POLL_THREAD_EXCEPTION);
- supported.add(TwiddlePoller.TYPE_TERMINATED);
- supported.add(TwiddlePoller.TYPE_RESULT);
+ supported.add(JMXPoller.TYPE_TERMINATED);
+ supported.add(JMXPoller.TYPE_RESULT);
supported.add(JBossServerBehavior.FORCE_SHUTDOWN_EVENT_KEY);
}
@@ -84,15 +84,15 @@
return getErrorImage();
}
- if( element.getSpecificType().equals(TwiddlePoller.TYPE_TERMINATED)) return
getErrorImage();
- if( element.getSpecificType().equals(TwiddlePoller.TYPE_RESULT)) {
- int state = ((Integer)element.getProperty(TwiddlePoller.STATUS)).intValue();
+ if( element.getSpecificType().equals(JMXPoller.TYPE_TERMINATED)) return
getErrorImage();
+ if( element.getSpecificType().equals(JMXPoller.TYPE_RESULT)) {
+ int state = ((Integer)element.getProperty(JMXPoller.STATUS)).intValue();
boolean expectedState =
((Boolean)element.getProperty(PollThread.EXPECTED_STATE)).booleanValue();
- if( state == TwiddlePoller.STATE_STOPPED)
+ if( state == JMXPoller.STATE_STOPPED)
return getStoppedImage();
- if( state == TwiddlePoller.STATE_STARTED)
+ if( state == JMXPoller.STATE_STARTED)
return getStartedImage();
- if( state == TwiddlePoller.STATE_TRANSITION) {
+ if( state == JMXPoller.STATE_TRANSITION) {
if( expectedState == IServerStatePoller.SERVER_UP )
return getStartingImage();
return getStoppingImage();
@@ -119,15 +119,15 @@
if( element.getSpecificType().equals(PollThread.FAILURE)) return expectedString +
" failed";
}
- if( element.getSpecificType().equals(TwiddlePoller.TYPE_TERMINATED)) return "All
processes have been terminated";
- if( element.getSpecificType().equals(TwiddlePoller.TYPE_RESULT)) {
- int state = ((Integer)element.getProperty(TwiddlePoller.STATUS)).intValue();
+ if( element.getSpecificType().equals(JMXPoller.TYPE_TERMINATED)) return "All
processes have been terminated";
+ if( element.getSpecificType().equals(JMXPoller.TYPE_RESULT)) {
+ int state = ((Integer)element.getProperty(JMXPoller.STATUS)).intValue();
boolean expectedState =
((Boolean)element.getProperty(PollThread.EXPECTED_STATE)).booleanValue();
- if( state == TwiddlePoller.STATE_STOPPED)
+ if( state == JMXPoller.STATE_STOPPED)
return "The server is down.";
- if( state == TwiddlePoller.STATE_STARTED)
+ if( state == JMXPoller.STATE_STARTED)
return "The server is up.";
- if( state == TwiddlePoller.STATE_TRANSITION) {
+ if( state == JMXPoller.STATE_TRANSITION) {
if( expectedState == IServerStatePoller.SERVER_UP )
return "The server is still starting";
return "The server is still stopping.";
@@ -168,13 +168,13 @@
protected void loadPropertyMap() {
// property names and their readable forms
propertyToMessageMap.put(EventLogTreeItem.DATE, "Time");
- propertyToMessageMap.put(TwiddlePoller.STATUS, "Status");
+ propertyToMessageMap.put(JMXPoller.STATUS, "Status");
propertyToMessageMap.put(PollThread.EXPECTED_STATE, "Expected State");
// now values and their readable forms
- propertyToMessageMap.put(TwiddlePoller.STATUS + DELIMITER + 0, "Server is
Down");
- propertyToMessageMap.put(TwiddlePoller.STATUS + DELIMITER + 1, "Server is
Up");
- propertyToMessageMap.put(TwiddlePoller.STATUS + DELIMITER + -1, "Server is in
transition");
+ propertyToMessageMap.put(JMXPoller.STATUS + DELIMITER + 0, "Server is
Down");
+ propertyToMessageMap.put(JMXPoller.STATUS + DELIMITER + 1, "Server is Up");
+ propertyToMessageMap.put(JMXPoller.STATUS + DELIMITER + -1, "Server is in
transition");
propertyToMessageMap.put(PollThread.EXPECTED_STATE + DELIMITER + "true",
"Up");
propertyToMessageMap.put(PollThread.EXPECTED_STATE + DELIMITER + "false",
"Down");
}