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 11:39:36 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 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 11:39:36 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()]);