[jbosstools-dev] [Fwd: [jbosstools-commits] JBoss Tools SVN: r2207 - in trunk/as/plugins/org.jboss.ide.eclipse.as.core: META-INF and 2 other directories.]
Max Rydahl Andersen
max.andersen at redhat.com
Mon Jul 2 11:43:27 EDT 2007
> The twiddle launch was a *very* heavy thing. Sure, it'd only run a quick
> JMX client to poll the server, but it'd do this 10 times or more before
> the server was actually started. Each time it did it, it would spawn a
> new process, with all the overhead of a new VM etc, just to do what is
> really a few lines of JMX code.
fair enough.
Is the api we use portable enough for working with 4.x ?
/max
> I removed the hard-coded stuff within an hour of committing it ;) But
> I'm glad you're being diligent in communicating here.
>
> You're right in that my new Poller doesn't clean up its class loader.
I'll have to look into that.
>
> Overall I think it was a necessary change. yes it was heavy.
>
> Max Rydahl Andersen wrote:
>> Just noticed this one in commits:
>>
>> No longer launches twiddle as its own process.
>>
>> and the code is now using classloaders inside the eclipse process to
>> get the launch going.
>>
>> I know this is tempting to do (I did it myself in hibernate tools) BUT
>> I wan't to remove it again simply because it very easily result in leaks.
>>
>> e.g. the current code does not use a finally block to clean up its
>> classloader (p.s. it also seem to use hardcoded paths to the jbossas
>> server?!)
>>
>> Was the twiddle launch really a heavy thing or ?
>>
>> /max
>>
>> ------------------------------------------------------------------------
>>
>> Subject:
>> [jbosstools-commits] JBoss Tools SVN: r2207 - in
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core: META-INF and 2 other
>> directories.
>> From:
>> jbosstools-commits at lists.jboss.org
>> Date:
>> Thu, 28 Jun 2007 20:19:55 -0400
>> To:
>> jbosstools-commits at lists.jboss.org
>>
>> To:
>> jbosstools-commits at lists.jboss.org
>>
>>
>> Author: rob.stryker at jboss.com
>> Date: 2007-06-28 20:19:55 -0400 (Thu, 28 Jun 2007)
>> New Revision: 2207
>>
>> Added:
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/getopt.jar
>> Modified:
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/.classpath
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/build.properties
>>
>> 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/server/JBossServerBehavior.java
>>
>> Log:
>> More efficient polling mechanism added. No longer launches twiddle as
>> its own process.
>>
>> Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/.classpath
>> ===================================================================
>> --- trunk/as/plugins/org.jboss.ide.eclipse.as.core/.classpath
>> 2007-06-28 17:15:47 UTC (rev 2206)
>> +++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/.classpath
>> 2007-06-29 00:19:55 UTC (rev 2207)
>> @@ -1,9 +1,11 @@
>> <?xml version="1.0" encoding="UTF-8"?>
>> <classpath>
>> <classpathentry kind="src" path="jbosscore"/>
>> + <classpathentry exported="true" kind="lib" path="getopt.jar"/>
>> <classpathentry exported="true" kind="lib" path="dom4j-1.6.1.jar"/>
>> <classpathentry exported="true" kind="lib"
>> path="jaxen-1.1-beta-6.jar"/>
>> <classpathentry kind="con"
>> path="org.eclipse.pde.core.requiredPlugins"/>
>> <classpathentry kind="con"
>> path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
>> + <classpathentry kind="lib"
>> path="C:/Training/jboss-4.x/lib/getopt.jar"/>
>> <classpathentry kind="output" path="bin"/>
>> </classpath>
>>
>> Modified:
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
>> ===================================================================
>> ---
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
>> 2007-06-28 17:15:47 UTC (rev 2206)
>> +++
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
>> 2007-06-29 00:19:55 UTC (rev 2207)
>> @@ -36,4 +36,5 @@
>> org.jboss.ide.eclipse.as.core.util
>> Bundle-ClassPath: dom4j-1.6.1.jar,
>> jaxen-1.1-beta-6.jar,
>> - jbossascore.jar
>> + jbossascore.jar,
>> + getopt.jar
>>
>> Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/build.properties
>> ===================================================================
>> --- trunk/as/plugins/org.jboss.ide.eclipse.as.core/build.properties
>> 2007-06-28 17:15:47 UTC (rev 2206)
>> +++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/build.properties
>> 2007-06-29 00:19:55 UTC (rev 2207)
>> @@ -6,5 +6,6 @@
>> jaxen-1.1-beta-6.jar,\
>> dom4j-1.6.1.jar,\
>> plugin.properties,\
>> - schema/
>> + schema/,\
>> + getopt.jar
>> source.jbossascore.jar = jbosscore/
>>
>> Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/getopt.jar
>> ===================================================================
>> (Binary files differ)
>>
>>
>> Property changes on:
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/getopt.jar
>> ___________________________________________________________________
>> Name: svn:mime-type
>> + application/octet-stream
>>
>> Modified:
>> 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-06-28 17:15:47 UTC (rev 2206)
>> +++
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/runtime/server/polling/TwiddlePoller.java
>> 2007-06-29 00:19:55 UTC (rev 2207)
>> @@ -21,9 +21,25 @@
>> */
>> package org.jboss.ide.eclipse.as.core.runtime.server.polling;
>>
>> +import java.io.IOException;
>> +import java.net.MalformedURLException;
>> +import java.net.URL;
>> +import java.net.URLClassLoader;
>> import java.util.Date;
>> +import java.util.Properties;
>>
>> -import org.eclipse.debug.core.model.IProcess;
>> +import javax.management.AttributeNotFoundException;
>> +import javax.management.InstanceNotFoundException;
>> +import javax.management.MBeanException;
>> +import javax.management.MBeanServerConnection;
>> +import javax.management.MalformedObjectNameException;
>> +import javax.management.ObjectName;
>> +import javax.management.ReflectionException;
>> +import javax.naming.InitialContext;
>> +import javax.naming.NamingException;
>> +
>> +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
>> +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
>> import org.eclipse.wst.server.core.IServer;
>> import org.jboss.ide.eclipse.as.core.model.EventLogModel;
>> import org.jboss.ide.eclipse.as.core.model.ServerProcessModel;
>> @@ -32,7 +48,7 @@
>> 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.server.TwiddleLauncher.ProcessData;
>> +import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
>> import org.jboss.ide.eclipse.as.core.util.SimpleTreeItem;
>>
>> public class TwiddlePoller implements IServerStatePoller {
>> @@ -66,44 +82,61 @@
>> private class PollerRunnable implements Runnable {
>> private TwiddleLauncher launcher;
>> public void run() {
>> - String args = "get \"jboss.system:type=Server\" Started";
>> - while( !canceled && !done ) {
>> - // are start processes still going?
>> - ServerProcessModelEntity ent =
>> ServerProcessModel.getDefault().getModel(server.getId());
>> - IProcess[] processes =
>> ent.getProcesses(JBossServerLaunchConfiguration.START);
>> - if(
>> ServerProcessModel.allProcessesTerminated(processes)) {
>> - done = true;
>> - started = 0;
>> - eventAllProcessesTerminated();
>> - } else {
>> - launcher = new TwiddleLauncher();
>> - ProcessData[] datas =
>> launcher.getTwiddleResults(server, args, true);
>> - if( datas.length == 1 ) {
>> - ProcessData d = datas[0];
>> - String out = d.getOut();
>> - if( out.startsWith("Started=true")) {
>> - started = STATE_STARTED;
>> - } else if(out.startsWith("Started=false")) {
>> - started = STATE_TRANSITION; // it's alive
>> and responding
>> - } else if(
>> out.indexOf("java.lang.SecurityException") != -1 ) {
>> - // throw exception
>> - securityException = true;
>> - } else {
>> - started = STATE_STOPPED; // It's fully down
>> - }
>> -
>> - if( started == 1 && expectedState ==
>> SERVER_UP ) {
>> + ClassLoader currentLoader =
>> Thread.currentThread().getContextClassLoader();
>> + ClassLoader twiddleLoader = getClassLoader();
>> + if( twiddleLoader != null ) {
>> +
>> Thread.currentThread().setContextClassLoader(twiddleLoader);
>> + System.out.println("here we go");
>> +
>> + Properties props = new Properties();
>> + props.put("java.naming.factory.initial",
>> "org.jnp.interfaces.NamingContextFactory");
>> +
>> props.put("java.naming.provider.url","jnp://localhost:1099");
>> +
>> props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
>>
>> + + while( !done && !canceled ) {
>> + InitialContext ic;
>> + try {
>> + ic = new InitialContext(props);
>> + Object obj =
>> ic.lookup("jmx/invoker/RMIAdaptor");
>> + ic.close();
>> + System.out.println(obj);
>> + 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 (NamingException e) {
>> + // should give up now
>> + } catch( SecurityException se ) {
>> + securityException = true;
>> + } catch( Exception e ) {
>> + System.out.println("exception: " +
>> e.getMessage());
>> + e.printStackTrace();
>> + started = STATE_STOPPED;
>> + if( !expectedState )
>> done = true;
>> - } else if( started == 0 && expectedState ==
>> SERVER_DOWN) {
>> - done = true;
>> - } }
>> - }
>> - if( !canceled )
>> - eventTwiddleExecuted();
>> +
>> + } // end while
>> }
>> +
>> + Thread.currentThread().setContextClassLoader(currentLoader);
>> +
>> }
>> -
>> + protected ClassLoader getClassLoader() {
>> + try {
>> + URL url = new
>> URL("file:///C:/apps/jboss/4.2.ga.src/build/output/jboss-4.2.0.GA/client/jbossall-client.jar");
>>
>> + URL url2 = new
>> URL("file:///C:/apps/jboss/4.2.ga.src/build/output/jboss-4.2.0.GA/bin/twiddle.jar");
>>
>> + 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();
>>
>> 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-06-28 17:15:47 UTC (rev 2206)
>> +++
>> trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java
>> 2007-06-29 00:19:55 UTC (rev 2207)
>> @@ -45,6 +45,7 @@
>>
>>
>> private PollThread pollThread = null;
>> +
>> public JBossServerBehavior() {
>> super();
>> }
>> @@ -87,14 +88,18 @@
>> }
>>
>> protected void forceStop() {
>> + forceStop(true);
>> + }
>> + protected void forceStop(boolean addEvent) {
>> // just terminate the processes. All of them
>> try {
>>
>> ServerProcessModel.getDefault().getModel(getServer().getId()).clearAll();
>> process = null;
>> setServerStopped();
>> - EventLogTreeItem tpe = new ForceShutdownEvent();
>> - EventLogModel.markChanged(tpe.getEventRoot());
>> -
>> + if( addEvent ) {
>> + EventLogTreeItem tpe = new ForceShutdownEvent();
>> + EventLogModel.markChanged(tpe.getEventRoot());
>> + }
>> } catch( Throwable t ) {
>> t.printStackTrace();
>> }
>> @@ -131,7 +136,7 @@
>> for (int i = 0; i < size; i++) {
>> if (process != null &&
>> process.equals(events[i].getSource()) && events[i].getKind() ==
>> DebugEvent.TERMINATE) {
>>
>> DebugPlugin.getDefault().removeDebugEventListener(this);
>> - forceStop();
>> + forceStop(false);
>> }
>> }
>> }
>>
>> _______________________________________________
>> jbosstools-commits mailing list
>> jbosstools-commits at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/jbosstools-commits
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> jbosstools-dev mailing list
>> jbosstools-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/jbosstools-dev
More information about the jbosstools-dev
mailing list