Author: markt Date: Thu Jun 4 15:06:19 2009 New Revision: 781767 URL: http://svn.apache.org/viewvc?rev=781767&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=42707 Make adding a host alias via jmx take effect immediately
Modified: tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/mapper/Mapper.java tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/MapperListener.java tomcat/container/tc5.5.x/webapps/docs/changelog.xml Modified: tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/mapper/Mapper.java URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/mapper/Mapper.java?rev=781767&r1=781766&r2=781767&view=diff ============================================================================== --- tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/mapper/Mapper.java (original) +++ tomcat/connectors/trunk/util/java/org/apache/tomcat/util/http/mapper/Mapper.java Thu Jun 4 15:06:19 2009 @@ -136,6 +136,47 @@ } } + /** + * Add an alias to an existing host. + * @param name The name of the host + * @param alias The alias to add + */ + public synchronized void addHostAlias(String name, String alias) { + int pos = find(hosts, name); + if (pos < 0) { + // Should not be adding an alias for a host that doesn't exist but + // just in case... + return; + } + Host realHost = hosts[pos]; + + Host[] newHosts = new Host[hosts.length + 1]; + Host newHost = new Host(); + newHost.name = alias; + newHost.contextList = realHost.contextList; + newHost.object = realHost; + if (insertMap(hosts, newHosts, newHost)) { + hosts = newHosts; + } + } + + /** + * Remove a host alias + * @param alias The alias to remove + */ + public synchronized void removeHostAlias(String alias) { + // Find and remove the alias + int pos = find(hosts, alias); + if (pos < 0) { + return; + } + Host[] newHosts = new Host[hosts.length - 1]; + if (removeMap(hosts, newHosts, alias)) { + hosts = newHosts; + } + + } + public String[] getHosts() { String hostN[] = new String[hosts.length]; for( int i = 0; i < hosts.length; i++ ) { @@ -1025,7 +1066,7 @@ /** - * Find a map elemnt given its name in a sorted array of map elements. + * Find a map element given its name in a sorted array of map elements. * This will return the index for the closest inferior or equal item in the * given array. */ Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/MapperListener.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/MapperListener.java?rev=781767&r1=781766&r2=781767&view=diff ============================================================================== --- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/MapperListener.java (original) +++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/connector/MapperListener.java Thu Jun 4 15:06:19 2009 @@ -26,6 +26,10 @@ import javax.management.ObjectInstance; import javax.management.ObjectName; +import org.apache.catalina.ContainerEvent; +import org.apache.catalina.ContainerListener; +import org.apache.catalina.Host; +import org.apache.catalina.ServerFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,8 +47,10 @@ * @author Costin Manolache */ public class MapperListener - implements NotificationListener + implements NotificationListener, ContainerListener { + + private static Log log = LogFactory.getLog(MapperListener.class); @@ -251,6 +257,19 @@ } + // --------------------------------------------- Container Listener methods + + public void containerEvent(ContainerEvent event) { + + if (event.getType() == Host.ADD_ALIAS_EVENT) { + mapper.addHostAlias(((Host) event.getSource()).getName(), + event.getData().toString()); + } else if (event.getType() == Host.REMOVE_ALIAS_EVENT) { + mapper.removeHostAlias(event.getData().toString()); + } + } + + // ------------------------------------------------------ Protected Methods private void registerEngine() @@ -293,7 +312,7 @@ if (!isRegisteredWithAlias && log.isWarnEnabled()) log.warn(sm.getString("mapperListener.unknownDefaultHost", defaultHost)); } - // This should probablt be called later + // This should probably be called later if( defaultHost != null ) { mapper.setDefaultHostName(defaultHost); } @@ -306,13 +325,16 @@ throws Exception { String name=objectName.getKeyProperty("host"); if( name != null ) { - String[] aliases = (String[]) - mBeanServer.invoke(objectName, "findAliases", null, null); + + Host host = (Host) ServerFactory.getServer().findService( + domain).getContainer().findChild(name); + + String[] aliases = host.findAliases(); mapper.addHost(name, aliases, objectName); + host.addContainerListener(this); if(log.isDebugEnabled()) log.debug(sm.getString ("mapperListener.registerHost", name, domain)); - } } @@ -323,10 +345,16 @@ private void unregisterHost(ObjectName objectName) throws Exception { String name=objectName.getKeyProperty("host"); - mapper.removeHost(name); - if(log.isDebugEnabled()) - log.debug(sm.getString - ("mapperListener.unregisterHost", name, domain)); + if( name != null ) { + Host host = (Host) ServerFactory.getServer().findService( + domain).getContainer().findChild(name); + + mapper.removeHost(name); + host.removeContainerListener(this); + if(log.isDebugEnabled()) + log.debug(sm.getString + ("mapperListener.unregisterHost", name, domain)); + } } Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?rev=781767&r1=781766&r2=781767&view=diff ============================================================================== --- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original) +++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Thu Jun 4 15:06:19 2009 @@ -84,6 +84,10 @@ (markt) </fix> <fix> + <bug>42707</bug>: Make adding a host alias via JMX take effect + immediately. (markt) + </fix> + <fix> <bug>45576</bug>: JAAS Realm now works with DIGEST authentication. (markt) </fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org