JBoss Native SVN: r1819 - in trunk/mod_cluster/src: test/java/org/jboss/modcluster and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-12 18:18:06 -0400 (Fri, 12 Sep 2008)
New Revision: 1819
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
Log:
Stand-alone jbossweb lifecycle listener
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java 2008-09-12 22:18:06 UTC (rev 1819)
@@ -0,0 +1,230 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jboss.modcluster;
+
+import java.util.List;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Server;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.apache.catalina.util.StringManager;
+import org.apache.tomcat.util.IntrospectionUtils;
+import org.apache.tomcat.util.modeler.Registry;
+import org.jboss.logging.Logger;
+import org.jboss.modcluster.config.ModClusterConfig;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
+import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
+
+/**
+ * This listener communicates with a front end mod_cluster enabled proxy to
+ * automatically maintain the node configuration according to what is
+ * deployed.
+ */
+public class ClusterListener extends ModClusterConfig
+ implements LifecycleListener, ContainerListener, ResetRequestSource
+{
+ private static final Logger log = Logger.getLogger(ClusterListener.class);
+
+ /** The string manager for this package. */
+ private final StringManager sm = StringManager.getManager(Constants.Package);
+
+ // ----------------------------------------------------------------- Fields
+
+ private final LifecycleListener lifecycleListener;
+ private final ContainerListener containerListener;
+ private final MCMPHandler mcmpHandler;
+
+ // ----------------------------------------------------------- Constructors
+
+ public ClusterListener()
+ {
+ this.mcmpHandler = new DefaultMCMPHandler(this, this);
+
+ JBossWebEventHandler eventHandler = new DefaultJBossWebEventHandler(this, this, this, this.mcmpHandler, this);
+
+ BasicClusterListener listener = new BasicClusterListener(eventHandler);
+
+ this.lifecycleListener = listener;
+ this.containerListener = listener;
+ }
+
+ protected ClusterListener(MCMPHandler mcmpHandler, LifecycleListener lifecycleListener, ContainerListener containerListener)
+ {
+ this.mcmpHandler = mcmpHandler;
+ this.lifecycleListener = lifecycleListener;
+ this.containerListener = containerListener;
+ }
+
+ // ---------------------------------------------------- ResetRequestSource
+
+ /**
+ * Reset configuration for a particular proxy following an error.
+ */
+ public List<MCMPRequest> getResetRequests()
+ {
+ return MCMPUtils.getResetRequests(ServerFactory.getServer(), this, this);
+ }
+
+ //----------------------------------------------------------------- Public
+
+ /**
+ * Retrieves the full proxy configuration. To be used through JMX or similar.
+ *
+ * response: HTTP/1.1 200 OK
+ * response:
+ * node: [1:1] JVMRoute: node1 Domain: [bla] Host: 127.0.0.1 Port: 8009 Type: ajp
+ * host: 1 [] vhost: 1 node: 1
+ * context: 1 [/] vhost: 1 node: 1 status: 1
+ * context: 2 [/myapp] vhost: 1 node: 1 status: 1
+ * context: 3 [/host-manager] vhost: 1 node: 1 status: 1
+ * context: 4 [/docs] vhost: 1 node: 1 status: 1
+ * context: 5 [/manager] vhost: 1 node: 1 status: 1
+ *
+ * @return the proxy confguration
+ */
+ public String getProxyConfiguration()
+ {
+ return this.mcmpHandler.getProxyConfiguration();
+ }
+
+ /**
+ * Reset a DOWN connection to the proxy up to ERROR, where the configuration will
+ * be refreshed. To be used through JMX or similar.
+ */
+ public void reset()
+ {
+ this.mcmpHandler.reset();
+ }
+
+ /**
+ * Refresh configuration. To be used through JMX or similar.
+ */
+ public void refresh()
+ {
+ // Set as error, and the periodic event will refresh the configuration
+ this.mcmpHandler.markProxiesInError();
+ }
+
+ /**
+ * Disable all webapps for all engines. To be used through JMX or similar.
+ */
+ public boolean disable()
+ {
+ Service[] services = ServerFactory.getServer().findServices();
+ for (Service service: services)
+ {
+ Engine engine = (Engine) service.getContainer();
+ // Send DISABLE-APP * request
+ MCMPRequest request = MCMPUtils.createDisableEngineRequest(engine);
+ this.mcmpHandler.sendRequest(request);
+ }
+ return this.mcmpHandler.isProxyHealthOK();
+ }
+
+ /**
+ * Enable all webapps for all engines. To be used through JMX or similar.
+ */
+ public boolean enable()
+ {
+ Service[] services = ServerFactory.getServer().findServices();
+ for (Service service: services)
+ {
+ Engine engine = (Engine) service.getContainer();
+ // Send ENABLE-APP * request
+ MCMPRequest request = MCMPUtils.createEnableEngineRequest(engine);
+ this.mcmpHandler.sendRequest(request);
+ }
+ return this.mcmpHandler.isProxyHealthOK();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.apache.catalina.ContainerListener#containerEvent(org.apache.catalina.ContainerEvent)
+ */
+ public void containerEvent(ContainerEvent event)
+ {
+ this.containerListener.containerEvent(event);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.apache.catalina.LifecycleListener#lifecycleEvent(org.apache.catalina.LifecycleEvent)
+ */
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ this.lifecycleListener.lifecycleEvent(event);
+
+ Lifecycle source = event.getLifecycle();
+
+ if (source instanceof Server)
+ {
+ Server server = (Server) source;
+
+ // Register/unregister ClusterListener mbean on server start/stop
+ if (Lifecycle.AFTER_START_EVENT.equals(event.getType()))
+ {
+ try
+ {
+ ObjectName name = this.getObjectName(server);
+
+ Registry.getRegistry(null, null).registerComponent(this, name, null);
+ }
+ catch (Exception e)
+ {
+ log.error(this.sm.getString("modcluster.error.jmxRregister"), e);
+ }
+ }
+ else if (Lifecycle.STOP_EVENT.equals(event.getType()))
+ {
+ try
+ {
+ ObjectName name = this.getObjectName(server);
+
+ Registry.getRegistry(null, null).unregisterComponent(name);
+ }
+ catch (Exception e)
+ {
+ log.error(this.sm.getString("modcluster.error.jmxUnregister"), e);
+ }
+ }
+ }
+ }
+
+ private ObjectName getObjectName(Server server) throws MalformedObjectNameException
+ {
+ String domain = (String) IntrospectionUtils.getProperty(server, "domain");
+ return ObjectName.getInstance(domain , "type", "ClusterListener");
+ }
+}
\ No newline at end of file
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java 2008-09-12 22:18:06 UTC (rev 1819)
@@ -0,0 +1,346 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jboss.modcluster;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Server;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.apache.catalina.connector.Connector;
+import org.apache.tomcat.util.modeler.Registry;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestType;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ClusterListenerTestCase extends TestCase
+{
+ private static final LifecycleServer server = EasyMock.createStrictMock(LifecycleServer.class);
+ {
+ ServerFactory.setServer(server);
+ }
+
+ private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private final LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
+ private final ContainerListener containerListener = EasyMock.createStrictMock(ContainerListener.class);
+
+ private final ClusterListener listener = new ClusterListener(this.mcmpHandler, this.lifecycleListener, this.containerListener);
+
+ public void testGetResetRequests() throws Exception
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Connector connector = new Connector("AJP/1.3");
+
+ this.listener.setDomain("domain");
+ this.listener.setFlushPackets(true);
+ this.listener.setFlushWait(1);
+ this.listener.setPing(2);
+ this.listener.setSmax(3);
+ this.listener.setTtl(4);
+ this.listener.setNodeTimeout(5);
+ this.listener.setBalancer("S");
+ this.listener.setStickySession(false);
+ this.listener.setStickySessionRemove(true);
+ this.listener.setStickySessionForce(false);
+ this.listener.setWorkerTimeout(6);
+ this.listener.setMaxAttempts(7);
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ // create remove-all request
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
+
+ // create config request
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ EasyMock.expect(context.isStarted()).andReturn(true);
+
+ // create enable-app request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+
+ EasyMock.replay(server, service, engine, container, context, host);
+
+ List<MCMPRequest> requests = this.listener.getResetRequests();
+
+ EasyMock.verify(server, service, engine, container, context, host);
+
+ MCMPRequest request = requests.get(0);
+ Map<String, String> parameters = request.getParameters();
+
+ assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ assertTrue(request.isWildcard());
+ assertEquals(1, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+
+ request = requests.get(1);
+ parameters = request.getParameters();
+
+ assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ assertFalse(request.isWildcard());
+ assertEquals(17, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("172.0.0.1", parameters.get("Host"));
+ assertEquals("0", parameters.get("Port"));
+ assertEquals("ajp", parameters.get("Type"));
+ assertEquals("domain", parameters.get("Domain"));
+ assertEquals("On", parameters.get("flushpackets"));
+ assertEquals("1", parameters.get("flushwait"));
+ assertEquals("2", parameters.get("ping"));
+ assertEquals("3", parameters.get("smax"));
+ assertEquals("4", parameters.get("ttl"));
+ assertEquals("5", parameters.get("Timeout"));
+ assertEquals("S", parameters.get("Balancer"));
+ assertEquals("No", parameters.get("StickySession"));
+ assertEquals("Yes", parameters.get("StickySessionRemove"));
+ assertEquals("No", parameters.get("StickySessionForce"));
+ assertEquals("6", parameters.get("WaitWorker"));
+ assertEquals("7", parameters.get("Maxattempts"));
+
+ request = requests.get(2);
+ parameters = request.getParameters();
+
+ assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+ assertEquals(3, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(server, service, engine, container, context, host);
+ }
+
+ public void testGetProxyConfiguration()
+ {
+ EasyMock.expect(this.mcmpHandler.getProxyConfiguration()).andReturn("config");
+
+ EasyMock.replay(this.mcmpHandler);
+
+ String result = this.listener.getProxyConfiguration();
+
+ EasyMock.verify(this.mcmpHandler);
+
+ assertEquals("config", result);
+
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ public void testReset()
+ {
+ this.mcmpHandler.reset();
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.reset();
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ public void testRefresh()
+ {
+ this.mcmpHandler.markProxiesInError();
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.refresh();
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ public void testEnable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
+
+ EasyMock.replay(this.mcmpHandler, server, service, engine);
+
+ boolean result = this.listener.enable();
+
+ EasyMock.verify(this.mcmpHandler, server, service, engine);
+
+ assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+ Map<String, String> parameters = request.getParameters();
+
+ assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ assertTrue(request.isWildcard());
+ assertEquals(1, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+
+ EasyMock.reset(this.mcmpHandler, server, service, engine);
+ }
+
+ public void testDisable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(this.mcmpHandler.isProxyHealthOK()).andReturn(true);
+
+ EasyMock.replay(this.mcmpHandler, server, service, engine);
+
+ boolean result = this.listener.disable();
+
+ EasyMock.verify(this.mcmpHandler, server, service, engine);
+
+ assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+ Map<String, String> parameters = request.getParameters();
+
+ assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
+ assertTrue(request.isWildcard());
+ assertEquals(1, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+
+ EasyMock.reset(this.mcmpHandler, server, service, engine);
+ }
+
+ public void testContainerEvent()
+ {
+ ContainerEvent event = new ContainerEvent(EasyMock.createMock(Container.class), Container.ADD_CHILD_EVENT, null);
+
+ this.containerListener.containerEvent(event);
+
+ EasyMock.replay(this.containerListener);
+
+ this.listener.containerEvent(event);
+
+ EasyMock.verify(this.containerListener);
+ EasyMock.reset(this.containerListener);
+ }
+
+ public void testStartServerLifecycleEvent() throws MalformedObjectNameException
+ {
+ LifecycleEvent event = new LifecycleEvent(server, Lifecycle.AFTER_START_EVENT);
+
+ this.lifecycleListener.lifecycleEvent(event);
+
+ EasyMock.expect(server.getDomain()).andReturn("domain");
+
+ EasyMock.replay(this.lifecycleListener, server);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.lifecycleListener, server);
+
+ Registry registry = Registry.getRegistry(null, null);
+ ObjectName name = ObjectName.getInstance("domain:type=ClusterListener");
+
+ assertTrue(registry.getMBeanServer().isRegistered(name));
+
+ EasyMock.reset(this.lifecycleListener, server);
+ }
+
+ public void testStopServerLifecycleEvent() throws MalformedObjectNameException
+ {
+ LifecycleEvent event = new LifecycleEvent(server, Lifecycle.STOP_EVENT);
+
+ this.lifecycleListener.lifecycleEvent(event);
+
+ EasyMock.expect(server.getDomain()).andReturn("domain");
+
+ EasyMock.replay(this.lifecycleListener, server);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.lifecycleListener, server);
+
+ Registry registry = Registry.getRegistry(null, null);
+ ObjectName name = ObjectName.getInstance("domain:type=ClusterListener");
+
+ assertFalse(registry.getMBeanServer().isRegistered(name));
+
+ EasyMock.reset(this.lifecycleListener, server);
+ }
+
+ public void testOtherLifecycleEvent()
+ {
+ LifecycleEvent event = new LifecycleEvent(EasyMock.createMock(Lifecycle.class), Lifecycle.START_EVENT);
+
+ this.lifecycleListener.lifecycleEvent(event);
+
+ EasyMock.replay(this.lifecycleListener);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.lifecycleListener);
+ EasyMock.reset(this.lifecycleListener);
+ }
+
+ interface LifecycleServer extends Server, Lifecycle
+ {
+ String getDomain();
+ }
+}
17 years, 3 months
JBoss Native SVN: r1818 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/config.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-12 11:38:06 -0400 (Fri, 12 Sep 2008)
New Revision: 1818
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java
Log:
extends StaticLoadBalanceFactorProvider
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java 2008-09-12 15:37:38 UTC (rev 1817)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java 2008-09-12 15:38:06 UTC (rev 1818)
@@ -25,19 +25,17 @@
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
+import org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProvider;
+
/**
* Java bean implementing the various configuration interfaces.
*
* @author Brian Stansberry
*/
public class ModClusterConfig
- implements
- BalancerConfiguration,
- MCMPHandlerConfiguration,
- NodeConfiguration,
- SSLConfiguration
+ extends StaticLoadBalanceFactorProvider
+ implements BalancerConfiguration, MCMPHandlerConfiguration, NodeConfiguration, SSLConfiguration
{
-
// ----------------------------------------------- MCMPHandlerConfiguration
/**
@@ -293,18 +291,6 @@
public String getBalancer() { return this.balancer; }
public void setBalancer(String balancer) { this.balancer = balancer; }
- /**
- * Our load balance factor
- */
- private int loadBalanceFactor = 1;
- public int getLoadBalanceFactor() { return this.loadBalanceFactor; }
- public void setLoadBalanceFactor(int loadBalanceFactor)
- {
- assert loadBalanceFactor >= 0 : "loadBalanceFactor is negative";
- this.loadBalanceFactor = loadBalanceFactor;
- }
-
-
// ------------------------------------------------- BalancerConfiguration
/**
17 years, 3 months
JBoss Native SVN: r1817 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/config.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-12 11:37:38 -0400 (Fri, 12 Sep 2008)
New Revision: 1817
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/NodeConfiguration.java
Log:
extends LoadBalanceFactorProvider
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/NodeConfiguration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/NodeConfiguration.java 2008-09-12 15:29:24 UTC (rev 1816)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/NodeConfiguration.java 2008-09-12 15:37:38 UTC (rev 1817)
@@ -22,7 +22,9 @@
package org.jboss.modcluster.config;
-public interface NodeConfiguration
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+
+public interface NodeConfiguration extends LoadBalanceFactorProvider
{
int getSocketTimeout();
@@ -41,7 +43,4 @@
int getNodeTimeout();
String getBalancer();
-
- int getLoadBalanceFactor();
-
}
\ No newline at end of file
17 years, 3 months
JBoss Native SVN: r1816 - in trunk/mod_cluster/src: test/java/org/jboss/modcluster and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-12 11:29:24 -0400 (Fri, 12 Sep 2008)
New Revision: 1816
Added:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java
Log:
Tested.
Stand-alone JBossWeb cluster listener will decorate this class, not extend it.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java 2008-09-12 12:26:32 UTC (rev 1815)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java 2008-09-12 15:29:24 UTC (rev 1816)
@@ -32,8 +32,6 @@
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Server;
import org.apache.catalina.Service;
-import org.apache.catalina.util.StringManager;
-import org.jboss.logging.Logger;
/**
* This listener communicates with a front end mod_cluster enabled proxy to
@@ -42,24 +40,11 @@
*/
public class BasicClusterListener implements LifecycleListener, ContainerListener
{
- protected static Logger log = Logger.getLogger(BasicClusterListener.class);
+ /** Initialization flag. */
+ private volatile boolean init = false;
- /**
- * The string manager for this package.
- */
- protected StringManager sm = StringManager.getManager(Constants.Package);
+ private JBossWebEventHandler eventHandler;
- // -------------------------------------------------------------- Constants
-
- // ----------------------------------------------------------------- Fields
-
- /**
- * Initialization flag.
- */
- protected boolean init = false;
-
- protected JBossWebEventHandler eventHandler;
-
// ----------------------------------------------------------- Constructors
public BasicClusterListener(JBossWebEventHandler eventHandler)
@@ -67,10 +52,6 @@
this.eventHandler = eventHandler;
}
- protected BasicClusterListener()
- {
- }
-
// ------------------------------------------------------------- Properties
// ---------------------------------------------- LifecycleListener Methods
@@ -116,7 +97,6 @@
container.removeContainerListener(this);
}
}
-
}
/**
@@ -126,9 +106,10 @@
*/
public void lifecycleEvent(LifecycleEvent event)
{
- Object source = event.getLifecycle();
-
- if (Lifecycle.START_EVENT.equals(event.getType()))
+ Lifecycle source = event.getLifecycle();
+ String type = event.getType();
+
+ if (type.equals(Lifecycle.START_EVENT))
{
if (source instanceof Context)
{
@@ -136,18 +117,22 @@
this.eventHandler.startContext((Context) source);
}
}
- else if (Lifecycle.AFTER_START_EVENT.equals(event.getType()))
+ else if (type.equals(Lifecycle.AFTER_START_EVENT))
{
if (source instanceof Server)
{
this.eventHandler.init();
+
+ Server server = (Server) source;
+
+ this.addListeners(server);
- this.startServer((Server) source);
+ this.eventHandler.startServer(server);
this.init = true;
}
}
- else if (Lifecycle.STOP_EVENT.equals(event.getType()))
+ else if (type.equals(Lifecycle.STOP_EVENT))
{
if (source instanceof Context)
{
@@ -156,81 +141,71 @@
}
else if (source instanceof Server)
{
- this.stopServer((Server) source);
+ this.init = false;
- this.eventHandler.shutdown();
+ Server server = (Server) source;
+
+ this.removeListeners(server);
- this.init = false;
+ this.eventHandler.stopServer(server);
+
+ this.eventHandler.shutdown();
}
}
- else if (Lifecycle.PERIODIC_EVENT.equals(event.getType()))
+ else if (type.equals(Lifecycle.PERIODIC_EVENT))
{
- if (this.init && source instanceof Engine)
+ if (this.init && (source instanceof Engine))
{
this.eventHandler.status((Engine) source);
}
}
}
- /**
- * Send commands to the front end server associated with the startup of the
- * node.
- */
- protected void startServer(Server server)
+ private void addListeners(Server server)
{
// Register ourself as a listener for child services
Service[] services = server.findServices();
- for (Service service : services)
+ for (Service service: services)
{
- service.getContainer().addContainerListener(this);
-
Engine engine = (Engine) service.getContainer();
+ engine.addContainerListener(this);
((Lifecycle) engine).addLifecycleListener(this);
- Container[] children = engine.findChildren();
- for (Container element : children)
+ Container[] containers = engine.findChildren();
+ for (Container container: containers)
{
- element.addContainerListener(this);
- Container[] children2 = element.findChildren();
- for (Container element2 : children2)
+ container.addContainerListener(this);
+
+ Container[] childContainers = container.findChildren();
+ for (Container childContainer: childContainers)
{
- ((Lifecycle) element2).addLifecycleListener(this);
+ ((Lifecycle) childContainer).addLifecycleListener(this);
}
}
}
-
- this.eventHandler.startServer(server);
}
- /**
- * Send commands to the front end server associated with the shutdown of the
- * node.
- */
- protected void stopServer(Server server)
+ private void removeListeners(Server server)
{
- // Register ourself as a listener to child components
+ // Unregister ourself as a listener to child components
Service[] services = server.findServices();
- for (Service service : services)
+ for (Service service: services)
{
- service.getContainer().removeContainerListener(this);
- ((Lifecycle) service.getContainer()).removeLifecycleListener(this);
- Container[] children = service.getContainer().findChildren();
- for (Container element : children)
+ Engine engine = (Engine) service.getContainer();
+ engine.removeContainerListener(this);
+ ((Lifecycle) engine).removeLifecycleListener(this);
+
+ Container[] containers = engine.findChildren();
+ for (Container container: containers)
{
- element.removeContainerListener(this);
- Container[] children2 = element.findChildren();
- for (Container element2 : children2)
+ container.removeContainerListener(this);
+
+ Container[] childContainers = container.findChildren();
+ for (Container childContainer: childContainers)
{
- ((Lifecycle) element2).removeLifecycleListener(this);
+ ((Lifecycle) childContainer).removeLifecycleListener(this);
}
}
}
-
- this.eventHandler.stopServer(server);
}
-
- protected void setEventHandler(JBossWebEventHandler handler)
- {
- this.eventHandler = handler;
- }
}
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java 2008-09-12 15:29:24 UTC (rev 1816)
@@ -0,0 +1,261 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jboss.modcluster;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.Server;
+import org.apache.catalina.Service;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class BasicClusterListenerTestCase extends TestCase
+{
+ private JBossWebEventHandler eventHandler = EasyMock.createStrictMock(JBossWebEventHandler.class);
+
+ private BasicClusterListener listener = new BasicClusterListener(this.eventHandler);
+
+ public void testDeployWebApp()
+ {
+ Host host = EasyMock.createStrictMock(Host.class);
+ LifecycleContext context = EasyMock.createStrictMock(LifecycleContext.class);
+
+ ContainerEvent event = new ContainerEvent(host, Container.ADD_CHILD_EVENT, context);
+
+ context.addLifecycleListener(this.listener);
+ this.eventHandler.addContext(context);
+
+ EasyMock.replay(this.eventHandler, host, context);
+
+ this.listener.containerEvent(event);
+
+ EasyMock.verify(this.eventHandler, host, context);
+ EasyMock.reset(this.eventHandler, host, context);
+ }
+
+ public void testDeployHost()
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ ContainerEvent event = new ContainerEvent(engine, Container.ADD_CHILD_EVENT, null);
+
+ engine.addContainerListener(this.listener);
+
+ EasyMock.replay(engine);
+
+ this.listener.containerEvent(event);
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
+ }
+
+ public void testUndeployWebApp()
+ {
+ Host host = EasyMock.createStrictMock(Host.class);
+ LifecycleContext context = EasyMock.createStrictMock(LifecycleContext.class);
+
+ ContainerEvent event = new ContainerEvent(host, Container.REMOVE_CHILD_EVENT, context);
+
+ context.removeLifecycleListener(this.listener);
+ this.eventHandler.removeContext(context);
+
+ EasyMock.replay(this.eventHandler, host, context);
+
+ this.listener.containerEvent(event);
+
+ EasyMock.verify(this.eventHandler, host, context);
+ EasyMock.reset(this.eventHandler, host, context);
+ }
+
+ public void testUndeployHost()
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ ContainerEvent event = new ContainerEvent(engine, Container.REMOVE_CHILD_EVENT, null);
+
+ engine.removeContainerListener(this.listener);
+
+ EasyMock.replay(engine);
+
+ this.listener.containerEvent(event);
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
+ }
+
+ public void testStartWebApp()
+ {
+ LifecycleContext context = EasyMock.createStrictMock(LifecycleContext.class);
+
+ LifecycleEvent event = new LifecycleEvent(context, Lifecycle.START_EVENT);
+
+ this.eventHandler.startContext(context);
+
+ EasyMock.replay(this.eventHandler);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler);
+ EasyMock.reset(this.eventHandler);
+ }
+
+ public void testStartServer()
+ {
+ LifecycleServer server = EasyMock.createStrictMock(LifecycleServer.class);
+ Service service = EasyMock.createStrictMock(Service.class);
+ LifecycleEngine engine = EasyMock.createStrictMock(LifecycleEngine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ LifecycleContainer childContainer = EasyMock.createStrictMock(LifecycleContainer.class);
+
+ LifecycleEvent event = new LifecycleEvent(server, Lifecycle.AFTER_START_EVENT);
+
+ this.eventHandler.init();
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ engine.addContainerListener(this.listener);
+ engine.addLifecycleListener(this.listener);
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+
+ container.addContainerListener(this.listener);
+
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { childContainer });
+
+ childContainer.addLifecycleListener(this.listener);
+
+ this.eventHandler.startServer(server);
+
+ EasyMock.replay(this.eventHandler, server, service, engine, container, childContainer);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler, server, service, engine, container, childContainer);
+ EasyMock.reset(this.eventHandler, server, service, engine, container, childContainer);
+ }
+
+ public void testStopWebApp()
+ {
+ LifecycleContext context = EasyMock.createStrictMock(LifecycleContext.class);
+
+ LifecycleEvent event = new LifecycleEvent(context, Lifecycle.STOP_EVENT);
+
+ this.eventHandler.stopContext(context);
+
+ EasyMock.replay(this.eventHandler);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler);
+ EasyMock.reset(this.eventHandler);
+ }
+
+ public void testStopServer()
+ {
+ LifecycleServer server = EasyMock.createStrictMock(LifecycleServer.class);
+ Service service = EasyMock.createStrictMock(Service.class);
+ LifecycleEngine engine = EasyMock.createStrictMock(LifecycleEngine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ LifecycleContainer childContainer = EasyMock.createStrictMock(LifecycleContainer.class);
+
+ LifecycleEvent event = new LifecycleEvent(server, Lifecycle.STOP_EVENT);
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ engine.removeContainerListener(this.listener);
+ engine.removeLifecycleListener(this.listener);
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+
+ container.removeContainerListener(this.listener);
+
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { childContainer });
+
+ childContainer.removeLifecycleListener(this.listener);
+
+ this.eventHandler.stopServer(server);
+ this.eventHandler.shutdown();
+
+ EasyMock.replay(this.eventHandler, server, service, engine, container, childContainer);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler, server, service, engine, container, childContainer);
+ EasyMock.reset(this.eventHandler, server, service, engine, container, childContainer);
+ }
+
+ public void testPeriodicEvent()
+ {
+ LifecycleEngine engine = EasyMock.createStrictMock(LifecycleEngine.class);
+
+ LifecycleEvent event = new LifecycleEvent(engine, Lifecycle.PERIODIC_EVENT);
+
+ // Test uninitialized
+ EasyMock.replay(this.eventHandler);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler);
+ EasyMock.reset(this.eventHandler);
+
+ // Init
+ this.testStartServer();
+
+ // Test initialized
+ this.eventHandler.status(engine);
+
+ EasyMock.replay(this.eventHandler);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler);
+ EasyMock.reset(this.eventHandler);
+ }
+
+ interface LifecycleContext extends Lifecycle, Context
+ {
+ }
+
+ interface LifecycleServer extends Lifecycle, Server
+ {
+ }
+
+ interface LifecycleEngine extends Lifecycle, Engine
+ {
+ }
+
+ interface LifecycleContainer extends Lifecycle, Container
+ {
+ }
+}
17 years, 3 months
JBoss Native SVN: r1815 - trunk/mod_cluster/test/java/org/jboss/mod_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-09-12 08:26:32 -0400 (Fri, 12 Sep 2008)
New Revision: 1815
Added:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java
Modified:
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java
Log:
Arrange JBWEB_117 test. Special chunked stuff...
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-09-11 17:39:06 UTC (rev 1814)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-09-12 12:26:32 UTC (rev 1815)
@@ -127,9 +127,17 @@
HttpMethodBase bm = null;
if (fd != null) {
pm = new PostMethod(URL);
- pm.setRequestBody(fd);
+ // InputStreamRequestEntity buf = new InputStreamRequestEntity(fd);
+ // XXX: Ugly hack to test...
+ byte [] buffet = new byte[6144];
+ for (int i=0; i<buffet.length;i++)
+ buffet[i] = 'a';
+ ByteArrayRequestEntity buf = new ByteArrayRequestEntity(buffet);
+ pm.setRequestEntity(buf);
+ // pm.setRequestBody(fd);
pm.setHttp11(true);
- pm.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
+ pm.setContentChunked(true);
+ // pm.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
bm = pm;
} else if (post != null) {
pm = new PostMethod(URL);
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java (rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/ClientBasicAuthen.java 2008-09-12 12:26:32 UTC (rev 1815)
@@ -0,0 +1,155 @@
+/*
+ * mod_cluster
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision$
+ */
+
+package org.jboss.mod_cluster;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.ByteArrayInputStream;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardServer;
+
+import org.jboss.web.cluster.ClusterListener;
+
+import org.apache.catalina.core.AprLifecycleListener;
+
+public class ClientBasicAuthen {
+
+ /* Tests for Basic Authentication needs (JBWEB-117.war) */
+ public static String test(boolean nat, File fd) {
+ InputStream in = null;
+ if (fd != null)
+ try {
+ in = new FileInputStream(fd);
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ return("can't start service");
+ }
+ return test(nat, in);
+ }
+ public static String test(boolean nat, InputStream fd) {
+
+ boolean clienterror = false;
+ StandardServer server = Maintest.getServer();
+ JBossWeb service = null;
+ ClusterListener cluster = null;
+ try {
+ // server = (StandardServer) ServerFactory.getServer();
+
+ service = new JBossWeb("node1", "localhost", nat);
+ if (nat)
+ service.addConnector(8009, "org.apache.coyote.ajp.AjpAprProtocol");
+ else
+ service.addConnector(8009, "ajp");
+
+ service.addWAR("JBWEB-117.war", "node1");
+ server.addService(service);
+
+ cluster = new ClusterListener();
+ cluster.setAdvertiseGroupAddress("232.0.0.2");
+ cluster.setAdvertisePort(23364);
+ cluster.setSsl(false);
+ // SSL ?
+ server.addLifecycleListener((LifecycleListener) cluster);
+
+ // Add AprLifecycleListener.
+ if (nat) {
+ AprLifecycleListener listener = new AprLifecycleListener();
+ server.addLifecycleListener((LifecycleListener) listener);
+ }
+
+ // Debug Stuff
+ Maintest.listServices();
+
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ return("can't start service");
+ }
+
+ // start the server thread.
+ ServerThread wait = new ServerThread(3000, server);
+ wait.start();
+
+ // Wait until httpd as received the nodes information.
+ try {
+ Thread.sleep(40000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+
+ // Start the client and wait for it.
+ Client client = new Client();
+
+ // Wait for it.
+ String data = "a";
+ for (int i=0; i<517; i++)
+ data = data.concat("a");
+ int ret = 0;
+ try {
+ ret = client.runit("http://localhost:7779/JBWEB-117/JBWEB_117", 1, true, data, "manager" , "manager", fd);
+ client.start();
+ client.join();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ clienterror = true;
+ }
+
+ // Stop the jboss and remove the services.
+ try {
+ wait.stopit();
+ wait.join();
+
+ server.removeService(service);
+ server.removeLifecycleListener(cluster);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ return("can't stop service");
+ }
+ if (clienterror)
+ return("Client error");
+
+ if (ret != 401)
+ return("Should get 401 code");
+
+ // Wait until httpd as received the stop messages.
+ System.gc();
+ try {
+ Thread.sleep(20000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+}
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java 2008-09-11 17:39:06 UTC (rev 1814)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java 2008-09-12 12:26:32 UTC (rev 1815)
@@ -51,109 +51,8 @@
/* Test for JBWEB-117 */
public void testJBWEB_117() {
- testJBWEB_117(false, (File) null);
+ String result = ClientBasicAuthen.test(false, (File) null);
+ if (result != null)
+ fail(result);
}
- public void testJBWEB_117(boolean nat, File fd) {
- InputStream in = null;
- if (fd != null)
- try {
- in = new FileInputStream(fd);
- } catch(IOException ex) {
- ex.printStackTrace();
- fail("can't start service");
- }
- testJBWEB_117(nat, in);
- }
- public void testJBWEB_117(boolean nat, InputStream fd) {
-
- boolean clienterror = false;
- StandardServer server = Maintest.getServer();
- JBossWeb service = null;
- ClusterListener cluster = null;
- try {
- // server = (StandardServer) ServerFactory.getServer();
-
- service = new JBossWeb("node1", "localhost", nat);
- if (nat)
- service.addConnector(8009, "org.apache.coyote.ajp.AjpAprProtocol");
- else
- service.addConnector(8009, "ajp");
-
- service.addWAR("JBWEB-117.war", "node1");
- server.addService(service);
-
- cluster = new ClusterListener();
- cluster.setAdvertiseGroupAddress("232.0.0.2");
- cluster.setAdvertisePort(23364);
- cluster.setSsl(false);
- // SSL ?
- server.addLifecycleListener((LifecycleListener) cluster);
-
- // Add AprLifecycleListener.
- if (nat) {
- AprLifecycleListener listener = new AprLifecycleListener();
- server.addLifecycleListener((LifecycleListener) listener);
- }
-
- // Debug Stuff
- Maintest.listServices();
-
- } catch(IOException ex) {
- ex.printStackTrace();
- fail("can't start service");
- }
-
- // start the server thread.
- ServerThread wait = new ServerThread(3000, server);
- wait.start();
-
- // Wait until httpd as received the nodes information.
- try {
- Thread.sleep(40000);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
-
- // Start the client and wait for it.
- Client client = new Client();
-
- // Wait for it.
- String data = "a";
- for (int i=0; i<517; i++)
- data = data.concat("a");
- int ret = 0;
- try {
- ret = client.runit("http://localhost:7779/JBWEB-117/JBWEB_117", 1, true, data, "manager" , "manager", fd);
- client.start();
- client.join();
- } catch (Exception ex) {
- ex.printStackTrace();
- clienterror = true;
- }
-
- // Stop the jboss and remove the services.
- try {
- wait.stopit();
- wait.join();
-
- server.removeService(service);
- server.removeLifecycleListener(cluster);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- fail("can't stop service");
- }
- if (clienterror)
- fail("Client error");
-
- if (ret != 401)
- fail("Should get 401 code");
-
- // Wait until httpd as received the stop messages.
- System.gc();
- try {
- Thread.sleep(20000);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- }
}
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java 2008-09-11 17:39:06 UTC (rev 1814)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java 2008-09-12 12:26:32 UTC (rev 1815)
@@ -46,7 +46,7 @@
import org.apache.catalina.core.AprLifecycleListener;
-public class Test_Chunk_JBWEB_117 extends TestJBWEB_117 {
+public class Test_Chunk_JBWEB_117 extends TestCase {
/* Test for JBWEB-117 */
public void test_Chunk_JBWEB_117() {
@@ -54,6 +54,8 @@
for (int i=0; i<buf.length;i++)
buf[i] = 'a';
ByteArrayInputStream fd = new ByteArrayInputStream(buf);
- super.testJBWEB_117(false, fd);
+ String result = ClientBasicAuthen.test(false, fd);
+ if (result != null)
+ fail(result);
}
}
17 years, 3 months
JBoss Native SVN: r1814 - trunk/mod_cluster/src/main/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-11 13:39:06 -0400 (Thu, 11 Sep 2008)
New Revision: 1814
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
Log:
init needs to be volatile
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-11 17:37:33 UTC (rev 1813)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-11 17:39:06 UTC (rev 1814)
@@ -66,7 +66,7 @@
private final LoadBalanceFactorProvider loadBalanceFactorProvider;
private final AdvertiseListenerFactory listenerFactory;
- private boolean init;
+ private volatile boolean init;
private AdvertiseListener advertiseListener;
@@ -119,9 +119,23 @@
public synchronized void shutdown()
{
- this.stopListener();
- this.mcmpHandler.shutdown();
this.init = false;
+
+ if (this.advertiseListener != null)
+ {
+ try
+ {
+ this.advertiseListener.destroy();
+ }
+ catch (IOException e)
+ {
+ log.error(this.sm.getString("modcluster.error.stopListener"), e);
+ }
+
+ this.advertiseListener = null;
+ }
+
+ this.mcmpHandler.shutdown();
}
/**
@@ -288,23 +302,4 @@
throw new IllegalStateException(this.sm.getString("modcluster.error.uninitialized"));
}
}
-
- /**
- * Stop the advertise listener.
- */
- private void stopListener()
- {
- if (this.advertiseListener != null)
- {
- try
- {
- this.advertiseListener.destroy();
- }
- catch (IOException e)
- {
- log.error(this.sm.getString("modcluster.error.stopListener"), e);
- }
- this.advertiseListener = null;
- }
- }
}
17 years, 3 months
JBoss Native SVN: r1813 - trunk/mod_cluster/src/main/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-11 13:37:33 -0400 (Thu, 11 Sep 2008)
New Revision: 1813
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
Log:
Code cleanup.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-11 17:37:04 UTC (rev 1812)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-11 17:37:33 UTC (rev 1813)
@@ -553,7 +553,7 @@
ModClusterServiceDRMEntry removed = nonresponsive.remove(cn);
if (removed != null)
{
- Integer lbf = new Integer(mcssgrr.getLoadBalanceFactor());
+ Integer lbf = Integer.valueOf(mcssgrr.getLoadBalanceFactor());
for (String jvmRoute: removed.getJvmRoutes())
{
loadBalanceFactors.put(jvmRoute, lbf);
@@ -589,7 +589,7 @@
}
// Add error-state objects for non-responsive peers
- Integer lbf = new Integer(0);
+ Integer lbf = Integer.valueOf(0);
for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry: nonresponsive.entrySet())
{
ClusterNode cn = entry.getKey();
17 years, 3 months
JBoss Native SVN: r1812 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-11 13:37:04 -0400 (Thu, 11 Sep 2008)
New Revision: 1812
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ModClusterServiceDRMEntry.java
Log:
Code cleanup.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ModClusterServiceDRMEntry.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ModClusterServiceDRMEntry.java 2008-09-11 17:36:43 UTC (rev 1811)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ModClusterServiceDRMEntry.java 2008-09-11 17:37:04 UTC (rev 1812)
@@ -81,10 +81,10 @@
}
}
- this.establishedCount = new Integer(knownEstablished);
- this.healthyCount = new Integer(healthy);
- this.healthyEstablishedCount = new Integer(healthyEstablished);
- this.knownCount = new Integer(known);
+ this.establishedCount = Integer.valueOf(knownEstablished);
+ this.healthyCount = Integer.valueOf(healthy);
+ this.healthyEstablishedCount = Integer.valueOf(healthyEstablished);
+ this.knownCount = Integer.valueOf(known);
}
public ClusterNode getPeer()
17 years, 3 months
JBoss Native SVN: r1811 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-11 13:36:43 -0400 (Thu, 11 Sep 2008)
New Revision: 1811
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
Log:
RpcStub can be static
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-09-11 17:36:09 UTC (rev 1810)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-09-11 17:36:43 UTC (rev 1811)
@@ -139,7 +139,7 @@
}
}
- private class RpcStub implements ResetRequestSourceRpcHandler<List<?>>
+ private static class RpcStub implements ResetRequestSourceRpcHandler<List<?>>
{
private final HAServiceKeyProvider serviceKeyProvider;
17 years, 3 months
JBoss Native SVN: r1810 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-11 13:36:09 -0400 (Thu, 11 Sep 2008)
New Revision: 1810
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
Log:
Label as thread safe
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2008-09-11 17:34:32 UTC (rev 1809)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2008-09-11 17:36:09 UTC (rev 1810)
@@ -31,18 +31,12 @@
import java.util.concurrent.atomic.AtomicInteger;
import net.jcip.annotations.GuardedBy;
+import net.jcip.annotations.ThreadSafe;
import org.apache.catalina.util.StringManager;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.logging.Logger;
-import org.jboss.modcluster.config.MCMPHandlerConfiguration;
-import org.jboss.modcluster.mcmp.AbstractMCMPHandler;
-import org.jboss.modcluster.mcmp.AddressPort;
-import org.jboss.modcluster.mcmp.MCMPHandler;
-import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPServer;
-import org.jboss.modcluster.mcmp.MCMPServerState;
import org.jboss.modcluster.Constants;
import org.jboss.modcluster.Utils;
import org.jboss.modcluster.ha.rpc.BooleanGroupRpcResponse;
@@ -52,7 +46,14 @@
import org.jboss.modcluster.ha.rpc.MCMPServerDiscoveryEvent;
import org.jboss.modcluster.ha.rpc.StringGroupRpcResponse;
import org.jboss.modcluster.ha.rpc.ThrowableGroupRpcResponse;
+import org.jboss.modcluster.mcmp.AbstractMCMPHandler;
+import org.jboss.modcluster.mcmp.AddressPort;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPServer;
+import org.jboss.modcluster.mcmp.MCMPServerState;
+@ThreadSafe
public class ClusteredMCMPHandlerImpl extends AbstractMCMPHandler implements ClusteredMCMPHandler
{
static final Object[] NULL_ARGS = new Object[0];
@@ -67,7 +68,6 @@
private final MCMPHandler localHandler;
private final HASingletonMBean singleton;
private final ClusteredMCMPHandlerRpcHandler rpcStub = new RpcStub();
-// private AdvertiseListener advertiseListener;
private volatile String haServiceName;
@@ -422,7 +422,7 @@
{
// Just log it; we'll retry later
String msg = addition ? "modcluster.error.discovery.add" : "modcluster.error.discovery.remove";
- log.error(this.sm.getString(msg, address, new Integer(port)), ((ThrowableGroupRpcResponse) response).getValue());
+ log.error(this.sm.getString(msg, address, Integer.valueOf(port)), ((ThrowableGroupRpcResponse) response).getValue());
}
}
@@ -430,7 +430,7 @@
{
synchronized (this.errorState)
{
- if (this.errorState.size() == 0 || this.errorState.get(this.errorState.size() -1).booleanValue())
+ if (this.errorState.size() == 0 || this.errorState.get(this.errorState.size() - 1).booleanValue())
{
this.errorState.add(Boolean.FALSE);
}
17 years, 3 months