diff -r 9587e4825f10 j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Fri Nov 20 21:53:40 2009 +0100 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Mon Nov 23 17:50:14 2009 -0800 @@ -53,6 +53,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Enumeration; import java.util.EventListener; import java.util.HashMap; import java.util.HashSet; @@ -357,7 +358,7 @@ checkInstanceAlreadyExists(url); try { - addInstanceImpl(url, username, password, displayName, withoutUI, initialproperties); + addInstanceImpl(url, username, password, displayName, withoutUI, initialproperties,true); } catch (InstanceCreationException ice) { InstanceCreationException e = new InstanceCreationException(NbBundle.getMessage(ServerRegistry.class, "MSG_FailedToCreateInstance", displayName)); e.initCause(ice); @@ -413,57 +414,76 @@ * @return true if the server instance was created successfully, * false otherwise. */ - private synchronized void addInstanceImpl(String url, String username, - String password, String displayName, boolean withoutUI, Map initialProperties) throws InstanceCreationException { - if (instancesMap().containsKey(url)) { - throw new InstanceCreationException("already exists"); - } + private void addInstanceImpl(String url, String username, + String password, String displayName, boolean withoutUI, + Map initialProperties, boolean loadPlugins) throws InstanceCreationException { - LOGGER.log(Level.FINE, "Registering instance {0}", url); + synchronized (this) { + if (instancesMap().containsKey(url)) { + throw new InstanceCreationException("already exists"); + } - Map properties = cleanInitialProperties(initialProperties); + LOGGER.log(Level.FINE, "Registering instance {0}", url); - Collection serversMap = serversMap().values(); - for (Iterator i = serversMap.iterator(); i.hasNext();) { - Server server = (Server) i.next(); - try { - if(server.handlesUri(url)) { - ServerInstance tmp = new ServerInstance(server,url); - // PENDING persist url/password in ServerString as well - instancesMap().put(url,tmp); - // try to create a disconnected deployment manager to see - // whether the instance is not corrupted - see #46929 - writeInstanceToFile(url,username,password); - tmp.getInstanceProperties().setProperty( - InstanceProperties.REGISTERED_WITHOUT_UI, Boolean.toString(withoutUI)); - if (displayName != null) { + Map properties = cleanInitialProperties(initialProperties); + + Collection serversMap = serversMap().values(); + for (Iterator i = serversMap.iterator(); i.hasNext();) { + Server server = (Server) i.next(); + try { + if (server.handlesUri(url)) { + ServerInstance tmp = new ServerInstance(server, url); + // PENDING persist url/password in ServerString as well + instancesMap().put(url, tmp); + // try to create a disconnected deployment manager to see + // whether the instance is not corrupted - see #46929 + writeInstanceToFile(url, username, password); tmp.getInstanceProperties().setProperty( - InstanceProperties.DISPLAY_NAME_ATTR, displayName); + InstanceProperties.REGISTERED_WITHOUT_UI, Boolean.toString(withoutUI)); + if (displayName != null) { + tmp.getInstanceProperties().setProperty( + InstanceProperties.DISPLAY_NAME_ATTR, displayName); + } + + for (Map.Entry entry : properties.entrySet()) { + tmp.getInstanceProperties().setProperty(entry.getKey(), entry.getValue()); + } + + DeploymentManager manager = server.getDisconnectedDeploymentManager(url); + // FIXME this shouldn't be called in synchronized block + if (manager != null) { + fireInstanceListeners(url, true); + return; // true; + } else { + removeInstanceFromFile(url); + instancesMap().remove(url); + } } - - for (Map.Entry entry : properties.entrySet()) { - tmp.getInstanceProperties().setProperty(entry.getKey(), entry.getValue()); - } - - DeploymentManager manager = server.getDisconnectedDeploymentManager(url); - // FIXME this shouldn't be called in synchronized block - if (manager != null) { - fireInstanceListeners(url, true); - return; // true; - } else { + } catch (Exception e) { + if (instancesMap().containsKey(url)) { removeInstanceFromFile(url); instancesMap().remove(url); } + LOGGER.log(Level.INFO, null, e); } - } catch (Exception e) { - if (instancesMap().containsKey(url)) { - removeInstanceFromFile(url); - instancesMap().remove(url); - } - LOGGER.log(Level.INFO, null, e); } } - throw new InstanceCreationException(serversMap.size()+" handlers registered, no handlers for "+url); + + if (loadPlugins) { + // don't wait for FS event, try to load the plugin now + FileObject dir = FileUtil.getConfigFile(DIR_JSR88_PLUGINS); + if (dir != null) { + for (FileObject fo : dir.getChildren()) { + // if it is already registered this is noop + addPlugin(fo); + } + } + + addInstanceImpl(url, username, password, displayName, withoutUI, initialProperties, false); + return; + } + + throw new InstanceCreationException("No handlers for " + url); } private Map cleanInitialProperties(Map initialProperties) { @@ -488,7 +508,7 @@ String withoutUI = (String) fo.getAttribute(InstanceProperties.REGISTERED_WITHOUT_UI); boolean withoutUIFlag = withoutUI == null ? false : Boolean.valueOf(withoutUI); try { - addInstanceImpl(url, username, password, displayName, withoutUIFlag, null); + addInstanceImpl(url, username, password, displayName, withoutUIFlag, null, false); } catch (InstanceCreationException ice) { // yes... we are ignoring this.. because that }