diff -r 6497ddae98ca glassfish.common/manifest.mf --- a/glassfish.common/manifest.mf Thu Jun 21 18:33:27 2012 +0400 +++ b/glassfish.common/manifest.mf Fri Jun 22 13:10:34 2012 +0200 @@ -3,6 +3,6 @@ OpenIDE-Module-Install: org/netbeans/modules/glassfish/common/Installer.class OpenIDE-Module-Layer: org/netbeans/modules/glassfish/common/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/glassfish/common/Bundle.properties -OpenIDE-Module-Specification-Version: 1.23 +OpenIDE-Module-Specification-Version: 1.24 OpenIDE-Module-Provides: org.netbeans.modules.glassfish.common diff -r 6497ddae98ca glassfish.common/src/org/netbeans/modules/glassfish/common/Bundle.properties --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/Bundle.properties Thu Jun 21 18:33:27 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/Bundle.properties Fri Jun 22 13:10:34 2012 +0200 @@ -84,7 +84,7 @@ MSG_ServerCmdRunning={0} running on {1} MSG_ServerCmdCompleted={0} completed on {1} MSG_ServerCmdFailed={0} failed on {1} \n {2} -MSG_ServerCmdFailedIncorrectInstance={0} failed. Instance is not {1}. +MSG_ServerCmdFailedIncorrectInstance={0} failed. Instance is not {1} or it is not running. MSG_AuthorizationFailed=Authorization failed for {0} on {1}. Bad password? MSG_AuthorizationFailedRemote=Authorization failed for {0} on {1}. Have you run the enable-secure-admin command? MSG_Exception={0} diff -r 6497ddae98ca glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java Thu Jun 21 18:33:27 2012 +0400 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/CommonServerSupport.java Fri Jun 22 13:10:34 2012 +0200 @@ -48,7 +48,6 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.URL; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -78,7 +77,7 @@ import org.netbeans.modules.glassfish.spi.ServerCommand; import org.netbeans.modules.glassfish.spi.ServerCommand.GetPropertyCommand; import org.netbeans.modules.glassfish.spi.CommandFactory; -import org.netbeans.modules.glassfish.spi.GlassfishModule2; +import org.netbeans.modules.glassfish.spi.GlassfishModule3; import org.netbeans.modules.glassfish.spi.Utils; import org.netbeans.modules.glassfish.spi.VMIntrospector; import org.openide.DialogDisplayer; @@ -93,7 +92,7 @@ * * @author Peter Williams */ -public class CommonServerSupport implements GlassfishModule2, RefreshModulesCookie { +public class CommonServerSupport implements GlassfishModule3, RefreshModulesCookie { private final transient Lookup lookup; private final Map properties = @@ -424,6 +423,7 @@ return task; } + @Override public Future restartServer(OperationStateListener stateListener) { Logger.getLogger("glassfish").log(Level.FINEST, "CSS.restartServer called on thread \"{0}\"", Thread.currentThread().getName()); // NOI18N diff -r 6497ddae98ca glassfish.javaee/manifest.mf --- a/glassfish.javaee/manifest.mf Thu Jun 21 18:33:27 2012 +0400 +++ b/glassfish.javaee/manifest.mf Fri Jun 22 13:10:34 2012 +0200 @@ -4,5 +4,5 @@ OpenIDE-Module-Layer: org/netbeans/modules/glassfish/javaee/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/glassfish/javaee/Bundle.properties OpenIDE-Module-Provides: org.netbeans.modules.serverplugins.javaee -OpenIDE-Module-Specification-Version: 1.15 +OpenIDE-Module-Specification-Version: 1.16 diff -r 6497ddae98ca glassfish.javaee/nbproject/project.xml --- a/glassfish.javaee/nbproject/project.xml Thu Jun 21 18:33:27 2012 +0400 +++ b/glassfish.javaee/nbproject/project.xml Fri Jun 22 13:10:34 2012 +0200 @@ -118,7 +118,7 @@ 0-1 - 1.14 + 1.24 diff -r 6497ddae98ca glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2StartServer.java --- a/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2StartServer.java Thu Jun 21 18:33:27 2012 +0400 +++ b/glassfish.javaee/src/org/netbeans/modules/glassfish/javaee/Hk2StartServer.java Fri Jun 22 13:10:34 2012 +0200 @@ -47,6 +47,9 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import javax.enterprise.deploy.shared.ActionType; @@ -71,6 +74,7 @@ import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer; import org.netbeans.modules.glassfish.spi.GlassfishModule; import org.netbeans.modules.glassfish.spi.GlassfishModule.OperationState; +import org.netbeans.modules.glassfish.spi.GlassfishModule3; import org.netbeans.modules.glassfish.spi.OperationStateListener; import org.netbeans.modules.j2ee.deployment.profiler.api.ProfilerSupport; import org.openide.DialogDescriptor; @@ -437,7 +441,7 @@ return this; //we failed to start the server. } - GlassfishModule commonSupport = getCommonServerSupport(); + final GlassfishModule commonSupport = getCommonServerSupport(); if (commonSupport != null) { if (isClusterOrInstance(commonSupport)) { fireHandleProgressEvent(null, new Hk2DeploymentStatus( @@ -478,6 +482,23 @@ fireHandleProgressEvent(null, new Hk2DeploymentStatus( CommandType.START, translateState(newState), ActionType.EXECUTE, message)); + + // FIXME this is pretty ugly workaround and if this is still + // needed once GF plugin is rewritten we should introduce + // some API to notify about external changes of server state + final ScheduledExecutorService statusUpdater = Executors.newSingleThreadScheduledExecutor(); + statusUpdater.scheduleAtFixedRate(new Runnable() { + + @Override + public void run() { + if (ProfilerSupport.getState() == ProfilerSupport.STATE_INACTIVE) { + statusUpdater.shutdownNow(); + if (commonSupport instanceof GlassfishModule3) { + ((GlassfishModule3) commonSupport).refresh(); + } + } + } + }, 50, 100, TimeUnit.MILLISECONDS); } }, GlassfishModule.ServerState.STOPPED_JVM_PROFILER); } diff -r 6497ddae98ca j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java Thu Jun 21 18:33:27 2012 +0400 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java Fri Jun 22 13:10:34 2012 +0200 @@ -72,6 +72,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException; @@ -181,7 +182,7 @@ private final ChangeSupport managerChangeSupport = new ChangeSupport(this); - private volatile static ServerInstance profiledServerInstance; + private static AtomicReference profiledServerInstance = new AtomicReference(); private final DebuggerStateListener debuggerStateListener; @@ -376,7 +377,7 @@ try { int oldState = getServerState(); setServerState(STATE_WAITING); - if (ServerInstance.this == profiledServerInstance) { + if (ServerInstance.this == profiledServerInstance.get()) { updateStateFromProfiler(); return; } @@ -1107,7 +1108,7 @@ throws ServerException { // check whether another server not already running in profile mode // and ask whether it is ok to stop it - ServerInstance tmpProfiledServerInstance = profiledServerInstance; + ServerInstance tmpProfiledServerInstance = profiledServerInstance.get(); if (tmpProfiledServerInstance != null && tmpProfiledServerInstance != this) { String msg = NbBundle.getMessage( ServerInstance.class, @@ -1138,7 +1139,7 @@ try { setServerState(STATE_WAITING); boolean inDebug = isDebuggable(null); - boolean inProfile = profiledServerInstance == this; + boolean inProfile = profiledServerInstance.get() == this; boolean stopped = true; if (inProfile || isReallyRunning() || isSuspended()) { @@ -1166,7 +1167,7 @@ public void stop(ProgressUI ui) throws ServerException { try { setServerState(STATE_WAITING); - if (profiledServerInstance == this || isReallyRunning() || isSuspended()) { + if (profiledServerInstance.get() == this || isReallyRunning() || isSuspended()) { _stop(ui); } debugInfo.clear(); @@ -1488,19 +1489,20 @@ Target target, boolean forceRestart, ProgressUI ui) throws ServerException { - ServerInstance tmpProfiledServerInstance = profiledServerInstance; + ServerInstance tmpProfiledServerInstance = profiledServerInstance.get(); if (tmpProfiledServerInstance == this && !forceRestart) { return; // server is already runnning in profile mode, no need to restart the server } if (tmpProfiledServerInstance != null && tmpProfiledServerInstance != this) { // another server currently running in profiler mode tmpProfiledServerInstance.stop(ui); - profiledServerInstance = null; + boolean done = profiledServerInstance.compareAndSet(tmpProfiledServerInstance, null); + assert done : "Unxpected profiled instance " + profiledServerInstance.get(); } - if (profiledServerInstance == this || isReallyRunning() || isDebuggable(target)) { + if (profiledServerInstance.get() == this || isReallyRunning() || isDebuggable(target)) { _stop(ui); debugInfo.clear(); - profiledServerInstance = null; + //profiledServerInstance = null; } final Profiler profiler = ServerRegistry.getProfiler(); @@ -1510,6 +1512,24 @@ } final ScheduledExecutorService statusUpdater = Executors.newSingleThreadScheduledExecutor(); + + final StateListener l = new StateListener() { + + @Override + public void stateChanged(int oldState, int newState) { + if (oldState != newState && newState == STATE_STOPPED) { + ServerInstance.this.removeStateListener(this); + statusUpdater.shutdownNow(); + ServerInstance.this.refresh(); + boolean done = profiledServerInstance.compareAndSet(ServerInstance.this, null); + assert done : "Unxpected profiled instance " + profiledServerInstance.get(); + } + } + }; + + this.addStateListener(l); + profiler.notifyStarting(); + statusUpdater.scheduleAtFixedRate(new Runnable() { @Override @@ -1518,21 +1538,6 @@ } }, 50, 100, TimeUnit.MILLISECONDS); - final StateListener l = new StateListener() { - - @Override - public void stateChanged(int oldState, int newState) { - if (oldState != newState && newState == STATE_STOPPED) { - ServerInstance.this.removeStateListener(this); - statusUpdater.shutdownNow(); - profiledServerInstance = null; - } - } - }; - - this.addStateListener(l); - - profiler.notifyStarting(); ProgressObject po = getStartServer().startProfiling(target); try { boolean completedSuccessfully = ProgressObjectUtil.trackProgressObject(ui, po, DEFAULT_TIMEOUT); @@ -1543,7 +1548,7 @@ String msg = NbBundle.getMessage(ServerInstance.class, "MSG_StartProfileTimeout", getDisplayName()); throw new ServerException(msg); } - profiledServerInstance = this; + profiledServerInstance.set(this); synchronized (this) { managerStartedByIde = true; // coTarget = null; @@ -1573,9 +1578,10 @@ // stopDeploymentManager private void _stop(ProgressUI ui) throws ServerException { // if the server is started in profile mode, deattach profiler first - if (profiledServerInstance == this) { + if (profiledServerInstance.get() == this) { shutdownProfiler(ui); - profiledServerInstance = null; + boolean done = profiledServerInstance.compareAndSet(this, null); + assert done : "Unxpected profiled instance " + profiledServerInstance.get(); } synchronized (this) { // if the server is suspended, the debug session has to be terminated first @@ -1728,6 +1734,9 @@ } private void fireStateChanged(int oldState, int newState) { + if (oldState == newState) { + return; + } StateListener[] listeners; synchronized (stateListeners) { listeners = (StateListener[])stateListeners.toArray(new StateListener[stateListeners.size()]);