Index: src/main/java/org/jnp/interfaces/NamingContext.java =================================================================== --- src/main/java/org/jnp/interfaces/NamingContext.java (revision 87585) +++ src/main/java/org/jnp/interfaces/NamingContext.java (working copy) @@ -84,6 +84,7 @@ * passed to the * @author oberg * @author scott.stark@jboss.org + * @author Galder ZamarreƱo * @version $Revision$ */ public class NamingContext @@ -159,6 +160,13 @@ public static final String JNP_NAMING_INSTANCE_NAME = "jnp.namingInstanceName"; /** + * Global JNP disable discovery system property: -Djboss.global.jnp.disableDiscover=[true|false] + * At the VM level, this property controls how disable discovery behaves in + * absence of per context jnp.disableDiscovery property. + */ + private static final boolean GLOBAL_JNP_DISABLE_DISCOVERY = Boolean.valueOf(System.getProperty("jboss.global.jnp.disableDiscovery", "false")); + + /** * The default discovery multicast information */ public final static String DEFAULT_DISCOVERY_GROUP_ADDRESS = "230.0.0.4"; @@ -1349,6 +1357,34 @@ } return linkResult; } + + protected boolean shouldDiscoveryHappen(boolean globalDisableDiscovery, String perCtxDisableDiscovery) + { + boolean trace = log.isTraceEnabled(); + if (!globalDisableDiscovery) + { + // No global disable, so act as before. + if (Boolean.valueOf(perCtxDisableDiscovery) == Boolean.TRUE) + { + if (trace) + log.trace("Skipping discovery due to disable flag in context"); + return false; + } + } + else + { + // Global disable on but double check whether there's a per context override. + // If disableDiscovery in context is explicitly set to false, do discovery. + if (perCtxDisableDiscovery == null || Boolean.valueOf(perCtxDisableDiscovery) == Boolean.TRUE) + { + if (trace) + log.trace("Skipping discovery due to disable flag in context, or disable flag globally (and no override in context)"); + return false; + } + } + + return true; + } // Private ------------------------------------------------------- @@ -1482,6 +1518,12 @@ boolean trace = log.isTraceEnabled(); // Check if discovery should be done String disableDiscovery = (String) serverEnv.get(JNP_DISABLE_DISCOVERY); + + if (!shouldDiscoveryHappen(GLOBAL_JNP_DISABLE_DISCOVERY, disableDiscovery)) + { + return null; + } + if (Boolean.valueOf(disableDiscovery) == Boolean.TRUE) { if (trace) Index: src/test/java/org/jnp/test/NamingContextUnitTest.java =================================================================== --- src/test/java/org/jnp/test/NamingContextUnitTest.java (revision 0) +++ src/test/java/org/jnp/test/NamingContextUnitTest.java (revision 0) @@ -0,0 +1,72 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jnp.test; + +import javax.naming.NamingException; + +import junit.framework.Test; + +import org.jboss.test.BaseTestCase; +import org.jnp.interfaces.NamingContext; + +/** + * NamingContextUnitTest. + * + * @author Galder ZamarreƱo + */ +public class NamingContextUnitTest extends BaseTestCase +{ + public NamingContextUnitTest(String name) + { + super(name); + } + + public static Test suite() + { + return suite(NamingContextUnitTest.class); + } + + public void testShouldDiscoveryHappen() throws Exception + { + PublicExposeNamingContext ctx = new PublicExposeNamingContext(); + assertTrue(ctx.shouldDiscoveryHappen(false, null)); + assertFalse(ctx.shouldDiscoveryHappen(false, "true")); + assertTrue(ctx.shouldDiscoveryHappen(false, "false")); + assertFalse(ctx.shouldDiscoveryHappen(true, null)); + assertFalse(ctx.shouldDiscoveryHappen(true, "true")); + assertTrue(ctx.shouldDiscoveryHappen(true, "false")); + } + + @SuppressWarnings("serial") + public class PublicExposeNamingContext extends NamingContext + { + public PublicExposeNamingContext() throws NamingException + { + super(null, null, null); + } + + public boolean shouldDiscoveryHappen(boolean globalDisableDiscovery, String perCtxDisableDiscovery) + { + return super.shouldDiscoveryHappen(globalDisableDiscovery, perCtxDisableDiscovery); + } + } +} Index: src/test/java/org/jnp/test/NamingTestSuite.java =================================================================== --- src/test/java/org/jnp/test/NamingTestSuite.java (revision 87585) +++ src/test/java/org/jnp/test/NamingTestSuite.java (working copy) @@ -47,6 +47,7 @@ suite.addTest(NamingMCUnitTest.suite()); suite.addTest(NamingServerSecurityManagerUnitTest.suite()); suite.addTest(TestJNPSockets.suite()); + suite.addTest(NamingContextUnitTest.suite()); return suite; }