diff -r 3e0ff569f93e glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstanceProvider.java --- a/glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstanceProvider.java Mon Nov 23 17:28:37 2009 +0100 +++ b/glassfish.common/src/org/netbeans/modules/glassfish/common/GlassfishInstanceProvider.java Mon Nov 23 20:12:53 2009 +0100 @@ -726,18 +726,6 @@ CreateDomain cd = new CreateDomain("anonymous", "", new File(f,"glassfish"), ip, this,true); // NOI18N cd.start(); } - - FileObject serverInstanceDir = FileUtil.getConfigFile("J2EE/InstalledServers"); // NOI18N - if (serverInstanceDir == null) { - FileObject root = FileUtil.getConfigRoot(); - serverInstanceDir = FileUtil.createFolder(root, "J2EE/InstalledServers"); // NOI18N - } - - if (serverInstanceDir != null) { - registerServerInstanceFO(serverInstanceDir, ip); - } else { - Logger.getLogger("glassfish-javaee").log(Level.INFO, "Cannot register the default Tomcat server. The //J2EE//InstalledServers folder cannot be found."); // NOI18N - } } } } catch (IOException ex) { @@ -747,22 +735,6 @@ } } - private static void registerServerInstanceFO(FileObject serverInstanceDir, - Map props) { - String name = FileUtil.findFreeFileName(serverInstanceDir, "gfv3_autoregistered_instance", null); // NOI18N - FileObject instanceFO; - try { - instanceFO = serverInstanceDir.createData(name); - for (Map.Entry entry : props.entrySet()) { - instanceFO.setAttribute(entry.getKey(), entry.getValue()); - } - instanceFO.setAttribute("registeredWithoutUI", "true"); // NOI18N - } catch (IOException e) { - Logger.getLogger("glassfish-javaee").log(Level.INFO, "Cannot register the default Tomcat server."); // NOI18N - Logger.getLogger("glassfish-javaee").log(Level.INFO, null, e); - } - } - String[] getNoPasswordCreatDomainCommand(String startScript, String jarLocation, String domainDir, String portBase, String uname, String domain) { List retVal = new ArrayList(); retVal.addAll(Arrays.asList(new String[] {startScript, diff -r 3e0ff569f93e j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java --- a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Mon Nov 23 17:28:37 2009 +0100 +++ b/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerRegistry.java Mon Nov 23 20:12:53 2009 +0100 @@ -62,6 +62,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import org.netbeans.modules.j2ee.deployment.config.J2eeModuleAccessor; import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; @@ -358,7 +359,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); @@ -414,57 +415,92 @@ * @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); + HandlerPluginListener listener = null; - Map properties = cleanInitialProperties(initialProperties); + synchronized (this) { + if (instancesMap().containsKey(url)) { + throw new InstanceCreationException("already exists"); + } - 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) { + LOGGER.log(Level.FINE, "Registering instance {0}", url); + + 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); + } + + if (loadPlugins) { + new Exception().printStackTrace(System.out); + listener = new HandlerPluginListener(url); + addPluginListener(listener); } } - throw new InstanceCreationException(serversMap.size()+" handlers registered, no handlers for "+url); + + if (loadPlugins) { + try { + // don't wait for FS event, try to load the plugin now + FileObject dir = FileUtil.getConfigFile(DIR_JSR88_PLUGINS); + if (dir != null && !listener.isDone()) { + for (FileObject fo : dir.getChildren()) { + if (listener.isDone()) { + break; + } + addPlugin(fo); + } + } + + if (listener.isDone()) { + addInstanceImpl(url, username, password, displayName, withoutUI, initialProperties, false); + return; + } + } finally { + removePluginListener(listener); + } + } + + throw new InstanceCreationException("No handlers for " + url); } private Map cleanInitialProperties(Map initialProperties) { @@ -488,14 +524,8 @@ String displayName = (String) fo.getAttribute(InstanceProperties.DISPLAY_NAME_ATTR); String withoutUI = (String) fo.getAttribute(InstanceProperties.REGISTERED_WITHOUT_UI); boolean withoutUIFlag = withoutUI == null ? false : Boolean.valueOf(withoutUI); - Map props = new HashMap(); - for(Enumeration e = fo.getAttributes(); e.hasMoreElements();) { - String name = e.nextElement(); - Object attr = fo.getAttribute(name); - props.put(name, attr == null ? null : attr.toString()); - } try { - addInstanceImpl(url, username, password, displayName, withoutUIFlag, props); + addInstanceImpl(url, username, password, displayName, withoutUIFlag, null, true); } catch (InstanceCreationException ice) { // yes... we are ignoring this.. because that } @@ -607,4 +637,28 @@ public static Profiler getProfiler() { return (Profiler)Lookup.getDefault().lookup(Profiler.class); } + + private class HandlerPluginListener implements PluginListener { + + private final String url; + + private volatile boolean done; + + public HandlerPluginListener(String url) { + this.url = url; + } + + public void serverAdded(Server server) { + if (server != null && server.handlesUri(url)) { + done = true; + } + } + + public void serverRemoved(Server server) { + } + + public boolean isDone() { + return done; + } + } }