[jboss-cvs] JBossAS SVN: r88028 - in projects/naming/trunk/jnpserver/src: test/java/org/jnp/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 29 17:39:09 EDT 2009
Author: galder.zamarreno at jboss.com
Date: 2009-04-29 17:39:09 -0400 (Wed, 29 Apr 2009)
New Revision: 88028
Added:
projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingContextUnitTest.java
Modified:
projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java
projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java
Log:
[JBNAME-27] Added -Djboss.global.jnp.disableDiscovery=[true|false] system property.
Modified: projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java 2009-04-29 21:14:59 UTC (rev 88027)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java 2009-04-29 21:39:09 UTC (rev 88028)
@@ -38,6 +38,7 @@
import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -84,6 +85,7 @@
* passed to the
* @author oberg
* @author scott.stark at jboss.org
+ * @author Galder Zamarreño
* @version $Revision$
*/
public class NamingContext
@@ -159,6 +161,34 @@
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(getSystemProperty("jboss.global.jnp.disableDiscovery", "false"));
+
+ public static String getSystemProperty(final String name, final String defaultValue)
+ {
+ String prop;
+ if (System.getSecurityManager() == null)
+ {
+ prop = System.getProperty(name, defaultValue);
+ }
+ else
+ {
+ PrivilegedAction action = new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ prop = (String) AccessController.doPrivileged(action);
+ }
+ return prop;
+ }
+
+ /**
* The default discovery multicast information
*/
public final static String DEFAULT_DISCOVERY_GROUP_ADDRESS = "230.0.0.4";
@@ -1349,6 +1379,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 +1540,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)
Added: projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingContextUnitTest.java
===================================================================
--- projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingContextUnitTest.java (rev 0)
+++ projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingContextUnitTest.java 2009-04-29 21:39:09 UTC (rev 88028)
@@ -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);
+ }
+ }
+}
Modified: projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java
===================================================================
--- projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java 2009-04-29 21:14:59 UTC (rev 88027)
+++ projects/naming/trunk/jnpserver/src/test/java/org/jnp/test/NamingTestSuite.java 2009-04-29 21:39:09 UTC (rev 88028)
@@ -47,6 +47,7 @@
suite.addTest(NamingMCUnitTest.suite());
suite.addTest(NamingServerSecurityManagerUnitTest.suite());
suite.addTest(TestJNPSockets.suite());
+ suite.addTest(NamingContextUnitTest.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list