JBoss Native SVN: r2090 - trunk/mod_cluster/src/main/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 16:33:48 -0500 (Tue, 02 Dec 2008)
New Revision: 2090
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
Log:
javadoc
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java 2008-12-02 21:05:52 UTC (rev 2089)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java 2008-12-02 21:33:48 UTC (rev 2090)
@@ -35,7 +35,7 @@
import org.jboss.modcluster.mcmp.impl.ResetRequestSourceImpl;
/**
- * Abstract non-clustered mod_cluster listener
+ * Abstract non-clustered mod_cluster lifecycle listener
* @author Paul Ferraro
*/
public abstract class AbstractModClusterService extends ModClusterConfig
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java 2008-12-02 21:05:52 UTC (rev 2089)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java 2008-12-02 21:33:48 UTC (rev 2090)
@@ -43,8 +43,8 @@
import org.jboss.modcluster.mcmp.MCMPHandler;
/**
+ * Non-clustered mod_cluster lifecycle listener for use in JBoss Web standalone.
* @author Paul Ferraro
- *
*/
public class ModClusterListener extends AbstractModClusterService
implements LoadConfiguration
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-12-02 21:05:52 UTC (rev 2089)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-12-02 21:33:48 UTC (rev 2090)
@@ -26,8 +26,8 @@
import org.jboss.modcluster.mcmp.MCMPHandler;
/**
+ * Non-clustered mod_cluster lifecycle listener for use in JBoss AS.
* @author Paul Ferraro
- *
*/
public class ModClusterService extends AbstractModClusterService
{
16 years
JBoss Native SVN: r2089 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 16:05:52 -0500 (Tue, 02 Dec 2008)
New Revision: 2089
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Cleanup
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-12-02 20:56:39 UTC (rev 2088)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-12-02 21:05:52 UTC (rev 2089)
@@ -746,25 +746,25 @@
}
}
- private String sendRequest(Writer writer, BufferedReader reader, MCMPURLEncoder encoder, StringBuilder builder) throws IOException
+ private String sendRequest(Proxy proxy, String request, char[] body, int length) throws IOException
{
- writer.write(builder.toString());
+ Writer writer = proxy.getConnectionWriter();
+
+ writer.write(request);
writer.write("\r\n");
- int length = encoder.getLength();
-
writer.write("Content-Length: " + length + "\r\n");
writer.write("User-Agent: ClusterListener/1.0\r\n");
writer.write("Connection: Keep-Alive\r\n");
writer.write("\r\n");
- writer.write(encoder.getBuffer(), 0, length);
+ writer.write(body, 0, length);
writer.write("\r\n");
writer.flush();
// Read the first response line and skip the rest of the HTTP header
- return reader.readLine();
+ return proxy.getConnectionReader().readLine();
}
-
+
private String sendRequest(MCMPRequest request, Proxy proxy)
{
// If there was an error, do nothing until the next periodic event, where the whole configuration
@@ -812,9 +812,6 @@
try
{
// Then, connect to the proxy
- Writer writer = proxy.getConnectionWriter();
- BufferedReader reader = proxy.getConnectionReader();
-
// Generate and write request
StringBuilder builder = new StringBuilder();
@@ -839,20 +836,28 @@
builder.append(" HTTP/1.0");
+ String head = builder.toString();
+ int length = encoder.getLength();
+ char[] body = encoder.getBuffer();
+
String line = null;
- try {
- line = sendRequest(writer, reader, encoder, builder);
+ try
+ {
+ line = sendRequest(proxy, head, body, length);
}
- catch (IOException e) {
+ catch (IOException e)
+ {
+ // Ignore first write failure
}
- /* Retry once if it fails */
- if (line == null) {
- // Get a new connection; if it fails this second time, it is an error
+
+ if (line == null)
+ {
+ // Retry failed read/write with fresh connection
proxy.closeConnection();
- writer = proxy.getConnectionWriter();
- reader = proxy.getConnectionReader();
- line = sendRequest(writer, reader, encoder, builder);
+ line = sendRequest(proxy, head, body, length);
}
+
+ BufferedReader reader = proxy.getConnectionReader();
// Parse the line, which is formed like HTTP/1.x YYY Message
int status = 500;
// String version = "0";
@@ -867,14 +872,14 @@
String responseStatus = line.substring(spaceIndex + 1, line.indexOf(' ', spaceIndex + 1));
status = Integer.parseInt(responseStatus);
line = reader.readLine();
- while (line.length() > 0)
+ while ((line != null) && (line.length() > 0))
{
int colon = line.indexOf(':');
String headerName = line.substring(0, colon).trim();
String headerValue = line.substring(colon + 1).trim();
if ("version".equalsIgnoreCase(headerName))
{
-// version = headerValue;
+// version = headerValue;
}
else if ("type".equalsIgnoreCase(headerName))
{
16 years
JBoss Native SVN: r2088 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/config and 7 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 15:56:39 -0500 (Tue, 02 Dec 2008)
New Revision: 2088
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadConfiguration.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAConfiguration.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAModClusterConfig.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterServiceMBean.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadBalanceFactorProviderConfiguration.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadMetricConfiguration.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/NodeConfiguration.java
trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/META-INF/jboss-beans.xml
trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/server.xml
Log:
Refactored JBoss Web integration points.
Allow standalone ModClusterListener to define a single load metric.
Separate ha config, from non-ha config.
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/AbstractModClusterService.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,159 @@
+/*
+ * 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.Engine;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.jboss.modcluster.config.ModClusterConfig;
+import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
+import org.jboss.modcluster.mcmp.impl.ResetRequestSourceImpl;
+
+/**
+ * Abstract non-clustered mod_cluster listener
+ * @author Paul Ferraro
+ */
+public abstract class AbstractModClusterService extends ModClusterConfig
+ implements LifecycleListener, LoadBalanceFactorProviderFactory, ModClusterServiceMBean
+{
+ private final MCMPHandler mcmpHandler;
+ private final LifecycleListener lifecycleListener;
+
+ public AbstractModClusterService()
+ {
+ this.mcmpHandler = new DefaultMCMPHandler(this, new ResetRequestSourceImpl(this, this));
+
+ JBossWebEventHandler eventHandler = new DefaultJBossWebEventHandler(this, this, this, this.mcmpHandler, this);
+
+ this.lifecycleListener = new JBossWebEventHandlerAdapter(eventHandler);
+ }
+
+ protected AbstractModClusterService(MCMPHandler mcmpHandler, LifecycleListener lifecycleListener)
+ {
+ this.mcmpHandler = mcmpHandler;
+ this.lifecycleListener = lifecycleListener;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.apache.catalina.LifecycleListener#lifecycleEvent(org.apache.catalina.LifecycleEvent)
+ */
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ this.lifecycleListener.lifecycleEvent(event);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#addProxy(java.lang.String, int)
+ */
+ public void addProxy(String host, int port)
+ {
+ this.mcmpHandler.addProxy(host, port);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#removeProxy(java.lang.String, int)
+ */
+ public void removeProxy(String host, int port)
+ {
+ this.mcmpHandler.removeProxy(host, port);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#getProxyConfiguration()
+ */
+ public String getProxyConfiguration()
+ {
+ return this.mcmpHandler.getProxyConfiguration();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#getProxyInfo()
+ */
+ public String getProxyInfo()
+ {
+ return this.mcmpHandler.getProxyInfo();
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#refresh()
+ */
+ public void refresh()
+ {
+ // Set as error, and the periodic event will refresh the configuration
+ this.mcmpHandler.markProxiesInError();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#disable()
+ */
+ public boolean disable()
+ {
+ for (Service service: ServerFactory.getServer().findServices())
+ {
+ Engine engine = (Engine) service.getContainer();
+ // Send DISABLE-APP * request
+ MCMPRequest request = MCMPUtils.createDisableEngineRequest(engine);
+ this.mcmpHandler.sendRequest(request);
+ }
+
+ return this.mcmpHandler.isProxyHealthOK();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#enable()
+ */
+ public boolean enable()
+ {
+ for (Service service: ServerFactory.getServer().findServices())
+ {
+ Engine engine = (Engine) service.getContainer();
+ // Send ENABLE-APP * request
+ MCMPRequest request = MCMPUtils.createEnableEngineRequest(engine);
+ this.mcmpHandler.sendRequest(request);
+ }
+
+ return this.mcmpHandler.isProxyHealthOK();
+ }
+}
\ No newline at end of file
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,211 +0,0 @@
-/*
- * 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 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.Service;
-
-/**
- * This listener communicates with a front end mod_cluster enabled proxy to
- * automatically maintain the node configuration according to what is
- * deployed.
- */
-public class BasicClusterListener implements LifecycleListener, ContainerListener
-{
- /** Initialization flag. */
- private volatile boolean init = false;
-
- private JBossWebEventHandler eventHandler;
-
- // ----------------------------------------------------------- Constructors
-
- public BasicClusterListener(JBossWebEventHandler eventHandler)
- {
- this.eventHandler = eventHandler;
- }
-
- // ------------------------------------------------------------- Properties
-
- // ---------------------------------------------- LifecycleListener Methods
-
- /**
- * Acknowledge the occurrence of the specified event.
- * Note: Will never be called when the listener is associated to a Server,
- * since it is not a Container.
- *
- * @param event ContainerEvent that has occurred
- */
- public void containerEvent(ContainerEvent event)
- {
- Container container = event.getContainer();
- Object child = event.getData();
- String type = event.getType();
-
- if (type.equals(Container.ADD_CHILD_EVENT))
- {
- if (container instanceof Host)
- {
- // Deploying a webapp
- ((Lifecycle) child).addLifecycleListener(this);
- this.eventHandler.addContext((Context) child);
- }
- else if (container instanceof Engine)
- {
- // Deploying a host
- container.addContainerListener(this);
- }
- }
- else if (type.equals(Container.REMOVE_CHILD_EVENT))
- {
- if (container instanceof Host)
- {
- // Undeploying a webapp
- ((Lifecycle) child).removeLifecycleListener(this);
- this.eventHandler.removeContext((Context) child);
- }
- else if (container instanceof Engine)
- {
- // Undeploying a host
- container.removeContainerListener(this);
- }
- }
- }
-
- /**
- * Primary entry point for startup and shutdown events.
- *
- * @param event The event that has occurred
- */
- public void lifecycleEvent(LifecycleEvent event)
- {
- Lifecycle source = event.getLifecycle();
- String type = event.getType();
-
- if (type.equals(Lifecycle.START_EVENT))
- {
- if (source instanceof Context)
- {
- // Start a webapp
- this.eventHandler.startContext((Context) source);
- }
- }
- else if (type.equals(Lifecycle.AFTER_START_EVENT))
- {
- if (source instanceof Server)
- {
- this.eventHandler.init();
-
- Server server = (Server) source;
-
- this.addListeners(server);
-
- this.eventHandler.startServer(server);
-
- this.init = true;
- }
- }
- else if (type.equals(Lifecycle.STOP_EVENT))
- {
- if (source instanceof Context)
- {
- // Stop a webapp
- this.eventHandler.stopContext((Context) source);
- }
- else if (source instanceof Server)
- {
- this.init = false;
-
- Server server = (Server) source;
-
- this.removeListeners(server);
-
- this.eventHandler.stopServer(server);
-
- this.eventHandler.shutdown();
- }
- }
- else if (type.equals(Lifecycle.PERIODIC_EVENT))
- {
- if (this.init && (source instanceof Engine))
- {
- this.eventHandler.status((Engine) source);
- }
- }
- }
-
- private void addListeners(Server server)
- {
- // Register ourself as a listener for child services
- Service[] services = server.findServices();
- for (Service service: services)
- {
- Engine engine = (Engine) service.getContainer();
- engine.addContainerListener(this);
- ((Lifecycle) engine).addLifecycleListener(this);
-
- Container[] containers = engine.findChildren();
- for (Container container: containers)
- {
- container.addContainerListener(this);
-
- Container[] childContainers = container.findChildren();
- for (Container childContainer: childContainers)
- {
- ((Lifecycle) childContainer).addLifecycleListener(this);
- }
- }
- }
- }
-
- private void removeListeners(Server server)
- {
- // Unregister ourself as a listener to child components
- Service[] services = server.findServices();
- for (Service service: services)
- {
- Engine engine = (Engine) service.getContainer();
- engine.removeContainerListener(this);
- ((Lifecycle) engine).removeLifecycleListener(this);
-
- Container[] containers = engine.findChildren();
- for (Container container: containers)
- {
- container.removeContainerListener(this);
-
- Container[] childContainers = container.findChildren();
- for (Container childContainer: childContainers)
- {
- ((Lifecycle) childContainer).removeLifecycleListener(this);
- }
- }
- }
- }
-}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,256 +0,0 @@
-/*
- * 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 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.load.LoadBalanceFactorProvider;
-import org.jboss.modcluster.mcmp.MCMPHandler;
-import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPUtils;
-import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
-import org.jboss.modcluster.mcmp.impl.ResetRequestSourceImpl;
-
-/**
- * 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
-{
- static
- {
- // We expect to run in a JBoss Web/Tomcat environment where
- // server logging is done via java.util.logging. So, try to
- // initialize JBoss Logging to use the JDK logging plugin.
- // But only if it isn't already initialized to something else!
- if (Logger.getPluginClassName() == null)
- {
- String pluginClass = "org.jboss.logging.jdk.JDK14LoggerPlugin";
- try
- {
- ClusterListener.class.getClassLoader().loadClass(pluginClass);
- // We can load it, so let's use it
- Logger.setPluginClassName(pluginClass);
- }
- catch (Throwable t)
- {
- // Cannot load JDK14LoggerPlugin; just fall through to defaults
- }
- }
- }
- 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(null);
- }
-
- public ClusterListener(LoadBalanceFactorProvider loadBalanceFactorProvider)
- {
- this.mcmpHandler = new DefaultMCMPHandler(this, new ResetRequestSourceImpl(this, this));
-
- JBossWebEventHandler eventHandler = new DefaultJBossWebEventHandler(this, this, this, this.mcmpHandler, (loadBalanceFactorProvider != null) ? loadBalanceFactorProvider : 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;
- }
-
- //----------------------------------------------------------------- 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();
- }
-
- /**
- * Retrieves the full proxy info message.
- *
- *
- * @return the proxy info confguration
- */
- public String getProxyInfo()
- {
- return this.mcmpHandler.getProxyInfo();
- }
-
- /**
- * 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");
- }
-}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -39,6 +39,7 @@
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
import org.jboss.modcluster.mcmp.AddressPort;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
@@ -64,8 +65,10 @@
private final MCMPHandlerConfiguration mcmpConfig;
private final MCMPHandler mcmpHandler;
private final AdvertiseListenerFactory listenerFactory;
- private final LoadBalanceFactorProvider loadBalanceFactorProvider;
+ private final LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory;
+ private LoadBalanceFactorProvider loadBalanceFactorProvider;
+
private volatile boolean init;
private AdvertiseListener advertiseListener;
@@ -73,20 +76,20 @@
// ----------------------------------------------------------- Constructors
public DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider)
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory)
{
- this(nodeConfig, balancerConfig, mcmpConfig, mcmpHandler, loadBalanceFactorProvider, new AdvertiseListenerFactoryImpl());
+ this(nodeConfig, balancerConfig, mcmpConfig, mcmpHandler, loadBalanceFactorProviderFactory, new AdvertiseListenerFactoryImpl());
}
protected DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider,
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler mcmpHandler, LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory,
AdvertiseListenerFactory listenerFactory)
{
this.nodeConfig = nodeConfig;
this.balancerConfig = balancerConfig;
this.mcmpConfig = mcmpConfig;
this.mcmpHandler = mcmpHandler;
- this.loadBalanceFactorProvider = loadBalanceFactorProvider;
+ this.loadBalanceFactorProviderFactory = loadBalanceFactorProviderFactory;
this.listenerFactory = listenerFactory;
}
@@ -97,6 +100,8 @@
List<AddressPort> initialProxies = MCMPUtils.parseProxies(this.mcmpConfig.getProxyList());
this.mcmpHandler.init(initialProxies);
+ this.loadBalanceFactorProvider = this.loadBalanceFactorProviderFactory.createLoadBalanceFactorProvider();
+
Boolean advertise = this.mcmpConfig.getAdvertise();
if (Boolean.TRUE.equals(advertise) || (advertise == null && initialProxies.isEmpty()))
@@ -302,7 +307,7 @@
// ---------------------------------------------------------------- Private
- private void checkInit()
+ protected void checkInit()
{
if (!this.init)
{
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java (from rev 2062, trunk/mod_cluster/src/main/java/org/jboss/modcluster/BasicClusterListener.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,203 @@
+/*
+ * 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 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.Service;
+
+/**
+ * Adapts lifecycle and container listener events to the {@link JBossWebEventHandler} interface.
+ */
+public class JBossWebEventHandlerAdapter implements LifecycleListener, ContainerListener
+{
+ /** Initialization flag. */
+ private volatile boolean init = false;
+
+ private JBossWebEventHandler eventHandler;
+
+ // ----------------------------------------------------------- Constructors
+
+ public JBossWebEventHandlerAdapter(JBossWebEventHandler eventHandler)
+ {
+ this.eventHandler = eventHandler;
+ }
+
+ // ------------------------------------------------------------- Properties
+
+ // ---------------------------------------------- LifecycleListener Methods
+
+ /**
+ * Acknowledge the occurrence of the specified event.
+ * Note: Will never be called when the listener is associated to a Server,
+ * since it is not a Container.
+ *
+ * @param event ContainerEvent that has occurred
+ */
+ public void containerEvent(ContainerEvent event)
+ {
+ Container container = event.getContainer();
+ Object child = event.getData();
+ String type = event.getType();
+
+ if (type.equals(Container.ADD_CHILD_EVENT))
+ {
+ if (container instanceof Host)
+ {
+ // Deploying a webapp
+ ((Lifecycle) child).addLifecycleListener(this);
+ this.eventHandler.addContext((Context) child);
+ }
+ else if (container instanceof Engine)
+ {
+ // Deploying a host
+ container.addContainerListener(this);
+ }
+ }
+ else if (type.equals(Container.REMOVE_CHILD_EVENT))
+ {
+ if (container instanceof Host)
+ {
+ // Undeploying a webapp
+ ((Lifecycle) child).removeLifecycleListener(this);
+ this.eventHandler.removeContext((Context) child);
+ }
+ else if (container instanceof Engine)
+ {
+ // Undeploying a host
+ container.removeContainerListener(this);
+ }
+ }
+ }
+
+ /**
+ * Primary entry point for startup and shutdown events.
+ *
+ * @param event The event that has occurred
+ */
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ Lifecycle source = event.getLifecycle();
+ String type = event.getType();
+
+ if (type.equals(Lifecycle.START_EVENT))
+ {
+ if (source instanceof Context)
+ {
+ // Start a webapp
+ this.eventHandler.startContext((Context) source);
+ }
+ }
+ else if (type.equals(Lifecycle.AFTER_START_EVENT))
+ {
+ if (source instanceof Server)
+ {
+ this.eventHandler.init();
+
+ Server server = (Server) source;
+
+ this.addListeners(server);
+
+ this.eventHandler.startServer(server);
+
+ this.init = true;
+ }
+ }
+ else if (type.equals(Lifecycle.STOP_EVENT))
+ {
+ if (source instanceof Context)
+ {
+ // Stop a webapp
+ this.eventHandler.stopContext((Context) source);
+ }
+ else if (source instanceof Server)
+ {
+ this.init = false;
+
+ Server server = (Server) source;
+
+ this.removeListeners(server);
+
+ this.eventHandler.stopServer(server);
+
+ this.eventHandler.shutdown();
+ }
+ }
+ else if (type.equals(Lifecycle.PERIODIC_EVENT))
+ {
+ if (this.init && (source instanceof Engine))
+ {
+ this.eventHandler.status((Engine) source);
+ }
+ }
+ }
+
+ private void addListeners(Server server)
+ {
+ // Register ourself as a listener for child services
+ for (Service service: server.findServices())
+ {
+ Container engine = service.getContainer();
+ engine.addContainerListener(this);
+ ((Lifecycle) engine).addLifecycleListener(this);
+
+ for (Container host: engine.findChildren())
+ {
+ host.addContainerListener(this);
+
+ for (Container context: host.findChildren())
+ {
+ ((Lifecycle) context).addLifecycleListener(this);
+ }
+ }
+ }
+ }
+
+ private void removeListeners(Server server)
+ {
+ // Unregister ourself as a listener to child components
+ for (Service service: server.findServices())
+ {
+ Container engine = service.getContainer();
+ engine.removeContainerListener(this);
+ ((Lifecycle) engine).removeLifecycleListener(this);
+
+ for (Container host: engine.findChildren())
+ {
+ host.removeContainerListener(this);
+
+ for (Container context: host.findChildren())
+ {
+ ((Lifecycle) context).removeLifecycleListener(this);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/JBossWebEventHandlerAdapter.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterListener.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,231 @@
+/*
+ * 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.Collections;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Server;
+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.LoadConfiguration;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider;
+import org.jboss.modcluster.load.metric.LoadContext;
+import org.jboss.modcluster.load.metric.LoadMetric;
+import org.jboss.modcluster.load.metric.impl.BusyConnectorsLoadMetric;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ModClusterListener extends AbstractModClusterService
+ implements LoadConfiguration
+{
+ static
+ {
+ // We expect to run in a JBoss Web/Tomcat environment where
+ // server logging is done via java.util.logging. So, try to
+ // initialize JBoss Logging to use the JDK logging plugin.
+ // But only if it isn't already initialized to something else!
+ if (Logger.getPluginClassName() == null)
+ {
+ String pluginClass = "org.jboss.logging.jdk.JDK14LoggerPlugin";
+
+ try
+ {
+ ModClusterListener.class.getClassLoader().loadClass(pluginClass);
+ // We can load it, so let's use it
+ Logger.setPluginClassName(pluginClass);
+ }
+ catch (Throwable t)
+ {
+ // Cannot load JDK14LoggerPlugin; just fall through to defaults
+ }
+ }
+ }
+
+ private static final Logger log = Logger.getLogger(ModClusterListener.class);
+
+ private final StringManager sm = StringManager.getManager(Constants.Package);
+
+ private Class<? extends LoadMetric<? extends LoadContext>> loadMetricClass = BusyConnectorsLoadMetric.class;
+ private int decayFactor = 2;
+ private int history = 9;
+ private double capacity = 1;
+
+ public ModClusterListener()
+ {
+ super();
+ }
+
+ protected ModClusterListener(MCMPHandler mcmpHandler, LifecycleListener lifecycleListener)
+ {
+ super(mcmpHandler, lifecycleListener);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.LoadBalanceFactorProviderFactory#createLoadBalanceFactorProvider()
+ */
+ @SuppressWarnings("unchecked")
+ public LoadBalanceFactorProvider createLoadBalanceFactorProvider()
+ {
+ try
+ {
+ LoadMetric<LoadContext> metric = (LoadMetric<LoadContext>) this.loadMetricClass.newInstance();
+
+ metric.setCapacity(this.capacity);
+
+ DynamicLoadBalanceFactorProvider provider = new DynamicLoadBalanceFactorProvider(Collections.singleton(metric));
+
+ provider.setDecayFactor(this.decayFactor);
+ provider.setHistory(this.history);
+
+ return provider;
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.AbstractModClusterService#lifecycleEvent(org.apache.catalina.LifecycleEvent)
+ */
+ @Override
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ super.lifecycleEvent(event);
+
+ Lifecycle source = event.getLifecycle();
+
+ if (source instanceof Server)
+ {
+ Server server = (Server) source;
+ String type = event.getType();
+
+ // Register/unregister ClusterListener mbean on server start/stop
+ if (Lifecycle.AFTER_START_EVENT.equals(type))
+ {
+ 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(type))
+ {
+ 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");
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.config.LoadConfiguration#getLoadMetricClass()
+ */
+ public Class<? extends LoadMetric<? extends LoadContext>> getLoadMetricClass()
+ {
+ return this.loadMetricClass;
+ }
+
+ public void setLoadMetricClass(Class<? extends LoadMetric<? extends LoadContext>> loadMetricClass)
+ {
+ this.loadMetricClass = loadMetricClass;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.config.LoadBalanceFactorProviderConfiguration#getDecayFactor()
+ */
+ public int getLoadDecayFactor()
+ {
+ return this.decayFactor;
+ }
+
+ public void setLoadDecayFactor(int decayFactor)
+ {
+ this.decayFactor = decayFactor;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.config.LoadBalanceFactorProviderConfiguration#getHistory()
+ */
+ public int getLoadHistory()
+ {
+ return this.history;
+ }
+
+ public void setLoadHistory(int history)
+ {
+ this.history = history;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.config.LoadMetricConfiguration#getLoadMetricCapacity()
+ */
+ public double getLoadMetricCapacity()
+ {
+ return this.capacity;
+ }
+
+ public void setLoadMetricCapacity(double capacity)
+ {
+ this.capacity = capacity;
+ }
+}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,925 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, 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.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Server;
-import org.apache.catalina.util.StringManager;
-import org.jboss.beans.metadata.api.annotations.Inject;
-import org.jboss.beans.metadata.api.model.FromContext;
-import org.jboss.ha.framework.interfaces.ClusterNode;
-import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
-import org.jboss.ha.framework.interfaces.HAPartition;
-import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
-import org.jboss.ha.framework.server.HAServiceEvent;
-import org.jboss.ha.framework.server.HAServiceEventFactory;
-import org.jboss.ha.framework.server.HAServiceRpcHandler;
-import org.jboss.ha.framework.server.HASingletonImpl;
-import org.jboss.modcluster.config.BalancerConfiguration;
-import org.jboss.modcluster.config.MCMPHandlerConfiguration;
-import org.jboss.modcluster.config.ModClusterConfig;
-import org.jboss.modcluster.config.NodeConfiguration;
-import org.jboss.modcluster.ha.ClusteredMCMPHandler;
-import org.jboss.modcluster.ha.ClusteredMCMPHandlerImpl;
-import org.jboss.modcluster.ha.HASingletonAwareResetRequestSource;
-import org.jboss.modcluster.ha.HASingletonAwareResetRequestSourceImpl;
-import org.jboss.modcluster.ha.ModClusterServiceDRMEntry;
-import org.jboss.modcluster.ha.rpc.BooleanGroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler;
-import org.jboss.modcluster.ha.rpc.GroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.MCMPServerDiscoveryEvent;
-import org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler;
-import org.jboss.modcluster.ha.rpc.ModClusterServiceStateGroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.PeerMCMPDiscoveryStatus;
-import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler;
-import org.jboss.modcluster.ha.rpc.StringGroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.ThrowableGroupRpcResponse;
-import org.jboss.modcluster.load.LoadBalanceFactorProvider;
-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.mcmp.MCMPUtils;
-import org.jboss.modcluster.mcmp.ResetRequestSource;
-import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
-
-/**
- * A ModClusterService.
- *
- * @author Brian Stansberry
- * @version $Revision$
- */
-public class ModClusterService extends HASingletonImpl<HAServiceEvent>
- implements JBossWebEventHandler, ModClusterServiceMBean, ModClusterServiceRpcHandler<List<?>, MCMPServerState>
-{
- private static final Class<?>[] CLUSTER_STATUS_COMPLETE_TYPES = new Class[] { Map.class };
- private static final Class<?>[] GET_CLUSTER_COORDINATOR_STATE_TYPES = new Class[] { Set.class };
-
- // ----------------------------------------------------------------- Fields
-
- final MCMPHandler localHandler;
- final ClusteredMCMPHandler clusteredHandler;
- final HASingletonAwareResetRequestSource resetRequestSource;
- final Map<ClusterNode, MCMPServerDiscoveryEvent> proxyChangeDigest =
- new HashMap<ClusterNode, MCMPServerDiscoveryEvent>();
- final ModClusterServiceDRMEntry drmEntry;
-
- /**
- * The string manager for this package.
- */
- final StringManager sm = StringManager.getManager(Constants.Package);
-
- private final RpcHandler rpcHandler;
- private final JBossWebEventHandler eventHandlerDelegate;
- private final String domain;
- private final boolean masterPerDomain;
-
- volatile int latestLoad;
- volatile int statusCount = 0;
- volatile int processStatusFrequency = 1;
-
- /**
- * Create a new ClusterCoordinator.
- *
- * @param partition the partition of which we are a member
- * @param config our configuration
- * @param loadFactorProvider source for local load balance statistics
- */
- public ModClusterService(HAPartition partition,
- ModClusterConfig config,
- LoadBalanceFactorProvider loadFactorProvider)
- {
- this(partition, config, loadFactorProvider, null);
- }
-
-
- /**
- * Create a new ClusterCoordinator.
- *
- * @param partition the partition of which we are a member
- * @param config our configuration
- * @param loadFactorProvider source for local load balance statistics
- * @param singletonElector chooses the singleton master
- */
- public ModClusterService(HAPartition partition,
- ModClusterConfig config,
- LoadBalanceFactorProvider loadFactorProvider,
- HASingletonElectionPolicy electionPolicy)
- {
- super(new HAServiceEventFactory());
-
- assert partition != null : this.sm.getString("modcluster.error.iae.null", "partition");
- assert loadFactorProvider != null : this.sm.getString("modcluster.error.iae.null", "loadFactorProvider");
- assert config != null : this.sm.getString("modcluster.error.iae.null", "config is null");
-
- this.setHAPartition(partition);
-
- this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this, this);
- this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
- this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this);
- this.eventHandlerDelegate = new ClusteredJBossWebEventHandler(config, config, config, this.clusteredHandler, loadFactorProvider);
- this.domain = config.getDomain();
- this.masterPerDomain = config.isMasterPerDomain();
-
- this.setElectionPolicy(electionPolicy);
-
- this.drmEntry = new ModClusterServiceDRMEntry(partition.getClusterNode(), null);
-
- this.rpcHandler = new RpcHandler();
- }
-
- /**
- * Create a new ClusterCoordinator using the given component parts.
- * Only intended for use by test suites that may wish to inject
- * mock components.
- *
- * @param partition
- * @param nodeConfig
- * @param balancerConfig
- * @param localHandler
- * @param resetRequestSource
- * @param clusteredHandler
- * @param loadManager
- * @param singletonElector
- */
- protected ModClusterService(HAPartition partition,
- NodeConfiguration nodeConfig,
- BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig,
- MCMPHandler localHandler,
- HASingletonAwareResetRequestSource resetRequestSource,
- ClusteredMCMPHandler clusteredHandler,
- LoadBalanceFactorProvider loadFactorProvider,
- HASingletonElectionPolicy electionPolicy)
- {
- super(new HAServiceEventFactory());
-
- assert partition != null : this.sm.getString("modcluster.error.iae.null", "partition");
- assert localHandler != null : this.sm.getString("modcluster.error.iae.null", "localHandler");
- assert resetRequestSource != null : this.sm.getString("modcluster.error.iae.null", "resetRequestSource");
- assert nodeConfig != null : this.sm.getString("modcluster.error.iae.null", "nodeConfig");
- assert balancerConfig != null : this.sm.getString("modcluster.error.iae.null", "balancerConfig");
- assert clusteredHandler != null : this.sm.getString("modcluster.error.iae.null", "clusteredHandler");
-
- this.setHAPartition(partition);
-
- this.localHandler = localHandler;
- this.resetRequestSource = resetRequestSource;
- this.clusteredHandler = clusteredHandler;
- this.eventHandlerDelegate = new ClusteredJBossWebEventHandler(nodeConfig, balancerConfig, mcmpConfig, this.clusteredHandler, loadFactorProvider);
- this.domain = nodeConfig.getDomain();
- this.masterPerDomain = mcmpConfig.isMasterPerDomain();
-
- this.setElectionPolicy(electionPolicy);
-
- this.drmEntry = new ModClusterServiceDRMEntry(partition.getClusterNode(), null);
-
- this.rpcHandler = new RpcHandler();
- }
-
- // -------------------------------------------------- ModClusterServiceMBean
-
- public void addProxy(String host, int port)
- {
- this.clusteredHandler.addProxy(host, port);
- }
-
-
- public void removeProxy(String host, int port)
- {
- this.clusteredHandler.removeProxy(host, port);
- }
-
-
- public String getProxyInfo()
- {
- return this.clusteredHandler.getProxyInfo();
- }
-
-
- public String getProxyConfiguration()
- {
- return this.clusteredHandler.getProxyConfiguration();
- }
-
-
- public void refresh()
- {
- this.clusteredHandler.markProxiesInError();
- }
-
-
- public void reset()
- {
- this.clusteredHandler.reset();
- }
-
-
- // ---------------------------------------------------- JBossWebEventHandler
-
-
- public void init()
- {
- this.eventHandlerDelegate.init();
- }
-
- public void shutdown()
- {
- this.eventHandlerDelegate.shutdown();
- }
-
- public void startServer(Server server)
- {
- this.eventHandlerDelegate.startServer(server);
- }
-
- public void stopServer(Server server)
- {
- this.eventHandlerDelegate.stopServer(server);
- }
-
- public void addContext(Context context)
- {
- this.eventHandlerDelegate.addContext(context);
- }
-
- public void startContext(Context context)
- {
- this.eventHandlerDelegate.startContext(context);
- }
-
- public void stopContext(Context context)
- {
- this.eventHandlerDelegate.stopContext(context);
- }
-
- public void removeContext(Context context)
- {
- this.eventHandlerDelegate.removeContext(context);
- }
-
- public void status(Engine engine)
- {
- this.eventHandlerDelegate.status(engine);
- }
-
- // ------------------------------------------------------------- Properties
-
- public String getDomain()
- {
- return this.domain;
- }
-
- public int getProcessStatusFrequency()
- {
- return this.processStatusFrequency;
- }
-
- public void setProcessStatusFrequency(int processStatusFrequency)
- {
- this.processStatusFrequency = processStatusFrequency;
- }
-
- // ------------------------------------------------------- Public Overrides
-
- @Override
- public void startSingleton()
- {
- // Ensure we do a full status on the next event
- this.statusCount = this.processStatusFrequency - 1;
- }
-
- @Override
- @Inject(fromContext = FromContext.NAME)
- public void setServiceHAName(String haName)
- {
- super.setServiceHAName(haName);
- }
-
- // -------------------------------------------------------------- Protected
-
- /**
- * {@inheritDoc}
- *
- * @return an inner class that allows us to avoid exposing RPC methods as
- * public methods of this class
- */
- @Override
- protected HAServiceRpcHandler<HAServiceEvent> getRpcHandler()
- {
- return this.rpcHandler;
- }
-
- /**
- * {@inheritDoc}
- *
- * @returns the key used by DRM and the partition rpc handler mapping.
- */
- @Override
- public String getHAServiceKey()
- {
- String name = this.getServiceHAName();
-
- return ((this.domain != null) && this.masterPerDomain) ? name + ":" + this.domain : name;
- }
-
- /**
- * {@inheritDoc}
- *
- * @return a {@link ModClusterServiceDRMEntry}
- */
- @Override
- protected Serializable getReplicant()
- {
- return this.drmEntry;
- }
-
- /**
- * {@inheritDoc}
- * @return a list of cluster nodes from which to elect a new master
- */
- @Override
- @SuppressWarnings("unchecked")
- protected List<ClusterNode> getElectionCandidates()
- {
- List<ModClusterServiceDRMEntry> candidates = this.getHAPartition().getDistributedReplicantManager().lookupReplicants(this.getHAServiceKey());
-
- return this.narrowCandidateList(candidates);
- }
-
- /**
- * Processes the candidate list, discarding those who don't match our domain nor the best
- * candidate when it comes to the ability to communicate with proxies.
- *
- * @param candidates the universe of possible candidates.
- * @return a list of candidates with an equivalent ability to communicate
- * with proxies, or <code>null</code> if <code>candidates</code>
- * is <code>null</code>.
- */
- List<ClusterNode> narrowCandidateList(Collection<ModClusterServiceDRMEntry> candidates)
- {
- if (candidates == null) return null;
-
- List<ClusterNode> narrowed = new ArrayList<ClusterNode>(candidates.size());
- ModClusterServiceDRMEntry champion = null;
-
- for (ModClusterServiceDRMEntry candidate: candidates)
- {
- if (champion == null)
- {
- champion = candidate;
- narrowed.add(candidate.getPeer());
- }
- else
- {
- int compFactor = candidate.compareTo(champion);
- if (compFactor < 0)
- {
- // New champ
- narrowed.clear();
- champion = candidate;
- narrowed.add(candidate.getPeer());
- }
- else if (compFactor == 0)
- {
- // As good as our champ
- narrowed.add(candidate.getPeer());
- }
- // else candidate didn't make the cut; continue
- }
- }
-
- return narrowed;
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#clusterStatusComplete(java.util.Map)
- */
- public void clusterStatusComplete(Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
- {
- try
- {
- this.callMethodOnPartition("clusterStatusComplete", new Object[] { statuses }, CLUSTER_STATUS_COMPLETE_TYPES);
- }
- catch (Exception e)
- {
- this.log.error(this.sm.getString("modcluster.error.status.complete"), e);
- }
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#getClusterCoordinatorState(java.util.Set)
- */
- public List<?> getClusterCoordinatorState(Set<MCMPServerState> masterList)
- {
- try
- {
- return this.callMethodOnPartition("getClusterCoordinatorState", new Object[] { masterList }, GET_CLUSTER_COORDINATOR_STATE_TYPES);
- }
- catch (Exception e)
- {
- throw Utils.convertToUnchecked(e);
- }
- }
-
- void updateLocalDRM(ModClusterServiceDRMEntry status)
- {
- try
- {
- this.getHAPartition().getDistributedReplicantManager().add(this.getHAServiceKey(), status);
- }
- catch (Exception e)
- {
- throw Utils.convertToUnchecked(e);
- }
- }
-
- // ---------------------------------------------------------- Inner classes
-
- /**
- * This is the object that gets invoked on via reflection by HAPartition.
- */
- protected class RpcHandler extends HASingletonImpl<HAServiceEvent>.RpcHandler implements ModClusterServiceRpcHandler<GroupRpcResponse, MCMPServer>, ClusteredMCMPHandlerRpcHandler, ResetRequestSourceRpcHandler<GroupRpcResponse>
- {
- private final ModClusterService coord = ModClusterService.this;
- private final GroupRpcResponse SUCCESS = new GroupRpcResponse(this.coord.getHAPartition().getClusterNode());
-/*
- public GroupRpcResponse getLocalAddress() throws IOException
- {
- if (!this.coord.isMasterNode()) return null;
-
- return new InetAddressGroupRpcResponse(this.coord.getHAPartition().getClusterNode(), this.coord.localHandler.getLocalAddress());
- }
-*/
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#mcmpServerDiscoveryEvent(org.jboss.modcluster.ha.rpc.MCMPServerDiscoveryEvent)
- */
- public GroupRpcResponse mcmpServerDiscoveryEvent(MCMPServerDiscoveryEvent event)
- {
- if (!this.coord.isMasterNode()) return null;
-
- synchronized (ModClusterService.this.proxyChangeDigest)
- {
- AddressPort ap = event.getMCMPServer();
-
- if (event.isAddition())
- {
- this.coord.localHandler.addProxy(ap.getAddress(), ap.getPort());
- }
- else
- {
- this.coord.localHandler.removeProxy(ap.getAddress(), ap.getPort());
- }
-
- ModClusterService.this.proxyChangeDigest.put(event.getSender(), event);
-
- return new GroupRpcResponse(ModClusterService.this.getHAPartition().getClusterNode());
- }
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#getClusterCoordinatorState(java.util.Set)
- */
- public GroupRpcResponse getClusterCoordinatorState(Set<MCMPServer> masterList)
- {
- // TODO is this the correct response here?
- if (this.coord.isMasterNode()) return null;
-
- Set<MCMPServerState> ourStates = this.coord.clusteredHandler.updateServersFromMasterNode(masterList);
-
- boolean needReset = this.coord.clusteredHandler.getNeedsResetTransmission();
-
- Map<String, Set<ResetRequestSource.VirtualHost>> map = Collections.emptyMap();
- List<MCMPRequest> resetRequests = needReset ? this.coord.resetRequestSource.getLocalResetRequests(map) : null;
-
- ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
- List<MCMPServerDiscoveryEvent> events = this.coord.clusteredHandler.getPendingDiscoveryEvents();
-
- GroupRpcResponse response = new ModClusterServiceStateGroupRpcResponse(node, this.coord.latestLoad, ourStates, events, resetRequests);
-
- if (needReset)
- {
- this.coord.clusteredHandler.recordResetTransmission();
- }
-
- return response;
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#clusterStatusComplete(java.util.Map)
- */
- public void clusterStatusComplete(Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
- {
- HAPartition partition = this.coord.getHAPartition();
- ClusterNode cn = partition.getClusterNode();
- PeerMCMPDiscoveryStatus newStatus = statuses.get(cn);
- if (newStatus != null)
- {
- // Notify our handler that discovery events have been processed
- this.coord.clusteredHandler.discoveryEventsReceived(newStatus.getLatestDiscoveryEvent());
-
- // Notify our handler that any reset requests have been processed
- this.coord.clusteredHandler.recordResetSuccess();
-
- DistributedReplicantManager drm = partition.getDistributedReplicantManager();
- String key = this.coord.getHAServiceKey();
- ModClusterServiceDRMEntry oldStatus = (ModClusterServiceDRMEntry) drm.lookupLocalReplicant(key);
- if (!newStatus.equals(oldStatus))
- {
- try
- {
- drm.add(key, new ModClusterServiceDRMEntry(cn, newStatus.getMCMPServerStates(), oldStatus.getJvmRoutes()));
- }
- catch (Exception e)
- {
- this.coord.log.error(ModClusterService.this.sm.getString("modcluster.error.drm"), e);
- }
- }
- }
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#getProxyConfiguration()
- */
- public GroupRpcResponse getProxyConfiguration()
- {
- if (!this.coord.isMasterNode()) return null;
-
- ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
- String configuration = this.coord.localHandler.getProxyConfiguration();
-
- return new StringGroupRpcResponse(node, configuration);
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#getProxyInfo()
- */
- public GroupRpcResponse getProxyInfo()
- {
- if (!this.coord.isMasterNode()) return null;
-
- ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
- String info = this.coord.localHandler.getProxyInfo();
-
- return new StringGroupRpcResponse(node, info);
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#isProxyHealthOK()
- */
- public GroupRpcResponse isProxyHealthOK()
- {
- if (!this.coord.isMasterNode()) return null;
-
- ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
- boolean ok = this.coord.localHandler.isProxyHealthOK();
-
- return new BooleanGroupRpcResponse(node, ok);
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#markProxiesInError()
- */
- public GroupRpcResponse markProxiesInError()
- {
- if (!this.coord.isMasterNode()) return null;
-
- this.coord.localHandler.markProxiesInError();
-
- return this.SUCCESS;
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#reset()
- */
- public GroupRpcResponse reset()
- {
- if (!this.coord.isMasterNode()) return null;
-
- this.coord.localHandler.reset();
-
- return this.SUCCESS;
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#sendRequest(org.jboss.modcluster.mcmp.MCMPRequest)
- */
- public GroupRpcResponse sendRequest(MCMPRequest request)
- {
- if (!this.coord.isMasterNode()) return null;
-
- this.coord.localHandler.sendRequest(request);
-
- return this.SUCCESS;
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#sendRequests(java.util.List)
- */
- public GroupRpcResponse sendRequests(List<MCMPRequest> requests)
- {
- if (!this.coord.isMasterNode()) return null;
-
- this.coord.localHandler.sendRequests(requests);
-
- return this.SUCCESS;
- }
-
- /**
- * @see org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
- */
- public GroupRpcResponse getResetRequests(Map<String, Set<ResetRequestSource.VirtualHost>> response)
- {
- ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
- List<MCMPRequest> requests = this.coord.resetRequestSource.getLocalResetRequests(response);
-
- return new ResetRequestGroupRpcResponse(node, requests);
- }
- }
-
- private class ClusteredJBossWebEventHandler extends DefaultJBossWebEventHandler
- {
- private final ModClusterService coord = ModClusterService.this;
-
- /**
- * Create a new ClusteredJBossWebEventHandler.
- *
- * @param config
- * @param loadFactorProvider
- */
- public ClusteredJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
- MCMPHandlerConfiguration mcmpConfig, MCMPHandler clusteredHandler, LoadBalanceFactorProvider loadFactorProvider)
- {
- super(nodeConfig, balancerConfig, mcmpConfig, clusteredHandler, loadFactorProvider);
- }
-
- @Override
- public void startServer(Server server)
- {
- // Pass on ref to our server
- this.coord.resetRequestSource.setJbossWebServer(server);
-
- super.startServer(server);
- }
-
- @Override
- protected void config(Engine engine)
- {
- this.config(engine, this.coord.localHandler);
- }
-
- @Override
- protected void jvmRouteEstablished(Engine engine)
- {
- this.coord.drmEntry.addJvmRoute(engine.getJvmRoute());
- this.coord.updateLocalDRM(this.coord.drmEntry);
- }
-
- @Override
- protected void removeAll(Engine engine)
- {
- super.removeAll(engine);
-
- this.coord.drmEntry.removeJvmRoute(engine.getJvmRoute());
- this.coord.updateLocalDRM(this.coord.drmEntry);
- }
-
- @Override
- public void status(Engine engine)
- {
- log.debug(this.coord.sm.getString("modcluster.engine.status", engine.getName()));
-
- this.coord.latestLoad = this.getLoadBalanceFactor();
-
- if (this.coord.isMasterNode())
- {
- this.coord.statusCount = (this.coord.statusCount + 1) % this.coord.processStatusFrequency;
-
- if (this.coord.statusCount == 0)
- {
- this.updateClusterStatus();
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- void updateClusterStatus()
- {
- Set<MCMPServerState> masterList = null;
- Map<ClusterNode, MCMPServerDiscoveryEvent> latestEvents = null;
- Map<ClusterNode, ModClusterServiceDRMEntry> nonresponsive = new HashMap<ClusterNode, ModClusterServiceDRMEntry>();
- Map<String, Integer> loadBalanceFactors = new HashMap<String, Integer>();
- Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses = new HashMap<ClusterNode, PeerMCMPDiscoveryStatus>();
- List<MCMPRequest> resetRequests = new ArrayList<MCMPRequest>();
- HAPartition partition = this.coord.getHAPartition();
- DistributedReplicantManager drm = partition.getDistributedReplicantManager();
- boolean resync = false;
-
- do
- {
- resync = false;
-
- this.coord.localHandler.status();
-
- synchronized (this.coord.proxyChangeDigest)
- {
- masterList = this.coord.localHandler.getProxyStates();
- latestEvents = new HashMap<ClusterNode, MCMPServerDiscoveryEvent>(this.coord.proxyChangeDigest);
- }
-
- List<ModClusterServiceDRMEntry> replicants = drm.lookupReplicants(this.coord.getHAServiceKey());
- nonresponsive.clear();
-
- for (ModClusterServiceDRMEntry replicant: replicants)
- {
- nonresponsive.put(replicant.getPeer(), replicant);
- }
- nonresponsive.remove(partition.getClusterNode());
-
- // FIXME -- what about our own dropped discovery events if we just became master?
- List responses = this.coord.getClusterCoordinatorState(masterList);
-
- // Gather up all the reset requests in one list
- // FIXME -- what about our own dropped requests if we just became master?
- resetRequests.clear();
-
- // Gather all the load balance factors
- loadBalanceFactors.clear();
-
- // Add our own lbf - it is not returned via getclusterCoordinatorState(...)
- for (String jvmRoute: this.coord.drmEntry.getJvmRoutes())
- {
- loadBalanceFactors.put(jvmRoute, this.coord.latestLoad);
- }
-
- // Gather the info on who knows about what proxies
- statuses.clear();
-
- for (Object response: responses)
- {
- if (response instanceof ModClusterServiceStateGroupRpcResponse)
- {
- ModClusterServiceStateGroupRpcResponse mcssgrr = (ModClusterServiceStateGroupRpcResponse) response;
- ClusterNode cn = mcssgrr.getSender();
-
- // Check for discovery events we haven't processed
- MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
-
- for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
- {
- if (latestEvent != null && latestEvent.getEventIndex() <= toCheck.getEventIndex())
- {
- continue; // already processed it
- }
-
- AddressPort ap = toCheck.getMCMPServer();
- if (toCheck.isAddition())
- {
- this.coord.localHandler.addProxy(ap.getAddress(), ap.getPort());
- }
- else
- {
- this.coord.localHandler.removeProxy(ap.getAddress(), ap.getPort());
- }
- resync = true;
- }
-
- if (!resync) // don't bother if we are going to start over
- {
- statuses.put(cn, new PeerMCMPDiscoveryStatus(cn, mcssgrr.getStates(), latestEvent));
-
- List<MCMPRequest> toAdd = mcssgrr.getResetRequests();
- if (toAdd != null)
- {
- resetRequests.addAll(toAdd);
- }
-
- ModClusterServiceDRMEntry removed = nonresponsive.remove(cn);
- if (removed != null)
- {
- Integer lbf = Integer.valueOf(mcssgrr.getLoadBalanceFactor());
- for (String jvmRoute: removed.getJvmRoutes())
- {
- loadBalanceFactors.put(jvmRoute, lbf);
- }
- }
- }
- }
- else if (response instanceof ThrowableGroupRpcResponse)
- {
- ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
- ClusterNode cn = tgrr.getSender();
-
- log.warn(this.coord.sm.getString("modcluster.error.rpc.known", "getClusterCoordinatorState", cn), tgrr.getValue());
-
- // Don't remove from nonresponsive list and we'll pass back an error
- // status (null server list) to this peer
- }
- else if (response instanceof Throwable)
- {
- log.warn(this.coord.sm.getString("modcluster.error.rpc.unknown", "getClusterCoordinatorState"), (Throwable) response);
- }
- else
- {
- log.error(this.coord.sm.getString("modcluster.error.rpc.unexpected", response, "getClusterCoordinatorState"));
- }
- }
- }
- // We picked up previously unknown discovery events; start over
- while (resync);
-
- // Add error-state objects for non-responsive peers
- Integer lbf = Integer.valueOf(0);
- for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry: nonresponsive.entrySet())
- {
- ClusterNode cn = entry.getKey();
- statuses.put(entry.getKey(), new PeerMCMPDiscoveryStatus(cn, null, latestEvents.get(cn)));
-
- for (String jvmRoute: entry.getValue().getJvmRoutes())
- {
- loadBalanceFactors.put(jvmRoute, lbf);
- }
- }
- // FIXME handle crashed members, gone from DRM
-
- // Advise the proxies of any reset requests
- this.coord.localHandler.sendRequests(resetRequests);
-
- // Pass along the LBF values
- List<MCMPRequest> statusRequests = new ArrayList<MCMPRequest>();
- for (Map.Entry<String, Integer> entry: loadBalanceFactors.entrySet())
- {
- statusRequests.add(MCMPUtils.createStatusRequest(entry.getKey(), entry.getValue().intValue()));
- }
- this.coord.localHandler.sendRequests(statusRequests);
-
- // Advise the members the process is done and that they should update DRM
- this.notifyClusterStatusComplete(masterList, statuses);
- }
-
- private void notifyClusterStatusComplete(Set<MCMPServerState> masterList, Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
- {
- HAPartition partition = this.coord.getHAPartition();
-
- // Determine who should update DRM first -- us or the rest of the nodes
- Set<ModClusterServiceDRMEntry> allStatuses = new HashSet<ModClusterServiceDRMEntry>(statuses.values());
- DistributedReplicantManager drm = partition.getDistributedReplicantManager();
- ModClusterServiceDRMEntry ourCurrentStatus = (ModClusterServiceDRMEntry) drm.lookupLocalReplicant(this.coord.getHAServiceKey());
- allStatuses.add(ourCurrentStatus);
-
- ClusterNode node = partition.getClusterNode();
-
- boolean othersFirst = this.coord.narrowCandidateList(allStatuses).contains(node);
- ModClusterServiceDRMEntry newStatus = new ModClusterServiceDRMEntry(node, masterList, this.coord.drmEntry.getJvmRoutes());
- boolean updated = !newStatus.equals(ourCurrentStatus);
-
- if (othersFirst)
- {
- this.coord.clusterStatusComplete(statuses);
- }
-
- if (updated)
- {
- this.coord.updateLocalDRM(newStatus);
- }
-
- if (!othersFirst)
- {
- this.coord.clusterStatusComplete(statuses);
- }
- }
- }
-}
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java (from rev 2062, trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,58 @@
+/*
+ * 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.LifecycleListener;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ModClusterService extends AbstractModClusterService
+{
+ private final LoadBalanceFactorProvider lbfProvider;
+
+ public ModClusterService(LoadBalanceFactorProvider lbfProvider)
+ {
+ super();
+
+ this.lbfProvider = lbfProvider;
+ }
+
+ protected ModClusterService(MCMPHandler mcmpHandler, LifecycleListener lifecycleListener, LoadBalanceFactorProvider lbfProvider)
+ {
+ super(mcmpHandler, lifecycleListener);
+
+ this.lbfProvider = lbfProvider;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.LoadBalanceFactorProviderFactory#createLoadBalanceFactorProvider()
+ */
+ public LoadBalanceFactorProvider createLoadBalanceFactorProvider()
+ {
+ return this.lbfProvider;
+ }
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,82 +0,0 @@
-/*
- * 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.jboss.ha.framework.interfaces.HASingletonMBean;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
-import org.jboss.modcluster.mcmp.MCMPServerState;
-
-/**
- * StandardMBean interface for {@link ModClusterService}.
- *
- * @author Brian Stansberry
- */
-public interface ModClusterServiceMBean extends HASingletonMBean
-{
- /**
- * Add a proxy to the list of those with which this handler communicates.
- * Communication does not begin until the next call to {@link #status()}.
- *
- * @param host the hostname of the proxy; a string suitable for passing to
- * <code>InetAddress.getByHost(...)</code>
- * @param port the port on which the proxy listens for MCMP requests
- */
- void addProxy(String host, int port);
-
- /**
- * Remove a proxy from the list of those with which this handler communicates.
- * Communication does not end until the next call to {@link #status()}.
- *
- * @param host the hostname of the proxy; a string suitable for passing to
- * <code>InetAddress.getByHost(...)</code>
- * @param port the port on which the proxy listens for MCMP requests
- */
- void removeProxy(String host, int port);
-
- /**
- * Reset any proxies whose status is {@link MCMPServerState#DOWN DOWN} up to
- * {@link MCMPServerState#ERROR ERROR}, where the configuration will
- * be refreshed.
- */
- void reset();
-
- /**
- * FIXME. This is the same as markProxiesInError().
- *
- * Reset any proxies whose status is {@link MCMPServerState#OK OK} down to
- * {@link MCMPServerState#ERROR ERROR}, which will trigger a refresh of
- * their configuration. To be used through JMX or similar.
- */
- void refresh();
-
- /**
- * Sends a {@link MCMPRequestType#DUMP DUMP} request to all proxies,
- * concatentating their responses into a single string.
- *
- * TODO wouldn't a List<String> be better? Let the caller concatenate if
- * so desired.
- *
- * @return the configuration information from all the accessible proxies.
- */
- String getProxyConfiguration();
-}
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java (from rev 2062, trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,96 @@
+/*
+ * 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;
+
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface ModClusterServiceMBean
+{
+ /**
+ * Add a proxy to the list of those with which this handler communicates.
+ * Communication does not begin until the next call to {@link #status()}.
+ *
+ * @param host the hostname of the proxy; a string suitable for passing to
+ * <code>InetAddress.getByHost(...)</code>
+ * @param port the port on which the proxy listens for MCMP requests
+ */
+ void addProxy(String host, int port);
+
+ /**
+ * Remove a proxy from the list of those with which this handler communicates.
+ * Communication does not end until the next call to {@link #status()}.
+ *
+ * @param host the hostname of the proxy; a string suitable for passing to
+ * <code>InetAddress.getByHost(...)</code>
+ * @param port the port on which the proxy listens for MCMP requests
+ */
+ void removeProxy(String host, int port);
+
+ /**
+ * 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();
+
+ /**
+ * Retrieves the full proxy info message.
+ *
+ *
+ * @return the proxy info confguration
+ */
+ public String getProxyInfo();
+
+ /**
+ * 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();
+
+ /**
+ * Refresh configuration. To be used through JMX or similar.
+ */
+ public void refresh();
+
+ /**
+ * Disable all webapps for all engines. To be used through JMX or similar.
+ */
+ public boolean disable();
+
+ /**
+ * Enable all webapps for all engines. To be used through JMX or similar.
+ */
+ public boolean enable();
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadBalanceFactorProviderConfiguration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadBalanceFactorProviderConfiguration.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadBalanceFactorProviderConfiguration.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,41 +0,0 @@
-/*
- * 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.config;
-
-/**
- * @author Paul Ferraro
- *
- */
-public interface LoadBalanceFactorProviderConfiguration
-{
- /**
- * Returns the history count.
- * @return a positive integer
- */
- int getHistory();
-
- /**
- * Returns the exponential decay factor.
- * @return a positive integer
- */
- int getDecayFactor();
-}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadConfiguration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadConfiguration.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadConfiguration.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,55 @@
+/*
+ * 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.config;
+
+import org.jboss.modcluster.load.metric.LoadContext;
+import org.jboss.modcluster.load.metric.LoadMetric;
+
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface LoadConfiguration
+{
+ Class<? extends LoadMetric<? extends LoadContext>> getLoadMetricClass();
+
+ /**
+ * Returns the load capacity of this metric.
+ * Used to normalize the value returned by {@link #getLoad()} expressed as a percentage of the capacity, such that:
+ * 0 <= ({@link #getLoad()} / {@link #getCapacity()}) < 1
+ * @return the estimated capacity of this metric.
+ */
+ double getLoadMetricCapacity();
+
+ /**
+ * Returns the history count.
+ * @return a positive integer
+ */
+ int getLoadHistory();
+
+ /**
+ * Returns the exponential decay factor.
+ * @return a positive integer
+ */
+ int getLoadDecayFactor();
+}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadMetricConfiguration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadMetricConfiguration.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/LoadMetricConfiguration.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,44 +0,0 @@
-/*
- * 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.config;
-
-
-/**
- * @author Paul Ferraro
- *
- */
-public interface LoadMetricConfiguration
-{
- /**
- * Returns the "weight" of this metric, i.e. significance of this load metric compared to the other metrics.
- * @return the weight of the metric
- */
- int getWeight();
-
- /**
- * Returns the load capacity of this metric.
- * Used to normalize the value returned by {@link #getLoad()} expressed as a percentage of the capacity, such that:
- * 0 <= ({@link #getLoad()} / {@link #getCapacity()}) < 1
- * @return the estimated capacity of this metric.
- */
- double getCapacity();
-}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/MCMPHandlerConfiguration.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -70,9 +70,4 @@
* Advertise security key.
*/
String getAdvertiseSecurityKey();
-
- /**
- * Should clustered service use a singleton master per domain.
- */
- boolean isMasterPerDomain();
}
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-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ModClusterConfig.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -25,15 +25,12 @@
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
- extends StaticLoadBalanceFactorProvider
implements BalancerConfiguration, MCMPHandlerConfiguration, NodeConfiguration, SSLConfiguration
{
// ----------------------------------------------- MCMPHandlerConfiguration
@@ -70,11 +67,6 @@
public boolean isSsl() { return this.ssl; }
public void setSsl(boolean ssl) { this.ssl = ssl; }
- private boolean masterPerDomain = false;
- public boolean isMasterPerDomain() { return this.masterPerDomain; }
- public void setMasterPerDomain(boolean masterPerDomain) { this.masterPerDomain = masterPerDomain; }
-
-
// ----------------------------------------------------- SSLConfiguration
private String sslCiphers = null;
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-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/NodeConfiguration.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -22,9 +22,8 @@
package org.jboss.modcluster.config;
-import org.jboss.modcluster.load.LoadBalanceFactorProvider;
-public interface NodeConfiguration extends LoadBalanceFactorProvider
+public interface NodeConfiguration
{
/**
* Domain parameter, which allows tying a jvmRoute to a particular domain.
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAConfiguration.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAConfiguration.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAConfiguration.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,34 @@
+/*
+ * 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.config.ha;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface HAConfiguration
+{
+ /**
+ * Should clustered service use a singleton master per domain.
+ */
+ boolean isMasterPerDomain();
+}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAModClusterConfig.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAModClusterConfig.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/config/ha/HAModClusterConfig.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,35 @@
+/*
+ * 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.config.ha;
+
+import org.jboss.modcluster.config.ModClusterConfig;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class HAModClusterConfig extends ModClusterConfig implements HAConfiguration
+{
+ private boolean masterPerDomain = false;
+ public boolean isMasterPerDomain() { return this.masterPerDomain; }
+ public void setMasterPerDomain(boolean masterPerDomain) { this.masterPerDomain = masterPerDomain; }
+}
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java (from rev 2062, trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,966 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ha;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.catalina.Engine;
+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.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.beans.metadata.api.model.FromContext;
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
+import org.jboss.ha.framework.server.HAServiceEvent;
+import org.jboss.ha.framework.server.HAServiceEventFactory;
+import org.jboss.ha.framework.server.HAServiceRpcHandler;
+import org.jboss.ha.framework.server.HASingletonImpl;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.DefaultJBossWebEventHandler;
+import org.jboss.modcluster.JBossWebEventHandler;
+import org.jboss.modcluster.JBossWebEventHandlerAdapter;
+import org.jboss.modcluster.Utils;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.MCMPHandlerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.config.ha.HAConfiguration;
+import org.jboss.modcluster.config.ha.HAModClusterConfig;
+import org.jboss.modcluster.ha.rpc.BooleanGroupRpcResponse;
+import org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler;
+import org.jboss.modcluster.ha.rpc.GroupRpcResponse;
+import org.jboss.modcluster.ha.rpc.MCMPServerDiscoveryEvent;
+import org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler;
+import org.jboss.modcluster.ha.rpc.ModClusterServiceStateGroupRpcResponse;
+import org.jboss.modcluster.ha.rpc.PeerMCMPDiscoveryStatus;
+import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
+import org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler;
+import org.jboss.modcluster.ha.rpc.StringGroupRpcResponse;
+import org.jboss.modcluster.ha.rpc.ThrowableGroupRpcResponse;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
+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.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
+import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
+
+/**
+ * A ModClusterService.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class HAModClusterService extends HASingletonImpl<HAServiceEvent>
+ implements LifecycleListener, HAModClusterServiceMBean, ModClusterServiceRpcHandler<List<?>, MCMPServerState>, LoadBalanceFactorProviderFactory
+{
+ private static final Class<?>[] CLUSTER_STATUS_COMPLETE_TYPES = new Class[] { Map.class };
+ private static final Class<?>[] GET_CLUSTER_COORDINATOR_STATE_TYPES = new Class[] { Set.class };
+
+ // ----------------------------------------------------------------- Fields
+
+ final MCMPHandler localHandler;
+ final ClusteredMCMPHandler clusteredHandler;
+ final HASingletonAwareResetRequestSource resetRequestSource;
+ final Map<ClusterNode, MCMPServerDiscoveryEvent> proxyChangeDigest =
+ new HashMap<ClusterNode, MCMPServerDiscoveryEvent>();
+ final ModClusterServiceDRMEntry drmEntry;
+
+ /**
+ * The string manager for this package.
+ */
+ final StringManager sm = StringManager.getManager(Constants.Package);
+
+ private final LifecycleListener lifecycleListener;
+ private final LoadBalanceFactorProvider loadBalanceFactorProvider;
+ private final RpcHandler rpcHandler;
+ private final String domain;
+ private final boolean masterPerDomain;
+
+ volatile int latestLoad;
+ volatile int statusCount = 0;
+ volatile int processStatusFrequency = 1;
+
+ /**
+ * Create a new ClusterCoordinator.
+ *
+ * @param partition the partition of which we are a member
+ * @param config our configuration
+ * @param loadFactorProvider source for local load balance statistics
+ */
+ public HAModClusterService(HAPartition partition,
+ HAModClusterConfig config,
+ LoadBalanceFactorProvider loadFactorProvider)
+ {
+ this(partition, config, loadFactorProvider, null);
+ }
+
+
+ /**
+ * Create a new ClusterCoordinator.
+ *
+ * @param partition the partition of which we are a member
+ * @param config our configuration
+ * @param loadFactorProvider source for local load balance statistics
+ * @param singletonElector chooses the singleton master
+ */
+ public HAModClusterService(HAPartition partition,
+ HAModClusterConfig config,
+ LoadBalanceFactorProvider loadFactorProvider,
+ HASingletonElectionPolicy electionPolicy)
+ {
+ super(new HAServiceEventFactory());
+
+ assert partition != null : this.sm.getString("modcluster.error.iae.null", "partition");
+ assert loadFactorProvider != null : this.sm.getString("modcluster.error.iae.null", "loadFactorProvider");
+ assert config != null : this.sm.getString("modcluster.error.iae.null", "config is null");
+
+ this.setHAPartition(partition);
+
+ this.loadBalanceFactorProvider = loadFactorProvider;
+ this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this, this);
+ this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
+ this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this);
+
+ JBossWebEventHandler eventHandler = new ClusteredJBossWebEventHandler(config, config, config, this.clusteredHandler, this);
+
+ this.lifecycleListener = new JBossWebEventHandlerAdapter(eventHandler);
+
+ this.domain = config.getDomain();
+ this.masterPerDomain = config.isMasterPerDomain();
+
+ this.setElectionPolicy(electionPolicy);
+
+ this.drmEntry = new ModClusterServiceDRMEntry(partition.getClusterNode(), null);
+
+ this.rpcHandler = new RpcHandler();
+ }
+
+ /**
+ * Create a new ClusterCoordinator using the given component parts.
+ * Only intended for use by test suites that may wish to inject
+ * mock components.
+ *
+ * @param partition
+ * @param nodeConfig
+ * @param balancerConfig
+ * @param localHandler
+ * @param resetRequestSource
+ * @param clusteredHandler
+ * @param loadManager
+ * @param singletonElector
+ */
+ protected HAModClusterService(HAPartition partition,
+ NodeConfiguration nodeConfig,
+ BalancerConfiguration balancerConfig,
+ MCMPHandlerConfiguration mcmpConfig,
+ HAConfiguration haConfig,
+ MCMPHandler localHandler,
+ HASingletonAwareResetRequestSource resetRequestSource,
+ ClusteredMCMPHandler clusteredHandler,
+ LifecycleListener lifecycleListener,
+ LoadBalanceFactorProvider loadFactorProvider,
+ HASingletonElectionPolicy electionPolicy)
+ {
+ super(new HAServiceEventFactory());
+
+ assert partition != null : this.sm.getString("modcluster.error.iae.null", "partition");
+ assert localHandler != null : this.sm.getString("modcluster.error.iae.null", "localHandler");
+ assert resetRequestSource != null : this.sm.getString("modcluster.error.iae.null", "resetRequestSource");
+ assert nodeConfig != null : this.sm.getString("modcluster.error.iae.null", "nodeConfig");
+ assert mcmpConfig != null : this.sm.getString("modcluster.error.iae.null", "mcmpConfig");
+ assert haConfig != null : this.sm.getString("modcluster.error.iae.null", "haConfig");
+ assert balancerConfig != null : this.sm.getString("modcluster.error.iae.null", "balancerConfig");
+ assert clusteredHandler != null : this.sm.getString("modcluster.error.iae.null", "clusteredHandler");
+
+ this.setHAPartition(partition);
+
+ this.loadBalanceFactorProvider = loadFactorProvider;
+ this.localHandler = localHandler;
+ this.resetRequestSource = resetRequestSource;
+ this.clusteredHandler = clusteredHandler;
+ this.lifecycleListener = lifecycleListener;
+
+ this.domain = nodeConfig.getDomain();
+ this.masterPerDomain = haConfig.isMasterPerDomain();
+
+ this.setElectionPolicy(electionPolicy);
+
+ this.drmEntry = new ModClusterServiceDRMEntry(partition.getClusterNode(), null);
+
+ this.rpcHandler = new RpcHandler();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.apache.catalina.LifecycleListener#lifecycleEvent(org.apache.catalina.LifecycleEvent)
+ */
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ this.lifecycleListener.lifecycleEvent(event);
+ }
+
+ // -------------------------------------------------- ModClusterServiceMBean
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.LoadBalanceFactorProviderFactory#createLoadBalanceFactorProvider()
+ */
+ public LoadBalanceFactorProvider createLoadBalanceFactorProvider()
+ {
+ return this.loadBalanceFactorProvider;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#addProxy(java.lang.String, int)
+ */
+ public void addProxy(String host, int port)
+ {
+ this.clusteredHandler.addProxy(host, port);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#removeProxy(java.lang.String, int)
+ */
+ public void removeProxy(String host, int port)
+ {
+ this.clusteredHandler.removeProxy(host, port);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#getProxyInfo()
+ */
+ public String getProxyInfo()
+ {
+ return this.clusteredHandler.getProxyInfo();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#getProxyConfiguration()
+ */
+ public String getProxyConfiguration()
+ {
+ return this.clusteredHandler.getProxyConfiguration();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#refresh()
+ */
+ public void refresh()
+ {
+ this.clusteredHandler.markProxiesInError();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#reset()
+ */
+ public void reset()
+ {
+ this.clusteredHandler.reset();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#disable()
+ */
+ public boolean disable()
+ {
+ for (Service service: ServerFactory.getServer().findServices())
+ {
+ Engine engine = (Engine) service.getContainer();
+ // Send DISABLE-APP * request
+ MCMPRequest request = MCMPUtils.createDisableEngineRequest(engine);
+ this.clusteredHandler.sendRequest(request);
+ }
+
+ return this.clusteredHandler.isProxyHealthOK();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ModClusterServiceMBean#enable()
+ */
+ public boolean enable()
+ {
+ for (Service service: ServerFactory.getServer().findServices())
+ {
+ Engine engine = (Engine) service.getContainer();
+ // Send ENABLE-APP * request
+ MCMPRequest request = MCMPUtils.createEnableEngineRequest(engine);
+ this.clusteredHandler.sendRequest(request);
+ }
+
+ return this.clusteredHandler.isProxyHealthOK();
+ }
+
+ // ------------------------------------------------------------- Properties
+
+ public String getDomain()
+ {
+ return this.domain;
+ }
+
+ public int getProcessStatusFrequency()
+ {
+ return this.processStatusFrequency;
+ }
+
+ public void setProcessStatusFrequency(int processStatusFrequency)
+ {
+ this.processStatusFrequency = processStatusFrequency;
+ }
+
+ // ------------------------------------------------------- Public Overrides
+
+ @Override
+ public void startSingleton()
+ {
+ // Ensure we do a full status on the next event
+ this.statusCount = this.processStatusFrequency - 1;
+ }
+
+ @Override
+ @Inject(fromContext = FromContext.NAME)
+ public void setServiceHAName(String haName)
+ {
+ super.setServiceHAName(haName);
+ }
+
+ // -------------------------------------------------------------- Protected
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return an inner class that allows us to avoid exposing RPC methods as
+ * public methods of this class
+ */
+ @Override
+ protected HAServiceRpcHandler<HAServiceEvent> getRpcHandler()
+ {
+ return this.rpcHandler;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @returns the key used by DRM and the partition rpc handler mapping.
+ */
+ @Override
+ public String getHAServiceKey()
+ {
+ String name = this.getServiceHAName();
+
+ return ((this.domain != null) && this.masterPerDomain) ? name + ":" + this.domain : name;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return a {@link ModClusterServiceDRMEntry}
+ */
+ @Override
+ protected Serializable getReplicant()
+ {
+ return this.drmEntry;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return a list of cluster nodes from which to elect a new master
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ protected List<ClusterNode> getElectionCandidates()
+ {
+ List<ModClusterServiceDRMEntry> candidates = this.getHAPartition().getDistributedReplicantManager().lookupReplicants(this.getHAServiceKey());
+
+ return this.narrowCandidateList(candidates);
+ }
+
+ /**
+ * Processes the candidate list, discarding those who don't match our domain nor the best
+ * candidate when it comes to the ability to communicate with proxies.
+ *
+ * @param candidates the universe of possible candidates.
+ * @return a list of candidates with an equivalent ability to communicate
+ * with proxies, or <code>null</code> if <code>candidates</code>
+ * is <code>null</code>.
+ */
+ List<ClusterNode> narrowCandidateList(Collection<ModClusterServiceDRMEntry> candidates)
+ {
+ if (candidates == null) return null;
+
+ List<ClusterNode> narrowed = new ArrayList<ClusterNode>(candidates.size());
+ ModClusterServiceDRMEntry champion = null;
+
+ for (ModClusterServiceDRMEntry candidate: candidates)
+ {
+ if (champion == null)
+ {
+ champion = candidate;
+ narrowed.add(candidate.getPeer());
+ }
+ else
+ {
+ int compFactor = candidate.compareTo(champion);
+ if (compFactor < 0)
+ {
+ // New champ
+ narrowed.clear();
+ champion = candidate;
+ narrowed.add(candidate.getPeer());
+ }
+ else if (compFactor == 0)
+ {
+ // As good as our champ
+ narrowed.add(candidate.getPeer());
+ }
+ // else candidate didn't make the cut; continue
+ }
+ }
+
+ return narrowed;
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#clusterStatusComplete(java.util.Map)
+ */
+ public void clusterStatusComplete(Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
+ {
+ try
+ {
+ this.callMethodOnPartition("clusterStatusComplete", new Object[] { statuses }, CLUSTER_STATUS_COMPLETE_TYPES);
+ }
+ catch (Exception e)
+ {
+ this.log.error(this.sm.getString("modcluster.error.status.complete"), e);
+ }
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#getClusterCoordinatorState(java.util.Set)
+ */
+ public List<?> getClusterCoordinatorState(Set<MCMPServerState> masterList)
+ {
+ try
+ {
+ return this.callMethodOnPartition("getClusterCoordinatorState", new Object[] { masterList }, GET_CLUSTER_COORDINATOR_STATE_TYPES);
+ }
+ catch (Exception e)
+ {
+ throw Utils.convertToUnchecked(e);
+ }
+ }
+
+ void updateLocalDRM(ModClusterServiceDRMEntry status)
+ {
+ try
+ {
+ this.getHAPartition().getDistributedReplicantManager().add(this.getHAServiceKey(), status);
+ }
+ catch (Exception e)
+ {
+ throw Utils.convertToUnchecked(e);
+ }
+ }
+
+ // ---------------------------------------------------------- Inner classes
+
+ /**
+ * This is the object that gets invoked on via reflection by HAPartition.
+ */
+ protected class RpcHandler extends HASingletonImpl<HAServiceEvent>.RpcHandler implements ModClusterServiceRpcHandler<GroupRpcResponse, MCMPServer>, ClusteredMCMPHandlerRpcHandler, ResetRequestSourceRpcHandler<GroupRpcResponse>
+ {
+ private final HAModClusterService coord = HAModClusterService.this;
+ private final GroupRpcResponse SUCCESS = new GroupRpcResponse(this.coord.getHAPartition().getClusterNode());
+/*
+ public GroupRpcResponse getLocalAddress() throws IOException
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ return new InetAddressGroupRpcResponse(this.coord.getHAPartition().getClusterNode(), this.coord.localHandler.getLocalAddress());
+ }
+*/
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#mcmpServerDiscoveryEvent(org.jboss.modcluster.ha.rpc.MCMPServerDiscoveryEvent)
+ */
+ public GroupRpcResponse mcmpServerDiscoveryEvent(MCMPServerDiscoveryEvent event)
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ synchronized (HAModClusterService.this.proxyChangeDigest)
+ {
+ AddressPort ap = event.getMCMPServer();
+
+ if (event.isAddition())
+ {
+ this.coord.localHandler.addProxy(ap.getAddress(), ap.getPort());
+ }
+ else
+ {
+ this.coord.localHandler.removeProxy(ap.getAddress(), ap.getPort());
+ }
+
+ HAModClusterService.this.proxyChangeDigest.put(event.getSender(), event);
+
+ return new GroupRpcResponse(HAModClusterService.this.getHAPartition().getClusterNode());
+ }
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#getClusterCoordinatorState(java.util.Set)
+ */
+ public GroupRpcResponse getClusterCoordinatorState(Set<MCMPServer> masterList)
+ {
+ // TODO is this the correct response here?
+ if (this.coord.isMasterNode()) return null;
+
+ Set<MCMPServerState> ourStates = this.coord.clusteredHandler.updateServersFromMasterNode(masterList);
+
+ boolean needReset = this.coord.clusteredHandler.getNeedsResetTransmission();
+
+ Map<String, Set<ResetRequestSource.VirtualHost>> map = Collections.emptyMap();
+ List<MCMPRequest> resetRequests = needReset ? this.coord.resetRequestSource.getLocalResetRequests(map) : null;
+
+ ClusterNode node = HAModClusterService.this.getHAPartition().getClusterNode();
+ List<MCMPServerDiscoveryEvent> events = this.coord.clusteredHandler.getPendingDiscoveryEvents();
+
+ GroupRpcResponse response = new ModClusterServiceStateGroupRpcResponse(node, this.coord.latestLoad, ourStates, events, resetRequests);
+
+ if (needReset)
+ {
+ this.coord.clusteredHandler.recordResetTransmission();
+ }
+
+ return response;
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#clusterStatusComplete(java.util.Map)
+ */
+ public void clusterStatusComplete(Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
+ {
+ HAPartition partition = this.coord.getHAPartition();
+ ClusterNode cn = partition.getClusterNode();
+ PeerMCMPDiscoveryStatus newStatus = statuses.get(cn);
+ if (newStatus != null)
+ {
+ // Notify our handler that discovery events have been processed
+ this.coord.clusteredHandler.discoveryEventsReceived(newStatus.getLatestDiscoveryEvent());
+
+ // Notify our handler that any reset requests have been processed
+ this.coord.clusteredHandler.recordResetSuccess();
+
+ DistributedReplicantManager drm = partition.getDistributedReplicantManager();
+ String key = this.coord.getHAServiceKey();
+ ModClusterServiceDRMEntry oldStatus = (ModClusterServiceDRMEntry) drm.lookupLocalReplicant(key);
+ if (!newStatus.equals(oldStatus))
+ {
+ try
+ {
+ drm.add(key, new ModClusterServiceDRMEntry(cn, newStatus.getMCMPServerStates(), oldStatus.getJvmRoutes()));
+ }
+ catch (Exception e)
+ {
+ this.coord.log.error(HAModClusterService.this.sm.getString("modcluster.error.drm"), e);
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#getProxyConfiguration()
+ */
+ public GroupRpcResponse getProxyConfiguration()
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ ClusterNode node = HAModClusterService.this.getHAPartition().getClusterNode();
+ String configuration = this.coord.localHandler.getProxyConfiguration();
+
+ return new StringGroupRpcResponse(node, configuration);
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#getProxyInfo()
+ */
+ public GroupRpcResponse getProxyInfo()
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ ClusterNode node = HAModClusterService.this.getHAPartition().getClusterNode();
+ String info = this.coord.localHandler.getProxyInfo();
+
+ return new StringGroupRpcResponse(node, info);
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#isProxyHealthOK()
+ */
+ public GroupRpcResponse isProxyHealthOK()
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ ClusterNode node = HAModClusterService.this.getHAPartition().getClusterNode();
+ boolean ok = this.coord.localHandler.isProxyHealthOK();
+
+ return new BooleanGroupRpcResponse(node, ok);
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#markProxiesInError()
+ */
+ public GroupRpcResponse markProxiesInError()
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ this.coord.localHandler.markProxiesInError();
+
+ return this.SUCCESS;
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#reset()
+ */
+ public GroupRpcResponse reset()
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ this.coord.localHandler.reset();
+
+ return this.SUCCESS;
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#sendRequest(org.jboss.modcluster.mcmp.MCMPRequest)
+ */
+ public GroupRpcResponse sendRequest(MCMPRequest request)
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ this.coord.localHandler.sendRequest(request);
+
+ return this.SUCCESS;
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler#sendRequests(java.util.List)
+ */
+ public GroupRpcResponse sendRequests(List<MCMPRequest> requests)
+ {
+ if (!this.coord.isMasterNode()) return null;
+
+ this.coord.localHandler.sendRequests(requests);
+
+ return this.SUCCESS;
+ }
+
+ /**
+ * @see org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
+ */
+ public GroupRpcResponse getResetRequests(Map<String, Set<ResetRequestSource.VirtualHost>> response)
+ {
+ ClusterNode node = HAModClusterService.this.getHAPartition().getClusterNode();
+ List<MCMPRequest> requests = this.coord.resetRequestSource.getLocalResetRequests(response);
+
+ return new ResetRequestGroupRpcResponse(node, requests);
+ }
+ }
+
+ private class ClusteredJBossWebEventHandler extends DefaultJBossWebEventHandler
+ {
+ private final HAModClusterService coord = HAModClusterService.this;
+
+ /**
+ * Create a new ClusteredJBossWebEventHandler.
+ *
+ * @param config
+ * @param loadFactorProvider
+ */
+ public ClusteredJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig,
+ MCMPHandlerConfiguration mcmpConfig, MCMPHandler clusteredHandler, LoadBalanceFactorProviderFactory loadFactorProviderFactory)
+ {
+ super(nodeConfig, balancerConfig, mcmpConfig, clusteredHandler, loadFactorProviderFactory);
+ }
+
+ @Override
+ public void startServer(Server server)
+ {
+ // Pass on ref to our server
+ this.coord.resetRequestSource.setJbossWebServer(server);
+
+ super.startServer(server);
+ }
+
+ @Override
+ protected void config(Engine engine)
+ {
+ this.config(engine, this.coord.localHandler);
+ }
+
+ @Override
+ protected void jvmRouteEstablished(Engine engine)
+ {
+ this.coord.drmEntry.addJvmRoute(engine.getJvmRoute());
+ this.coord.updateLocalDRM(this.coord.drmEntry);
+ }
+
+ @Override
+ protected void removeAll(Engine engine)
+ {
+ super.removeAll(engine);
+
+ this.coord.drmEntry.removeJvmRoute(engine.getJvmRoute());
+ this.coord.updateLocalDRM(this.coord.drmEntry);
+ }
+
+ @Override
+ public void status(Engine engine)
+ {
+ this.checkInit();
+
+ log.debug(this.coord.sm.getString("modcluster.engine.status", engine.getName()));
+
+ this.coord.latestLoad = this.getLoadBalanceFactor();
+
+ if (this.coord.isMasterNode())
+ {
+ this.coord.statusCount = (this.coord.statusCount + 1) % this.coord.processStatusFrequency;
+
+ if (this.coord.statusCount == 0)
+ {
+ this.updateClusterStatus();
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ void updateClusterStatus()
+ {
+ Set<MCMPServerState> masterList = null;
+ Map<ClusterNode, MCMPServerDiscoveryEvent> latestEvents = null;
+ Map<ClusterNode, ModClusterServiceDRMEntry> nonresponsive = new HashMap<ClusterNode, ModClusterServiceDRMEntry>();
+ Map<String, Integer> loadBalanceFactors = new HashMap<String, Integer>();
+ Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses = new HashMap<ClusterNode, PeerMCMPDiscoveryStatus>();
+ List<MCMPRequest> resetRequests = new ArrayList<MCMPRequest>();
+ HAPartition partition = this.coord.getHAPartition();
+ DistributedReplicantManager drm = partition.getDistributedReplicantManager();
+ boolean resync = false;
+
+ do
+ {
+ resync = false;
+
+ this.coord.localHandler.status();
+
+ synchronized (this.coord.proxyChangeDigest)
+ {
+ masterList = this.coord.localHandler.getProxyStates();
+ latestEvents = new HashMap<ClusterNode, MCMPServerDiscoveryEvent>(this.coord.proxyChangeDigest);
+ }
+
+ List<ModClusterServiceDRMEntry> replicants = drm.lookupReplicants(this.coord.getHAServiceKey());
+ nonresponsive.clear();
+
+ for (ModClusterServiceDRMEntry replicant: replicants)
+ {
+ nonresponsive.put(replicant.getPeer(), replicant);
+ }
+ nonresponsive.remove(partition.getClusterNode());
+
+ // FIXME -- what about our own dropped discovery events if we just became master?
+ List responses = this.coord.getClusterCoordinatorState(masterList);
+
+ // Gather up all the reset requests in one list
+ // FIXME -- what about our own dropped requests if we just became master?
+ resetRequests.clear();
+
+ // Gather all the load balance factors
+ loadBalanceFactors.clear();
+
+ // Add our own lbf - it is not returned via getclusterCoordinatorState(...)
+ for (String jvmRoute: this.coord.drmEntry.getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, Integer.valueOf(this.coord.latestLoad));
+ }
+
+ // Gather the info on who knows about what proxies
+ statuses.clear();
+
+ for (Object response: responses)
+ {
+ if (response instanceof ModClusterServiceStateGroupRpcResponse)
+ {
+ ModClusterServiceStateGroupRpcResponse mcssgrr = (ModClusterServiceStateGroupRpcResponse) response;
+ ClusterNode cn = mcssgrr.getSender();
+
+ // Check for discovery events we haven't processed
+ MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
+
+ for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
+ {
+ if (latestEvent != null && latestEvent.getEventIndex() <= toCheck.getEventIndex())
+ {
+ continue; // already processed it
+ }
+
+ AddressPort ap = toCheck.getMCMPServer();
+ if (toCheck.isAddition())
+ {
+ this.coord.localHandler.addProxy(ap.getAddress(), ap.getPort());
+ }
+ else
+ {
+ this.coord.localHandler.removeProxy(ap.getAddress(), ap.getPort());
+ }
+ resync = true;
+ }
+
+ if (!resync) // don't bother if we are going to start over
+ {
+ statuses.put(cn, new PeerMCMPDiscoveryStatus(cn, mcssgrr.getStates(), latestEvent));
+
+ List<MCMPRequest> toAdd = mcssgrr.getResetRequests();
+ if (toAdd != null)
+ {
+ resetRequests.addAll(toAdd);
+ }
+
+ ModClusterServiceDRMEntry removed = nonresponsive.remove(cn);
+ if (removed != null)
+ {
+ Integer lbf = Integer.valueOf(mcssgrr.getLoadBalanceFactor());
+ for (String jvmRoute: removed.getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, lbf);
+ }
+ }
+ }
+ }
+ else if (response instanceof ThrowableGroupRpcResponse)
+ {
+ ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
+ ClusterNode cn = tgrr.getSender();
+
+ log.warn(this.coord.sm.getString("modcluster.error.rpc.known", "getClusterCoordinatorState", cn), tgrr.getValue());
+
+ // Don't remove from nonresponsive list and we'll pass back an error
+ // status (null server list) to this peer
+ }
+ else if (response instanceof Throwable)
+ {
+ log.warn(this.coord.sm.getString("modcluster.error.rpc.unknown", "getClusterCoordinatorState"), (Throwable) response);
+ }
+ else
+ {
+ log.error(this.coord.sm.getString("modcluster.error.rpc.unexpected", response, "getClusterCoordinatorState"));
+ }
+ }
+ }
+ // We picked up previously unknown discovery events; start over
+ while (resync);
+
+ // Add error-state objects for non-responsive peers
+ Integer lbf = Integer.valueOf(0);
+ for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry: nonresponsive.entrySet())
+ {
+ ClusterNode cn = entry.getKey();
+ statuses.put(entry.getKey(), new PeerMCMPDiscoveryStatus(cn, null, latestEvents.get(cn)));
+
+ for (String jvmRoute: entry.getValue().getJvmRoutes())
+ {
+ loadBalanceFactors.put(jvmRoute, lbf);
+ }
+ }
+ // FIXME handle crashed members, gone from DRM
+
+ // Advise the proxies of any reset requests
+ this.coord.localHandler.sendRequests(resetRequests);
+
+ // Pass along the LBF values
+ List<MCMPRequest> statusRequests = new ArrayList<MCMPRequest>();
+ for (Map.Entry<String, Integer> entry: loadBalanceFactors.entrySet())
+ {
+ statusRequests.add(MCMPUtils.createStatusRequest(entry.getKey(), entry.getValue().intValue()));
+ }
+ this.coord.localHandler.sendRequests(statusRequests);
+
+ // Advise the members the process is done and that they should update DRM
+ this.notifyClusterStatusComplete(masterList, statuses);
+ }
+
+ private void notifyClusterStatusComplete(Set<MCMPServerState> masterList, Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
+ {
+ HAPartition partition = this.coord.getHAPartition();
+
+ // Determine who should update DRM first -- us or the rest of the nodes
+ Set<ModClusterServiceDRMEntry> allStatuses = new HashSet<ModClusterServiceDRMEntry>(statuses.values());
+ DistributedReplicantManager drm = partition.getDistributedReplicantManager();
+ ModClusterServiceDRMEntry ourCurrentStatus = (ModClusterServiceDRMEntry) drm.lookupLocalReplicant(this.coord.getHAServiceKey());
+ allStatuses.add(ourCurrentStatus);
+
+ ClusterNode node = partition.getClusterNode();
+
+ boolean othersFirst = this.coord.narrowCandidateList(allStatuses).contains(node);
+ ModClusterServiceDRMEntry newStatus = new ModClusterServiceDRMEntry(node, masterList, this.coord.drmEntry.getJvmRoutes());
+ boolean updated = !newStatus.equals(ourCurrentStatus);
+
+ if (othersFirst)
+ {
+ this.coord.clusterStatusComplete(statuses);
+ }
+
+ if (updated)
+ {
+ this.coord.updateLocalDRM(newStatus);
+ }
+
+ if (!othersFirst)
+ {
+ this.coord.clusterStatusComplete(statuses);
+ }
+ }
+ }
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterServiceMBean.java (from rev 2062, trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterServiceMBean.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterServiceMBean.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterServiceMBean.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,38 @@
+/*
+ * 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.ha;
+
+import org.jboss.ha.framework.interfaces.HASingletonMBean;
+import org.jboss.modcluster.ModClusterServiceMBean;
+
+/**
+ * StandardMBean interface for {@link HAModClusterService}.
+ *
+ * @author Brian Stansberry
+ */
+public interface HAModClusterServiceMBean extends HASingletonMBean, ModClusterServiceMBean
+{
+ int getProcessStatusFrequency();
+
+ void setProcessStatusFrequency(int processStatusFrequency);
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterServiceMBean.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/main/resources/mod-cluster-jboss-beans.xml 2008-12-02 20:56:39 UTC (rev 2088)
@@ -4,43 +4,54 @@
beans are all "On Demand", i.e. that are not installed unless requested.
-->
<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- The core HAModClusterService, for use in clustered environments -->
+ <bean name="HAModClusterService" class="org.jboss.modcluster.ha.HAModClusterService" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ModCluster",exposedInterface=org.jboss.modcluster.ha.HAModClusterServiceMBean.class)</annotation>
+ <constructor>
+ <parameter><inject bean="HAPartition"/></parameter>
+ <parameter><inject bean="HAModClusterConfig"/></parameter>
+ <parameter><inject bean="DynamicLoadBalanceFactorProvider"/></parameter>
+ <parameter><bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"/></parameter>
+ </constructor>
+ </bean>
<!-- Configure this node's communication with the load balancer -->
- <bean name="ModClusterConfig" class="org.jboss.modcluster.config.ModClusterConfig" mode="On Demand">
-
- <!-- Comma separated list of address:port listing the httpd servers
- where mod_cluster is running. -->
- <!--property name="proxyList"></property-->
- <!-- URL prefix to send with commands to mod_cluster. Default is no prefix. -->
- <!--property name="proxyURL"></property-->
-
- <!-- mod_advertise is a small httpd module that advertises the
- availability of httpd servers via multicast, allowing
- ModClusterService to discover the httpd front-end instead of/in
- addition to having them defined in proxyList. -->
- <!-- Whether to listen for advertise messages -->
- <property name="advertise">true</property>
- <!-- Multicast address on which to listen for advertisements -->
- <property name="advertiseGroupAddress">${jboss.modcluster.advertise.address,jboss.partition.udpGroup:224.0.1.105}</property>
- <!-- Port to listen to for advertisements -->
- <property name="advertisePort">${jboss.modcluster.advertise.address:23364}</property>
-
- <!-- Security key the proxy is going to send with advertise messages.
- Default is none. -->
- <!--property name="advertiseSecurityKey"></property-->
-
- <!-- Whether to use SSL to communicate with mod_cluster. Note this
- has nothing to do with handling of https requests by JBoss Web -->
- <property name="ssl">false</property>
-
- <!-- Configuration values for the load balancer itself (must be the
- same on all nodes in the cluster). These will be passed to the
- load balancer. -->
- <property name="stickySession">true</property>
- <property name="stickySessionForce">false</property>
- <property name="stickySessionRemove">false</property>
- <property name="maxAttempts">-1</property>
- <property name="workerTimeout">-1</property>
+ <bean name="HAModClusterConfig" class="org.jboss.modcluster.config.ha.HAModClusterConfig" mode="On Demand">
+
+ <!-- Comma separated list of address:port listing the httpd servers
+ where mod_cluster is running. -->
+ <!--property name="proxyList"></property-->
+ <!-- URL prefix to send with commands to mod_cluster. Default is no prefix. -->
+ <!--property name="proxyURL"></property-->
+
+ <!-- mod_advertise is a small httpd module that advertises the
+ availability of httpd servers via multicast, allowing
+ ModClusterService to discover the httpd front-end instead of/in
+ addition to having them defined in proxyList. -->
+ <!-- Whether to listen for advertise messages -->
+ <property name="advertise">true</property>
+ <!-- Multicast address on which to listen for advertisements -->
+ <property name="advertiseGroupAddress">${jboss.modcluster.advertise.address,jboss.partition.udpGroup:224.0.1.105}</property>
+ <!-- Port to listen to for advertisements -->
+ <property name="advertisePort">${jboss.modcluster.advertise.address:23364}</property>
+
+ <!-- Security key the proxy is going to send with advertise messages.
+ Default is none. -->
+ <!--property name="advertiseSecurityKey"></property-->
+
+ <!-- Whether to use SSL to communicate with mod_cluster. Note this
+ has nothing to do with handling of https requests by JBoss Web -->
+ <property name="ssl">false</property>
+
+ <!-- Configuration values for the load balancer itself (must be the
+ same on all nodes in the cluster). These will be passed to the
+ load balancer. -->
+ <property name="stickySession">true</property>
+ <property name="stickySessionForce">false</property>
+ <property name="stickySessionRemove">false</property>
+ <property name="maxAttempts">-1</property>
+ <property name="workerTimeout">-1</property>
</bean>
<!-- Provides information to ModClusterService informing it how much load
@@ -91,27 +102,48 @@
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=HeapMemoryUsageLoadMetric",exposedInterface=org.jboss.modcluster.load.metric.LoadMetricMBean.class)</annotation>
<!--property name="weight">1</property-->
</bean>
-
- <!-- The core ModClusterService -->
+
+
+ <!-- The core ModClusterService, for use in non-clustered environments -->
<bean name="ModClusterService" class="org.jboss.modcluster.ModClusterService" mode="On Demand">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=ModCluster",exposedInterface=org.jboss.modcluster.ModClusterServiceMBean.class)</annotation>
<constructor>
- <parameter><inject bean="HAPartition"/></parameter>
- <parameter><inject bean="ModClusterConfig"/></parameter>
<parameter><inject bean="DynamicLoadBalanceFactorProvider"/></parameter>
- <parameter><bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"/></parameter>
</constructor>
+ <!-- Comma separated list of address:port listing the httpd servers
+ where mod_cluster is running. -->
+ <!--property name="proxyList"></property-->
+ <!-- URL prefix to send with commands to mod_cluster. Default is no prefix. -->
+ <!--property name="proxyURL"></property-->
+
+ <!-- mod_advertise is a small httpd module that advertises the
+ availability of httpd servers via multicast, allowing
+ ModClusterService to discover the httpd front-end instead of/in
+ addition to having them defined in proxyList. -->
+ <!-- Whether to listen for advertise messages -->
+ <property name="advertise">true</property>
+ <!-- Multicast address on which to listen for advertisements -->
+ <property name="advertiseGroupAddress">${jboss.modcluster.advertise.address,jboss.partition.udpGroup:224.0.1.105}</property>
+ <!-- Port to listen to for advertisements -->
+ <property name="advertisePort">${jboss.modcluster.advertise.address:23364}</property>
+
+ <!-- Security key the proxy is going to send with advertise messages.
+ Default is none. -->
+ <!--property name="advertiseSecurityKey"></property-->
+
+ <!-- Whether to use SSL to communicate with mod_cluster. Note this
+ has nothing to do with handling of https requests by JBoss Web -->
+ <property name="ssl">false</property>
+
+ <!-- Configuration values for the load balancer itself (must be the
+ same on all nodes in the cluster). These will be passed to the
+ load balancer. -->
+ <property name="stickySession">true</property>
+ <property name="stickySessionForce">false</property>
+ <property name="stickySessionRemove">false</property>
+ <property name="maxAttempts">-1</property>
+ <property name="workerTimeout">-1</property>
</bean>
-
- <!--
- An org.apache.catalina.LifecycleListener impl that notifies
- ModClusterService of events inside JBoss Web (deployments, starts, stops. etc.)
- -->
- <bean name="ModClusterLifecycleListener" class="org.jboss.modcluster.BasicClusterListener" mode="On Demand">
- <constructor>
- <parameter><inject bean="ModClusterService"/></parameter>
- </constructor>
- </bean>
<!-- Alternative load balance factor providers -->
@@ -120,7 +152,8 @@
This would replace the DynamicLoadBalanceFactorProvider
used above.
-->
- <bean name="StaticLoadBalanceFactorProvider" class="org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProvider" mode="On Demand">
+ <bean name="SimpleLoadBalanceFactorProvider" class="org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider" mode="On Demand">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.web:service=LoadBalanceFactorProvider",exposedInterface=org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProviderMBean.class)</annotation>
<property name="loadBalanceFactor">1</property>
</bean>
Deleted: trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,269 +0,0 @@
-/*
- * 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 org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-public class BasicClusterListenerTestCase
-{
- private JBossWebEventHandler eventHandler = EasyMock.createStrictMock(JBossWebEventHandler.class);
-
- private BasicClusterListener listener = new BasicClusterListener(this.eventHandler);
-
- @Test
- public void deployWebApp()
- {
- 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);
- }
-
- @Test
- public void deployHost()
- {
- 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);
- }
-
- @Test
- public void undeployWebApp()
- {
- 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);
- }
-
- @Test
- public void undeployHost()
- {
- 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);
- }
-
- @Test
- public void startWebApp()
- {
- 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);
- }
-
- @Test
- public void startServer()
- {
- 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);
- }
-
- @Test
- public void stopWebApp()
- {
- 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);
- }
-
- @Test
- public void stopServer()
- {
- 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);
- }
-
- @Test
- public void periodicEvent()
- {
- 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.startServer();
-
- // 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
- {
- }
-}
Deleted: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,250 +0,0 @@
-/*
- * 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 javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.apache.catalina.Container;
-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.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;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-@SuppressWarnings("boxing")
-public class ClusterListenerTestCase
-{
- 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);
-
- @Test
- public void getProxyConfiguration()
- {
- EasyMock.expect(this.mcmpHandler.getProxyConfiguration()).andReturn("config");
-
- EasyMock.replay(this.mcmpHandler);
-
- String result = this.listener.getProxyConfiguration();
-
- EasyMock.verify(this.mcmpHandler);
-
- Assert.assertEquals("config", result);
-
- EasyMock.reset(this.mcmpHandler);
- }
-
- @Test
- public void reset()
- {
- this.mcmpHandler.reset();
-
- EasyMock.replay(this.mcmpHandler);
-
- this.listener.reset();
-
- EasyMock.verify(this.mcmpHandler);
- EasyMock.reset(this.mcmpHandler);
- }
-
- @Test
- public void refresh()
- {
- this.mcmpHandler.markProxiesInError();
-
- EasyMock.replay(this.mcmpHandler);
-
- this.listener.refresh();
-
- EasyMock.verify(this.mcmpHandler);
- EasyMock.reset(this.mcmpHandler);
- }
-
- @Test
- public void enable()
- {
- 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);
-
- Assert.assertTrue(result);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- EasyMock.reset(this.mcmpHandler, server, service, engine);
- }
-
- @Test
- public void disable()
- {
- 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);
-
- Assert.assertTrue(result);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- EasyMock.reset(this.mcmpHandler, server, service, engine);
- }
-
- @Test
- public void containerEvent()
- {
- 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);
- }
-
- @Test
- public void startServerLifecycleEvent() 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");
-
- Assert.assertTrue(registry.getMBeanServer().isRegistered(name));
-
- EasyMock.reset(this.lifecycleListener, server);
- }
-
- @Test
- public void stopServerLifecycleEvent() 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");
-
- Assert.assertFalse(registry.getMBeanServer().isRegistered(name));
-
- EasyMock.reset(this.lifecycleListener, server);
- }
-
- @Test
- public void otherLifecycleEvent()
- {
- 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();
- }
-}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -43,6 +43,7 @@
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.load.LoadBalanceFactorProviderFactory;
import org.jboss.modcluster.mcmp.AddressPort;
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
@@ -63,7 +64,8 @@
private final BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
private final MCMPHandlerConfiguration mcmpConfig = EasyMock.createStrictMock(MCMPHandlerConfiguration.class);
private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
- private final LoadBalanceFactorProvider provider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
+ private final LoadBalanceFactorProviderFactory lbfProviderFactory = EasyMock.createStrictMock(LoadBalanceFactorProviderFactory.class);
+ private final LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
private final AdvertiseListenerFactory listenerFactory = EasyMock.createStrictMock(AdvertiseListenerFactory.class);
private JBossWebEventHandler handler;
@@ -71,7 +73,7 @@
@Before
public void construct() throws Exception
{
- this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.provider, this.listenerFactory);
+ this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.lbfProviderFactory, this.listenerFactory);
}
@Test
@@ -87,14 +89,16 @@
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+ EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
+
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.FALSE);
- EasyMock.replay(this.mcmpHandler, this.mcmpConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.mcmpConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.mcmpConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.reset(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
// Test advertise = true
@@ -102,18 +106,20 @@
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+ EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
+
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.TRUE);
EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
// Test advertise = null, proxies configured
@@ -121,14 +127,16 @@
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+ EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
+
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
- EasyMock.replay(this.mcmpHandler, this.mcmpConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.mcmpConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.mcmpConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.reset(this.mcmpHandler, this.mcmpConfig, this.lbfProviderFactory, listener);
// Test advertise = null, no proxies configured
@@ -138,18 +146,20 @@
this.mcmpHandler.init(emptyList);
+ EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
+
EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler, this.mcmpConfig)).andReturn(listener);
listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
}
@Test
@@ -165,15 +175,16 @@
EasyMock.verify(this.mcmpHandler);
EasyMock.reset(this.mcmpHandler);
-
// Test w/advertise listener
// First init() to create listener
+ this.init();
InetAddress localAddress = InetAddress.getLocalHost();
String localHostName = localAddress.getHostName();
AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
+ EasyMock.expect(this.lbfProviderFactory.createLoadBalanceFactorProvider()).andReturn(this.lbfProvider);
this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
@@ -183,12 +194,12 @@
listener.start();
- EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
this.handler.init();
- EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
- EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, this.lbfProviderFactory, listener);
// Now test shutdown()
listener.destroy();
@@ -555,16 +566,16 @@
this.mcmpHandler.status();
- EasyMock.expect(this.provider.getLoadBalanceFactor()).andReturn(10);
+ EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.replay(this.mcmpHandler, this.provider, engine);
+ EasyMock.replay(this.mcmpHandler, this.lbfProvider, engine);
this.handler.status(engine);
- EasyMock.verify(this.mcmpHandler, this.provider, engine);
+ EasyMock.verify(this.mcmpHandler, this.lbfProvider, engine);
MCMPRequest request = capturedRequest.getValue();
@@ -577,7 +588,7 @@
Assert.assertEquals(1, parameters.size());
Assert.assertEquals("10", parameters.get("Load"));
- EasyMock.reset(this.mcmpHandler, this.provider, engine);
+ EasyMock.reset(this.mcmpHandler, this.lbfProvider, engine);
}
@Test
Copied: trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java (from rev 2062, trunk/mod_cluster/src/test/java/org/jboss/modcluster/BasicClusterListenerTestCase.java)
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,269 @@
+/*
+ * 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 org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class JBossWebEventHandlerAdapterTestCase
+{
+ private JBossWebEventHandler eventHandler = EasyMock.createStrictMock(JBossWebEventHandler.class);
+
+ private JBossWebEventHandlerAdapter adapter = new JBossWebEventHandlerAdapter(this.eventHandler);
+
+ @Test
+ public void deployWebApp()
+ {
+ 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.adapter);
+ this.eventHandler.addContext(context);
+
+ EasyMock.replay(this.eventHandler, host, context);
+
+ this.adapter.containerEvent(event);
+
+ EasyMock.verify(this.eventHandler, host, context);
+ EasyMock.reset(this.eventHandler, host, context);
+ }
+
+ @Test
+ public void deployHost()
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ ContainerEvent event = new ContainerEvent(engine, Container.ADD_CHILD_EVENT, null);
+
+ engine.addContainerListener(this.adapter);
+
+ EasyMock.replay(engine);
+
+ this.adapter.containerEvent(event);
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
+ }
+
+ @Test
+ public void undeployWebApp()
+ {
+ 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.adapter);
+ this.eventHandler.removeContext(context);
+
+ EasyMock.replay(this.eventHandler, host, context);
+
+ this.adapter.containerEvent(event);
+
+ EasyMock.verify(this.eventHandler, host, context);
+ EasyMock.reset(this.eventHandler, host, context);
+ }
+
+ @Test
+ public void undeployHost()
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ ContainerEvent event = new ContainerEvent(engine, Container.REMOVE_CHILD_EVENT, null);
+
+ engine.removeContainerListener(this.adapter);
+
+ EasyMock.replay(engine);
+
+ this.adapter.containerEvent(event);
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
+ }
+
+ @Test
+ public void startWebApp()
+ {
+ LifecycleContext context = EasyMock.createStrictMock(LifecycleContext.class);
+
+ LifecycleEvent event = new LifecycleEvent(context, Lifecycle.START_EVENT);
+
+ this.eventHandler.startContext(context);
+
+ EasyMock.replay(this.eventHandler);
+
+ this.adapter.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler);
+ EasyMock.reset(this.eventHandler);
+ }
+
+ @Test
+ public void startServer()
+ {
+ 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.adapter);
+ engine.addLifecycleListener(this.adapter);
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+
+ container.addContainerListener(this.adapter);
+
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { childContainer });
+
+ childContainer.addLifecycleListener(this.adapter);
+
+ this.eventHandler.startServer(server);
+
+ EasyMock.replay(this.eventHandler, server, service, engine, container, childContainer);
+
+ this.adapter.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler, server, service, engine, container, childContainer);
+ EasyMock.reset(this.eventHandler, server, service, engine, container, childContainer);
+ }
+
+ @Test
+ public void stopWebApp()
+ {
+ LifecycleContext context = EasyMock.createStrictMock(LifecycleContext.class);
+
+ LifecycleEvent event = new LifecycleEvent(context, Lifecycle.STOP_EVENT);
+
+ this.eventHandler.stopContext(context);
+
+ EasyMock.replay(this.eventHandler);
+
+ this.adapter.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler);
+ EasyMock.reset(this.eventHandler);
+ }
+
+ @Test
+ public void stopServer()
+ {
+ 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.adapter);
+ engine.removeLifecycleListener(this.adapter);
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+
+ container.removeContainerListener(this.adapter);
+
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { childContainer });
+
+ childContainer.removeLifecycleListener(this.adapter);
+
+ this.eventHandler.stopServer(server);
+ this.eventHandler.shutdown();
+
+ EasyMock.replay(this.eventHandler, server, service, engine, container, childContainer);
+
+ this.adapter.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler, server, service, engine, container, childContainer);
+ EasyMock.reset(this.eventHandler, server, service, engine, container, childContainer);
+ }
+
+ @Test
+ public void periodicEvent()
+ {
+ LifecycleEngine engine = EasyMock.createStrictMock(LifecycleEngine.class);
+
+ LifecycleEvent event = new LifecycleEvent(engine, Lifecycle.PERIODIC_EVENT);
+
+ // Test uninitialized
+ EasyMock.replay(this.eventHandler);
+
+ this.adapter.lifecycleEvent(event);
+
+ EasyMock.verify(this.eventHandler);
+ EasyMock.reset(this.eventHandler);
+
+ // Init
+ this.startServer();
+
+ // Test initialized
+ this.eventHandler.status(engine);
+
+ EasyMock.replay(this.eventHandler);
+
+ this.adapter.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
+ {
+ }
+}
Property changes on: trunk/mod_cluster/src/test/java/org/jboss/modcluster/JBossWebEventHandlerAdapterTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterListenerTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,245 @@
+/*
+ * 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.Collection;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Service;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProviderMBean;
+import org.jboss.modcluster.load.metric.LoadMetricMBean;
+import org.jboss.modcluster.load.metric.impl.ActiveSessionsLoadMetric;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ModClusterListenerTestCase
+{
+ private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
+
+ private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private final LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
+
+ private final ModClusterListener listener = new ModClusterListener(this.mcmpHandler, this.lifecycleListener);
+
+ @Test
+ public void createLoadBalanceFactorProvider()
+ {
+ this.listener.setLoadMetricClass(ActiveSessionsLoadMetric.class);
+ this.listener.setLoadMetricCapacity(100);
+ this.listener.setLoadDecayFactor(3);
+ this.listener.setLoadHistory(5);
+
+ LoadBalanceFactorProvider result = this.listener.createLoadBalanceFactorProvider();
+
+ Assert.assertTrue(result instanceof DynamicLoadBalanceFactorProviderMBean);
+
+ DynamicLoadBalanceFactorProviderMBean lbfProvider = (DynamicLoadBalanceFactorProviderMBean) result;
+
+ Assert.assertEquals(3, lbfProvider.getDecayFactor());
+ Assert.assertEquals(5, lbfProvider.getHistory());
+
+ Collection<LoadMetricMBean> metrics = lbfProvider.getMetrics();
+ Assert.assertEquals(1, metrics.size());
+
+ LoadMetricMBean metric = metrics.iterator().next();
+ Assert.assertEquals(100, metric.getCapacity(), 0);
+ Assert.assertEquals(1, metric.getWeight());
+ }
+
+ @Test
+ public void lifecycleEvent()
+ {
+ LifecycleEvent event = new LifecycleEvent(EasyMock.createMock(Lifecycle.class), Lifecycle.INIT_EVENT);
+
+ this.lifecycleListener.lifecycleEvent(event);
+
+ EasyMock.replay(this.lifecycleListener);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.lifecycleListener);
+ EasyMock.reset(this.lifecycleListener);
+ }
+
+ @Test
+ public void addProxy()
+ {
+ this.mcmpHandler.addProxy("host", 100);
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.addProxy("host", 100);
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void removeProxy()
+ {
+ this.mcmpHandler.removeProxy("host", 100);
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.removeProxy("host", 100);
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void getProxyConfiguration()
+ {
+ EasyMock.expect(this.mcmpHandler.getProxyConfiguration()).andReturn("config");
+
+ EasyMock.replay(this.mcmpHandler);
+
+ String result = this.listener.getProxyConfiguration();
+
+ EasyMock.verify(this.mcmpHandler);
+
+ Assert.assertEquals("config", result);
+
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void getProxyInfo()
+ {
+ EasyMock.expect(this.mcmpHandler.getProxyInfo()).andReturn("info");
+
+ EasyMock.replay(this.mcmpHandler);
+
+ String result = this.listener.getProxyInfo();
+
+ EasyMock.verify(this.mcmpHandler);
+
+ Assert.assertEquals("info", result);
+
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void reset()
+ {
+ this.mcmpHandler.reset();
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.reset();
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void refresh()
+ {
+ this.mcmpHandler.markProxiesInError();
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.refresh();
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void enable()
+ {
+ 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);
+
+ Assert.assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ EasyMock.reset(this.mcmpHandler, server, service, engine);
+ }
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void disable()
+ {
+ 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);
+
+ Assert.assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ EasyMock.reset(this.mcmpHandler, server, service, engine);
+ }
+}
Deleted: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -1,920 +0,0 @@
-/*
- * 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.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.catalina.Container;
-import org.apache.catalina.Context;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Host;
-import org.apache.catalina.Server;
-import org.apache.catalina.Service;
-import org.apache.catalina.connector.Connector;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.jboss.ha.framework.interfaces.ClusterNode;
-import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
-import org.jboss.ha.framework.interfaces.HAPartition;
-import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
-import org.jboss.modcluster.advertise.AdvertiseListener;
-import org.jboss.modcluster.config.BalancerConfiguration;
-import org.jboss.modcluster.config.MCMPHandlerConfiguration;
-import org.jboss.modcluster.config.NodeConfiguration;
-import org.jboss.modcluster.ha.ClusteredMCMPHandler;
-import org.jboss.modcluster.ha.HASingletonAwareResetRequestSource;
-import org.jboss.modcluster.ha.ModClusterServiceDRMEntry;
-import org.jboss.modcluster.ha.rpc.MCMPServerDiscoveryEvent;
-import org.jboss.modcluster.ha.rpc.ModClusterServiceStateGroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.PeerMCMPDiscoveryStatus;
-import org.jboss.modcluster.load.LoadBalanceFactorProvider;
-import org.jboss.modcluster.mcmp.AddressPort;
-import org.jboss.modcluster.mcmp.MCMPHandler;
-import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPRequestType;
-import org.jboss.modcluster.mcmp.MCMPServerState;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-@SuppressWarnings("boxing")
-public class ModClusterServiceTestCase
-{
- private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
- private NodeConfiguration nodeConfig = EasyMock.createMock(NodeConfiguration.class);
- private BalancerConfiguration balancerConfig = EasyMock.createMock(BalancerConfiguration.class);
- private MCMPHandlerConfiguration mcmpConfig = EasyMock.createMock(MCMPHandlerConfiguration.class);
- private MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
- private HASingletonAwareResetRequestSource resetRequestSource = EasyMock.createStrictMock(HASingletonAwareResetRequestSource.class);
- private ClusteredMCMPHandler clusteredMCMPHandler = EasyMock.createStrictMock(ClusteredMCMPHandler.class);
- private LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
- private HASingletonElectionPolicy electionPolicy = EasyMock.createStrictMock(HASingletonElectionPolicy.class);
- private ClusterNode node = EasyMock.createStrictMock(ClusterNode.class);
-
- private static final boolean MASTER_PER_DOMAIN = true;
- private static final String SERVICE_HA_NAME = "myservice";
- private static final String DOMAIN = "domain";
-
- private ModClusterService modClusterService;
-
- @Before
- public void setUp() throws Exception
- {
- EasyMock.expect(this.mcmpConfig.isMasterPerDomain()).andReturn(MASTER_PER_DOMAIN);
- EasyMock.expect(this.nodeConfig.getDomain()).andReturn(DOMAIN);
-
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node).times(2);
-
- EasyMock.replay(this.mcmpConfig, this.nodeConfig, this.partition);
-
- this.modClusterService = new ModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.resetRequestSource, this.clusteredMCMPHandler, this.lbfProvider, this.electionPolicy);
- this.modClusterService.setServiceHAName(SERVICE_HA_NAME);
-
- EasyMock.verify(this.mcmpConfig, this.nodeConfig, this.partition);
- EasyMock.reset(this.mcmpConfig, this.nodeConfig, this.partition);
- }
-
- @Test
- public void addProxy()
- {
- String host = "127.0.0.1";
- int port = 0;
-
- this.clusteredMCMPHandler.addProxy(host, port);
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.modClusterService.addProxy(host, port);
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void removeProxy()
- {
- String host = "127.0.0.1";
- int port = 0;
-
- this.clusteredMCMPHandler.removeProxy(host, port);
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.modClusterService.removeProxy(host, port);
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void getProxyConfiguration()
- {
- EasyMock.expect(this.clusteredMCMPHandler.getProxyConfiguration()).andReturn("configuration");
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- String result = this.modClusterService.getProxyConfiguration();
-
- EasyMock.verify(this.clusteredMCMPHandler);
-
- Assert.assertEquals("configuration", result);
-
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void reset()
- {
- this.clusteredMCMPHandler.reset();
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.modClusterService.reset();
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void refresh()
- {
- this.clusteredMCMPHandler.markProxiesInError();
-
- EasyMock.replay(this.clusteredMCMPHandler);
-
- this.modClusterService.refresh();
-
- EasyMock.verify(this.clusteredMCMPHandler);
- EasyMock.reset(this.clusteredMCMPHandler);
- }
-
- @Test
- public void init() throws UnknownHostException
- {
- InetAddress localAddress = InetAddress.getLocalHost();
- String localHostName = localAddress.getHostName();
-
- AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
-
- // Test advertise = false
- EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
-
- this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
-
- EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.FALSE);
-
- EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
-
- this.modClusterService.init();
-
- EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
- EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
-
-
- // Test advertise = null, proxies configured
- EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
-
- this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
-
- EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
-
- EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
-
- this.modClusterService.init();
-
- EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
- EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
- }
-
- @Test
- public void startServer() throws Exception
- {
- Server server = EasyMock.createStrictMock(Server.class);
-
- this.resetRequestSource.setJbossWebServer(server);
-
- EasyMock.replay(this.resetRequestSource);
-
- // Test not initialized
- try
- {
- this.modClusterService.startServer(server);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(this.resetRequestSource);
- EasyMock.reset(this.resetRequestSource);
-
- init();
-
- // Test initialized
- Service service = EasyMock.createStrictMock(Service.class);
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Container container = EasyMock.createStrictMock(Container.class);
- Context context = EasyMock.createStrictMock(Context.class);
- DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
- Connector connector = new Connector("AJP/1.3");
-
- this.resetRequestSource.setJbossWebServer(server);
-
- EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
-
- EasyMock.expect(service.getContainer()).andReturn(engine);
-
- // Expect log message
- EasyMock.expect(engine.getName()).andReturn("engine");
-
- EasyMock.expect(engine.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
- EasyMock.expect(engine.getJvmRoute()).andReturn(null);
- Set<MCMPServerState> states = Collections.emptySet();
- EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("route");
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- drm.add("myservice:domain", this.modClusterService.drmEntry);
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(engine.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
-
- EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
- EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.nodeConfig.getFlushWait()).andReturn(1);
- EasyMock.expect(this.nodeConfig.getPing()).andReturn(2);
- EasyMock.expect(this.nodeConfig.getSmax()).andReturn(3);
- EasyMock.expect(this.nodeConfig.getTtl()).andReturn(4);
- EasyMock.expect(this.nodeConfig.getNodeTimeout()).andReturn(5);
- EasyMock.expect(this.nodeConfig.getBalancer()).andReturn("S");
-
- EasyMock.expect(this.balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
- EasyMock.expect(this.balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
- EasyMock.expect(this.balancerConfig.getWorkerTimeout()).andReturn(6);
- EasyMock.expect(this.balancerConfig.getMaxAttempts()).andReturn(7);
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
- EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- this.recordAddContext(context, container);
-
- EasyMock.replay(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- this.modClusterService.startServer(server);
-
- EasyMock.verify(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(16, parameters.size());
- Assert.assertEquals("127.0.0.1", parameters.get("Host"));
- Assert.assertEquals("0", parameters.get("Port"));
- Assert.assertEquals("ajp", parameters.get("Type"));
- Assert.assertEquals("domain", parameters.get("Domain"));
- Assert.assertEquals("On", parameters.get("flushpackets"));
- Assert.assertEquals("1", parameters.get("flushwait"));
- Assert.assertEquals("2", parameters.get("ping"));
- Assert.assertEquals("3", parameters.get("smax"));
- Assert.assertEquals("4", parameters.get("ttl"));
- Assert.assertEquals("5", parameters.get("Timeout"));
- Assert.assertEquals("S", parameters.get("Balancer"));
- Assert.assertEquals("No", parameters.get("StickySession"));
- Assert.assertEquals("Yes", parameters.get("StickySessionRemove"));
- Assert.assertEquals("No", parameters.get("StickySessionForce"));
- Assert.assertEquals("6", parameters.get("WaitWorker"));
- Assert.assertEquals("7", parameters.get("Maxattempts"));
-
- Set<String> routes = this.modClusterService.drmEntry.getJvmRoutes();
- Assert.assertEquals(1, routes.size());
- Assert.assertEquals("route", routes.iterator().next());
-
- EasyMock.reset(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
- }
-
- private void recordAddContext(Context context, Container container)
- {
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getName()).andReturn("parent-container");
-
- EasyMock.expect(context.isStarted()).andReturn(false);
- }
-
- @Test
- public void stopServer() throws Exception
- {
- Server server = EasyMock.createStrictMock(Server.class);
-
- // Test not initialized
- try
- {
- this.modClusterService.stopServer(server);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- init();
-
- this.modClusterService.drmEntry.addJvmRoute("route");
-
- // Test initialized
- Service service = EasyMock.createStrictMock(Service.class);
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Container container = EasyMock.createStrictMock(Container.class);
- Context context = EasyMock.createStrictMock(Context.class);
- DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
- EasyMock.expect(service.getContainer()).andReturn(engine);
-
- // Expect log message
- EasyMock.expect(engine.getName()).andReturn("engine");
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.expect(engine.getJvmRoute()).andReturn("route");
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- drm.add("myservice:domain", this.modClusterService.drmEntry);
-
- EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
- EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- this.recordRemoveContext(context, container, engine);
-
- EasyMock.replay(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- this.modClusterService.stopServer(server);
-
- EasyMock.verify(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- Assert.assertTrue(this.modClusterService.drmEntry.getJvmRoutes().isEmpty());
-
- EasyMock.reset(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
- }
-
- private void recordRemoveContext(Context context, Container container, Engine engine)
- {
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getName()).andReturn("parent-container");
-
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn(null);
- }
-
- @Test
- public void addContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- EasyMock.replay(context);
-
- // Test not initialized
- try
- {
- this.modClusterService.addContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(context);
- EasyMock.reset(context);
-
- init();
-
- // Test context not started
- Host host = EasyMock.createStrictMock(Host.class);
-
- recordAddContext(context, host);
-
- EasyMock.replay(context, host);
-
- this.modClusterService.addContext(context);
-
- EasyMock.verify(context, host);
- EasyMock.reset(context, host);
-
- // Test context started
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- EasyMock.expect(context.isStarted()).andReturn(true);
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.modClusterService.addContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @Test
- public void startContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- EasyMock.replay(context);
-
- // Test not initialized
- try
- {
- this.modClusterService.startContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(context);
- EasyMock.reset(context);
-
- init();
-
- // Test initialized
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Host host = EasyMock.createStrictMock(Host.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.modClusterService.startContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @Test
- public void stopContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- EasyMock.replay(context);
-
- // Test not initialized
- try
- {
- this.modClusterService.stopContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- EasyMock.verify(context);
- EasyMock.reset(context);
-
- init();
-
- // Test initialized
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Host host = EasyMock.createStrictMock(Host.class);
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.modClusterService.stopContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @Test
- public void removeContext() throws UnknownHostException
- {
- Context context = EasyMock.createStrictMock(Context.class);
-
- // Test not initialized
- try
- {
- this.modClusterService.removeContext(context);
-
- Assert.fail();
- }
- catch (IllegalStateException e)
- {
- // Expected
- }
-
- init();
-
- // Test initialized - no jvm route
- Engine engine = EasyMock.createStrictMock(Engine.class);
- Host host = EasyMock.createStrictMock(Host.class);
-
- this.recordRemoveContext(context, host, engine);
-
- EasyMock.replay(context, host, engine);
-
- this.modClusterService.removeContext(context);
-
- EasyMock.verify(context, host, engine);
- EasyMock.reset(context, host, engine);
-
-
- // Test initialized - jvm route exists
- Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
-
- // Expect log message
- EasyMock.expect(context.getPath()).andReturn("/context");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
-
- // jvm route null check
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
-
- // Building request
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
- EasyMock.expect(context.getParent()).andReturn(host);
- EasyMock.expect(host.getName()).andReturn("host");
- EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getPath()).andReturn("/context");
-
- this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
-
- EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
-
- this.modClusterService.removeContext(context);
-
- EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
-
- MCMPRequest request = capturedRequest.getValue();
-
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertFalse(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- Map<String, String> parameters = request.getParameters();
-
- Assert.assertEquals(2, parameters.size());
-
- Assert.assertEquals("/context", parameters.get("Context"));
- Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
-
- EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void status() throws Exception
- {
- Engine engine = EasyMock.createStrictMock(Engine.class);
-
- // Test non-master status
- EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
-
- EasyMock.replay(this.lbfProvider, engine);
-
- this.modClusterService.status(engine);
-
- EasyMock.verify(this.lbfProvider, engine);
- EasyMock.reset(this.lbfProvider, engine);
-
-
- // Make master
- String key = SERVICE_HA_NAME + ":" + DOMAIN;
- DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
-
- this.modClusterService.setElectionPolicy(null);
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- EasyMock.expect(drm.isMasterReplica(key)).andReturn(true);
-
- this.partition.callAsynchMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("stopOldMaster"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(true));
-
- EasyMock.replay(this.partition, drm);
-
- this.modClusterService.replicantsChanged(key, Collections.EMPTY_LIST, 1, false);
-
- EasyMock.verify(this.partition, drm);
-
- Assert.assertTrue(this.modClusterService.isMasterNode());
-
- EasyMock.reset(this.partition, drm);
-
- // Create drm entries
- ClusterNode remoteNode1 = EasyMock.createMock(ClusterNode.class);
- MCMPServerState remoteState1 = EasyMock.createMock(MCMPServerState.class);
-
- EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
- EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
-
- EasyMock.replay(remoteState1);
-
- ModClusterServiceDRMEntry drmEntry1 = new ModClusterServiceDRMEntry(remoteNode1, Collections.singleton(remoteState1));
- drmEntry1.addJvmRoute("host1");
-
- EasyMock.verify(remoteState1);
- EasyMock.reset(remoteState1);
-
-
- MCMPServerState remoteState2 = EasyMock.createMock(MCMPServerState.class);
- ClusterNode remoteNode2 = EasyMock.createMock(ClusterNode.class);
-
- EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
- EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
-
- EasyMock.replay(remoteState2);
-
- ModClusterServiceDRMEntry drmEntry2 = new ModClusterServiceDRMEntry(remoteNode2, Collections.singleton(remoteState2));
- drmEntry2.addJvmRoute("host2");
-
- EasyMock.verify(remoteState2);
- EasyMock.reset(remoteState2);
-
- // Test master status
- MCMPServerState localState = EasyMock.createMock(MCMPServerState.class);
- ModClusterServiceDRMEntry drmEntry = new ModClusterServiceDRMEntry(this.node, null);
- InetAddress address1 = InetAddress.getByName("127.0.0.1");
- InetAddress address2 = InetAddress.getByName("127.0.1.1");
- MCMPServerDiscoveryEvent event1 = new MCMPServerDiscoveryEvent(remoteNode1, new AddressPort(address1, 1), true, 1);
- MCMPServerDiscoveryEvent event2 = new MCMPServerDiscoveryEvent(remoteNode2, new AddressPort(address2, 2), false, 2);
-
- Map<String, String> emptyMap = Collections.emptyMap();
- MCMPRequest request1 = new MCMPRequest(MCMPRequestType.ENABLE_APP, false, "route", emptyMap);
- MCMPRequest request2 = new MCMPRequest(MCMPRequestType.DISABLE_APP, false, "route", emptyMap);
- Capture<List<MCMPRequest>> capturedRequests = new Capture<List<MCMPRequest>>();
- Capture<ModClusterServiceDRMEntry> capturedEntry = new Capture<ModClusterServiceDRMEntry>();
- Capture<Object[]> capturedArgs = new Capture<Object[]>();
-
- ModClusterServiceStateGroupRpcResponse response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, new TreeSet<MCMPServerState>(), Collections.singletonList(event1), new ArrayList<MCMPRequest>());
- ModClusterServiceStateGroupRpcResponse response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, new TreeSet<MCMPServerState>(), Collections.singletonList(event2), new ArrayList<MCMPRequest>());
-
- EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
-
- this.mcmpHandler.status();
-
- EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(new TreeSet<MCMPServerState>());
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- EasyMock.expect(drm.lookupReplicants(key)).andReturn(Collections.singletonList(drmEntry));
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
- EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { new TreeSet<MCMPServerState>() }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
-
- // Process discovery events
- this.mcmpHandler.addProxy(address1, 1);
- this.mcmpHandler.removeProxy(address2, 2);
-
- // Start over - this time with no discovery events
- response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, Collections.singleton(remoteState1), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request1));
- response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, Collections.singleton(remoteState2), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request2));
-
- this.mcmpHandler.status();
-
- Set<MCMPServerState> states = new LinkedHashSet<MCMPServerState>(Arrays.asList(remoteState1, remoteState2));
-
- EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
-
- EasyMock.expect(drm.lookupReplicants(key)).andReturn(Arrays.asList(drmEntry1, drmEntry2));
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
- EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { states }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
-
- EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
- EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
- EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
- EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
-
- this.mcmpHandler.sendRequests(Arrays.asList(request1, request2));
- this.mcmpHandler.sendRequests(EasyMock.capture(capturedRequests));
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
- EasyMock.expect(drm.lookupLocalReplicant(key)).andReturn(drmEntry);
-
- EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
-
- EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
- EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
- EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
- EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
-
- EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
-
- drm.add(EasyMock.eq(key), EasyMock.capture(capturedEntry));
-
- EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("clusterStatusComplete"), EasyMock.capture(capturedArgs), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(null);
-
- EasyMock.replay(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
-
- this.modClusterService.status(engine);
-
- EasyMock.verify(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
-
- List<MCMPRequest> requests = capturedRequests.getValue();
-
- Assert.assertEquals(2, requests.size());
-
- Assert.assertSame(MCMPRequestType.STATUS, requests.get(0).getRequestType());
- Assert.assertFalse(requests.get(0).isWildcard());
- Assert.assertEquals("host2", requests.get(0).getJvmRoute());
- Assert.assertEquals(1, requests.get(0).getParameters().size());
- Assert.assertEquals("20", requests.get(0).getParameters().get("Load"));
-
- Assert.assertSame(MCMPRequestType.STATUS, requests.get(1).getRequestType());
- Assert.assertFalse(requests.get(1).isWildcard());
- Assert.assertEquals("host1", requests.get(1).getJvmRoute());
- Assert.assertEquals(1, requests.get(1).getParameters().size());
- Assert.assertEquals("10", requests.get(1).getParameters().get("Load"));
-
- ModClusterServiceDRMEntry entry = capturedEntry.getValue();
-
- Assert.assertSame(this.node, entry.getPeer());
- Assert.assertEquals(states, entry.getMCMPServerStates());
- Assert.assertTrue(entry.getJvmRoutes().isEmpty());
-
- Object[] args = capturedArgs.getValue();
- Assert.assertEquals(1, args.length);
- Assert.assertTrue(args[0] instanceof Map);
-
- Map<ClusterNode, PeerMCMPDiscoveryStatus> map = (Map<ClusterNode, PeerMCMPDiscoveryStatus>) args[0];
-
- Assert.assertEquals(2, map.size());
- Assert.assertTrue(map.containsKey(remoteNode1));
- Assert.assertTrue(map.containsKey(remoteNode2));
-
- PeerMCMPDiscoveryStatus status1 = map.get(remoteNode1);
-
- Assert.assertSame(remoteNode1, status1.getPeer());
- Assert.assertEquals(Collections.singleton(remoteState1), status1.getMCMPServerStates());
- Assert.assertTrue(status1.getJvmRoutes().isEmpty());
- Assert.assertNull(status1.getLatestDiscoveryEvent());
-
- EasyMock.reset(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
-
-
- // Test master status, but off-frequency
- this.modClusterService.setProcessStatusFrequency(2);
-
- EasyMock.expect(engine.getName()).andReturn("engine");
- EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
-
- EasyMock.replay(this.lbfProvider, engine);
-
- this.modClusterService.status(engine);
-
- EasyMock.verify(this.lbfProvider, engine);
- EasyMock.reset(this.lbfProvider, engine);
- }
-}
Copied: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java (from rev 2062, trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java)
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,239 @@
+/*
+ * 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.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.easymock.Capture;
+import org.easymock.EasyMock;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ModClusterServiceTestCase
+{
+ public static final LifecycleServer server = EasyMock.createStrictMock(LifecycleServer.class);
+ static
+ {
+ ServerFactory.setServer(server);
+ }
+
+ private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private final LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
+ private final LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
+
+ private final ModClusterService listener = new ModClusterService(this.mcmpHandler, this.lifecycleListener, this.lbfProvider);
+
+ @Test
+ public void createLoadBalanceFactorProvider()
+ {
+ LoadBalanceFactorProvider lbfProvider = this.listener.createLoadBalanceFactorProvider();
+
+ Assert.assertSame(this.lbfProvider, lbfProvider);
+ }
+
+ @Test
+ public void lifecycleEvent()
+ {
+ LifecycleEvent event = new LifecycleEvent(EasyMock.createMock(Lifecycle.class), Lifecycle.INIT_EVENT);
+
+ this.lifecycleListener.lifecycleEvent(event);
+
+ EasyMock.replay(this.lifecycleListener);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.lifecycleListener);
+ EasyMock.reset(this.lifecycleListener);
+ }
+
+ @Test
+ public void addProxy()
+ {
+ this.mcmpHandler.addProxy("host", 100);
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.addProxy("host", 100);
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void removeProxy()
+ {
+ this.mcmpHandler.removeProxy("host", 100);
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.removeProxy("host", 100);
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void getProxyConfiguration()
+ {
+ EasyMock.expect(this.mcmpHandler.getProxyConfiguration()).andReturn("config");
+
+ EasyMock.replay(this.mcmpHandler);
+
+ String result = this.listener.getProxyConfiguration();
+
+ EasyMock.verify(this.mcmpHandler);
+
+ Assert.assertEquals("config", result);
+
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void getProxyInfo()
+ {
+ EasyMock.expect(this.mcmpHandler.getProxyInfo()).andReturn("info");
+
+ EasyMock.replay(this.mcmpHandler);
+
+ String result = this.listener.getProxyInfo();
+
+ EasyMock.verify(this.mcmpHandler);
+
+ Assert.assertEquals("info", result);
+
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void reset()
+ {
+ this.mcmpHandler.reset();
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.reset();
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @Test
+ public void refresh()
+ {
+ this.mcmpHandler.markProxiesInError();
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.listener.refresh();
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+ }
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void enable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ Assert.assertSame(server, ServerFactory.getServer());
+
+ 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);
+
+ Assert.assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ EasyMock.reset(this.mcmpHandler, server, service, engine);
+ }
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void disable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ Assert.assertSame(server, ServerFactory.getServer());
+
+ 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);
+
+ Assert.assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ EasyMock.reset(this.mcmpHandler, server, service, engine);
+ }
+
+ public interface LifecycleServer extends Server, Lifecycle
+ {
+ String getDomain();
+ }
+}
Property changes on: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java (from rev 2062, trunk/mod_cluster/src/test/java/org/jboss/modcluster/ModClusterServiceTestCase.java)
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java 2008-12-02 20:56:39 UTC (rev 2088)
@@ -0,0 +1,1035 @@
+/*
+ * 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.ha;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.ha.framework.interfaces.HASingletonElectionPolicy;
+import org.jboss.modcluster.ModClusterServiceTestCase;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.MCMPHandlerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.config.ha.HAConfiguration;
+import org.jboss.modcluster.ha.ClusteredMCMPHandler;
+import org.jboss.modcluster.ha.HAModClusterService;
+import org.jboss.modcluster.ha.HASingletonAwareResetRequestSource;
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPRequestType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+@SuppressWarnings("boxing")
+public class HAModClusterListenerTestCase
+{
+ private static final ModClusterServiceTestCase.LifecycleServer server = ModClusterServiceTestCase.server;
+
+ private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
+ private NodeConfiguration nodeConfig = EasyMock.createMock(NodeConfiguration.class);
+ private BalancerConfiguration balancerConfig = EasyMock.createMock(BalancerConfiguration.class);
+ private MCMPHandlerConfiguration mcmpConfig = EasyMock.createMock(MCMPHandlerConfiguration.class);
+ private HAConfiguration haConfig = EasyMock.createMock(HAConfiguration.class);
+ private MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private HASingletonAwareResetRequestSource resetRequestSource = EasyMock.createStrictMock(HASingletonAwareResetRequestSource.class);
+ private ClusteredMCMPHandler clusteredMCMPHandler = EasyMock.createStrictMock(ClusteredMCMPHandler.class);
+ private LoadBalanceFactorProvider lbfProvider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
+ private HASingletonElectionPolicy electionPolicy = EasyMock.createStrictMock(HASingletonElectionPolicy.class);
+ private ClusterNode node = EasyMock.createStrictMock(ClusterNode.class);
+ private LifecycleListener lifecycleListener = EasyMock.createStrictMock(LifecycleListener.class);
+
+ private static final boolean MASTER_PER_DOMAIN = true;
+ private static final String SERVICE_HA_NAME = "myservice";
+ private static final String DOMAIN = "domain";
+
+ private HAModClusterService listener;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ EasyMock.expect(this.haConfig.isMasterPerDomain()).andReturn(MASTER_PER_DOMAIN);
+ EasyMock.expect(this.nodeConfig.getDomain()).andReturn(DOMAIN);
+
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node).times(2);
+
+ EasyMock.replay(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
+
+ this.listener = new HAModClusterService(this.partition, this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.haConfig, this.mcmpHandler, this.resetRequestSource, this.clusteredMCMPHandler, this.lifecycleListener, this.lbfProvider, this.electionPolicy);
+ this.listener.setServiceHAName(SERVICE_HA_NAME);
+
+ EasyMock.verify(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
+ EasyMock.reset(this.mcmpConfig, this.nodeConfig, this.haConfig, this.partition);
+ }
+
+ @Test
+ public void addProxy()
+ {
+ String host = "127.0.0.1";
+ int port = 0;
+
+ this.clusteredMCMPHandler.addProxy(host, port);
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.listener.addProxy(host, port);
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void removeProxy()
+ {
+ String host = "127.0.0.1";
+ int port = 0;
+
+ this.clusteredMCMPHandler.removeProxy(host, port);
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.listener.removeProxy(host, port);
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void getProxyConfiguration()
+ {
+ EasyMock.expect(this.clusteredMCMPHandler.getProxyConfiguration()).andReturn("configuration");
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ String result = this.listener.getProxyConfiguration();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+
+ Assert.assertEquals("configuration", result);
+
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void getProxyInfo()
+ {
+ EasyMock.expect(this.clusteredMCMPHandler.getProxyInfo()).andReturn("info");
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ String result = this.listener.getProxyInfo();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+
+ Assert.assertEquals("info", result);
+
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void reset()
+ {
+ this.clusteredMCMPHandler.reset();
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.listener.reset();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void refresh()
+ {
+ this.clusteredMCMPHandler.markProxiesInError();
+
+ EasyMock.replay(this.clusteredMCMPHandler);
+
+ this.listener.refresh();
+
+ EasyMock.verify(this.clusteredMCMPHandler);
+ EasyMock.reset(this.clusteredMCMPHandler);
+ }
+
+ @Test
+ public void enable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ Assert.assertSame(server, ServerFactory.getServer());
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
+
+ EasyMock.replay(this.clusteredMCMPHandler, server, service, engine);
+
+ boolean result = this.listener.enable();
+
+ EasyMock.verify(this.clusteredMCMPHandler, server, service, engine);
+
+ Assert.assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ EasyMock.reset(this.clusteredMCMPHandler, server, service, engine);
+ }
+
+ @Test
+ public void disable()
+ {
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ Assert.assertSame(server, ServerFactory.getServer());
+
+ EasyMock.expect(ModClusterServiceTestCase.server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+ EasyMock.expect(this.clusteredMCMPHandler.isProxyHealthOK()).andReturn(true);
+
+ EasyMock.replay(this.clusteredMCMPHandler, server, service, engine);
+
+ boolean result = this.listener.disable();
+
+ EasyMock.verify(this.clusteredMCMPHandler, server, service, engine);
+
+ Assert.assertTrue(result);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.DISABLE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ EasyMock.reset(this.clusteredMCMPHandler, server, service, engine);
+ }
+
+ @Test
+ public void lifecycleEvent()
+ {
+ LifecycleEvent event = new LifecycleEvent(EasyMock.createMock(Lifecycle.class), Lifecycle.INIT_EVENT);
+
+ this.lifecycleListener.lifecycleEvent(event);
+
+ EasyMock.replay(this.lifecycleListener);
+
+ this.listener.lifecycleEvent(event);
+
+ EasyMock.verify(this.lifecycleListener);
+ EasyMock.reset(this.lifecycleListener);
+ }
+
+ @Test
+ public void createLoadBalanceFactorProvider()
+ {
+ LoadBalanceFactorProvider lbfProvider = this.listener.createLoadBalanceFactorProvider();
+
+ Assert.assertSame(this.lbfProvider, lbfProvider);
+ }
+
+/*
+ @Test
+ public void init() throws UnknownHostException
+ {
+ InetAddress localAddress = InetAddress.getLocalHost();
+ String localHostName = localAddress.getHostName();
+
+ AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
+
+ // Test advertise = false
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
+
+ this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(Boolean.FALSE);
+
+ EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
+ this.listener.init();
+
+ EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
+
+ // Test advertise = null, proxies configured
+ EasyMock.expect(this.mcmpConfig.getProxyList()).andReturn(localHostName);
+
+ this.clusteredMCMPHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(this.mcmpConfig.getAdvertise()).andReturn(null);
+
+ EasyMock.replay(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+
+ this.listener.init();
+
+ EasyMock.verify(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ EasyMock.reset(this.clusteredMCMPHandler, this.mcmpConfig, listener);
+ }
+
+ @Test
+ public void startServer() throws Exception
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
+
+ this.resetRequestSource.setJbossWebServer(server);
+
+ EasyMock.replay(this.resetRequestSource);
+
+ // Test not initialized
+ try
+ {
+ this.listener.startServer(server);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(this.resetRequestSource);
+ EasyMock.reset(this.resetRequestSource);
+
+ init();
+
+ // Test initialized
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ Connector connector = new Connector("AJP/1.3");
+
+ this.resetRequestSource.setJbossWebServer(server);
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
+
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+ EasyMock.expect(engine.getJvmRoute()).andReturn(null);
+ Set<MCMPServerState> states = Collections.emptySet();
+ EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ drm.add("myservice:domain", this.listener.drmEntry);
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(engine.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+
+ EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
+ EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
+ EasyMock.expect(this.nodeConfig.getFlushWait()).andReturn(1);
+ EasyMock.expect(this.nodeConfig.getPing()).andReturn(2);
+ EasyMock.expect(this.nodeConfig.getSmax()).andReturn(3);
+ EasyMock.expect(this.nodeConfig.getTtl()).andReturn(4);
+ EasyMock.expect(this.nodeConfig.getNodeTimeout()).andReturn(5);
+ EasyMock.expect(this.nodeConfig.getBalancer()).andReturn("S");
+
+ EasyMock.expect(this.balancerConfig.getStickySession()).andReturn(Boolean.FALSE);
+ EasyMock.expect(this.balancerConfig.getStickySessionRemove()).andReturn(Boolean.TRUE);
+ EasyMock.expect(this.balancerConfig.getStickySessionForce()).andReturn(Boolean.FALSE);
+ EasyMock.expect(this.balancerConfig.getWorkerTimeout()).andReturn(6);
+ EasyMock.expect(this.balancerConfig.getMaxAttempts()).andReturn(7);
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ this.recordAddContext(context, container);
+
+ EasyMock.replay(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ this.listener.startServer(server);
+
+ EasyMock.verify(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(16, parameters.size());
+ Assert.assertEquals("127.0.0.1", parameters.get("Host"));
+ Assert.assertEquals("0", parameters.get("Port"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals("domain", parameters.get("Domain"));
+ Assert.assertEquals("On", parameters.get("flushpackets"));
+ Assert.assertEquals("1", parameters.get("flushwait"));
+ Assert.assertEquals("2", parameters.get("ping"));
+ Assert.assertEquals("3", parameters.get("smax"));
+ Assert.assertEquals("4", parameters.get("ttl"));
+ Assert.assertEquals("5", parameters.get("Timeout"));
+ Assert.assertEquals("S", parameters.get("Balancer"));
+ Assert.assertEquals("No", parameters.get("StickySession"));
+ Assert.assertEquals("Yes", parameters.get("StickySessionRemove"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("6", parameters.get("WaitWorker"));
+ Assert.assertEquals("7", parameters.get("Maxattempts"));
+
+ Set<String> routes = this.listener.drmEntry.getJvmRoutes();
+ Assert.assertEquals(1, routes.size());
+ Assert.assertEquals("route", routes.iterator().next());
+
+ EasyMock.reset(this.partition, this.resetRequestSource, this.mcmpHandler, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+ }
+
+ private void recordAddContext(Context context, Container container)
+ {
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ EasyMock.expect(context.isStarted()).andReturn(false);
+ }
+
+ @Test
+ public void stopServer() throws Exception
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
+
+ // Test not initialized
+ try
+ {
+ this.listener.stopServer(server);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ init();
+
+ this.listener.drmEntry.addJvmRoute("route");
+
+ // Test initialized
+ Service service = EasyMock.createStrictMock(Service.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Container container = EasyMock.createStrictMock(Container.class);
+ Context context = EasyMock.createStrictMock(Context.class);
+ DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
+ EasyMock.expect(service.getContainer()).andReturn(engine);
+
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("route");
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ drm.add("myservice:domain", this.listener.drmEntry);
+
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
+ EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
+ this.recordRemoveContext(context, container, engine);
+
+ EasyMock.replay(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ this.listener.stopServer(server);
+
+ EasyMock.verify(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
+
+ Assert.assertTrue(this.listener.drmEntry.getJvmRoutes().isEmpty());
+
+ EasyMock.reset(this.partition, this.clusteredMCMPHandler, this.nodeConfig, this.balancerConfig, drm, server, service, engine, container, context);
+ }
+
+ private void recordRemoveContext(Context context, Container container, Engine engine)
+ {
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn(null);
+ }
+
+ @Test
+ public void addContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.replay(context);
+
+ // Test not initialized
+ try
+ {
+ this.listener.addContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+
+ // Test context not started
+ Host host = EasyMock.createStrictMock(Host.class);
+
+ recordAddContext(context, host);
+
+ EasyMock.replay(context, host);
+
+ this.listener.addContext(context);
+
+ EasyMock.verify(context, host);
+ EasyMock.reset(context, host);
+
+ // Test context started
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ EasyMock.expect(context.isStarted()).andReturn(true);
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.addContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @Test
+ public void startContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.replay(context);
+
+ // Test not initialized
+ try
+ {
+ this.listener.startContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+
+ // Test initialized
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.startContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @Test
+ public void stopContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.replay(context);
+
+ // Test not initialized
+ try
+ {
+ this.listener.stopContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+
+ // Test initialized
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.stopContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @Test
+ public void removeContext() throws UnknownHostException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ // Test not initialized
+ try
+ {
+ this.listener.removeContext(context);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ init();
+
+ // Test initialized - no jvm route
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
+
+ this.recordRemoveContext(context, host, engine);
+
+ EasyMock.replay(context, host, engine);
+
+ this.listener.removeContext(context);
+
+ EasyMock.verify(context, host, engine);
+ EasyMock.reset(context, host, engine);
+
+
+ // Test initialized - jvm route exists
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ // jvm route null check
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+ EasyMock.expect(context.getPath()).andReturn("/context");
+
+ this.clusteredMCMPHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.clusteredMCMPHandler, context, engine, host);
+
+ this.listener.removeContext(context);
+
+ EasyMock.verify(this.clusteredMCMPHandler, context, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+
+ Map<String, String> parameters = request.getParameters();
+
+ Assert.assertEquals(2, parameters.size());
+
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.clusteredMCMPHandler, context, engine, host);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void status() throws Exception
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.replay(engine);
+
+ // Test not initialized
+ try
+ {
+ this.listener.status(engine);
+
+ Assert.fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
+
+ init();
+
+ // Test non-master status
+ EasyMock.expect(engine.getName()).andReturn("engine");
+ EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
+
+ EasyMock.replay(this.lbfProvider, engine);
+
+ this.listener.status(engine);
+
+ EasyMock.verify(this.lbfProvider, engine);
+ EasyMock.reset(this.lbfProvider, engine);
+
+
+ // Make master
+ String key = SERVICE_HA_NAME + ":" + DOMAIN;
+ DistributedReplicantManager drm = EasyMock.createStrictMock(DistributedReplicantManager.class);
+
+ this.listener.setElectionPolicy(null);
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ EasyMock.expect(drm.isMasterReplica(key)).andReturn(true);
+
+ this.partition.callAsynchMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("stopOldMaster"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(true));
+
+ EasyMock.replay(this.partition, drm);
+
+ this.listener.replicantsChanged(key, Collections.EMPTY_LIST, 1, false);
+
+ EasyMock.verify(this.partition, drm);
+
+ Assert.assertTrue(this.listener.isMasterNode());
+
+ EasyMock.reset(this.partition, drm);
+
+ // Create drm entries
+ ClusterNode remoteNode1 = EasyMock.createMock(ClusterNode.class);
+ MCMPServerState remoteState1 = EasyMock.createMock(MCMPServerState.class);
+
+ EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
+ EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
+
+ EasyMock.replay(remoteState1);
+
+ ModClusterServiceDRMEntry drmEntry1 = new ModClusterServiceDRMEntry(remoteNode1, Collections.singleton(remoteState1));
+ drmEntry1.addJvmRoute("host1");
+
+ EasyMock.verify(remoteState1);
+ EasyMock.reset(remoteState1);
+
+
+ MCMPServerState remoteState2 = EasyMock.createMock(MCMPServerState.class);
+ ClusterNode remoteNode2 = EasyMock.createMock(ClusterNode.class);
+
+ EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
+ EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
+
+ EasyMock.replay(remoteState2);
+
+ ModClusterServiceDRMEntry drmEntry2 = new ModClusterServiceDRMEntry(remoteNode2, Collections.singleton(remoteState2));
+ drmEntry2.addJvmRoute("host2");
+
+ EasyMock.verify(remoteState2);
+ EasyMock.reset(remoteState2);
+
+ // Test master status
+ MCMPServerState localState = EasyMock.createMock(MCMPServerState.class);
+ ModClusterServiceDRMEntry drmEntry = new ModClusterServiceDRMEntry(this.node, null);
+ InetAddress address1 = InetAddress.getByName("127.0.0.1");
+ InetAddress address2 = InetAddress.getByName("127.0.1.1");
+ MCMPServerDiscoveryEvent event1 = new MCMPServerDiscoveryEvent(remoteNode1, new AddressPort(address1, 1), true, 1);
+ MCMPServerDiscoveryEvent event2 = new MCMPServerDiscoveryEvent(remoteNode2, new AddressPort(address2, 2), false, 2);
+
+ Map<String, String> emptyMap = Collections.emptyMap();
+ MCMPRequest request1 = new MCMPRequest(MCMPRequestType.ENABLE_APP, false, "route", emptyMap);
+ MCMPRequest request2 = new MCMPRequest(MCMPRequestType.DISABLE_APP, false, "route", emptyMap);
+ Capture<List<MCMPRequest>> capturedRequests = new Capture<List<MCMPRequest>>();
+ Capture<ModClusterServiceDRMEntry> capturedEntry = new Capture<ModClusterServiceDRMEntry>();
+ Capture<Object[]> capturedArgs = new Capture<Object[]>();
+
+ ModClusterServiceStateGroupRpcResponse response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, new TreeSet<MCMPServerState>(), Collections.singletonList(event1), new ArrayList<MCMPRequest>());
+ ModClusterServiceStateGroupRpcResponse response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, new TreeSet<MCMPServerState>(), Collections.singletonList(event2), new ArrayList<MCMPRequest>());
+
+ EasyMock.expect(engine.getName()).andReturn("engine");
+ EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
+
+ this.mcmpHandler.status();
+
+ EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(new TreeSet<MCMPServerState>());
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ EasyMock.expect(drm.lookupReplicants(key)).andReturn(Collections.singletonList(drmEntry));
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
+ EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { new TreeSet<MCMPServerState>() }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
+
+ // Process discovery events
+ this.mcmpHandler.addProxy(address1, 1);
+ this.mcmpHandler.removeProxy(address2, 2);
+
+ // Start over - this time with no discovery events
+ response1 = new ModClusterServiceStateGroupRpcResponse(remoteNode1, 10, Collections.singleton(remoteState1), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request1));
+ response2 = new ModClusterServiceStateGroupRpcResponse(remoteNode2, 20, Collections.singleton(remoteState2), new ArrayList<MCMPServerDiscoveryEvent>(), Collections.singletonList(request2));
+
+ this.mcmpHandler.status();
+
+ Set<MCMPServerState> states = new LinkedHashSet<MCMPServerState>(Arrays.asList(remoteState1, remoteState2));
+
+ EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
+
+ EasyMock.expect(drm.lookupReplicants(key)).andReturn(Arrays.asList(drmEntry1, drmEntry2));
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
+ EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(SERVICE_HA_NAME), EasyMock.eq("getClusterCoordinatorState"), EasyMock.aryEq(new Object[] { states }), EasyMock.aryEq(new Class[] { Set.class }), EasyMock.eq(true))).andReturn(new ArrayList<Object>(Arrays.asList(response1, response2)));
+
+ EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
+ EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
+ EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
+ EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
+
+ this.mcmpHandler.sendRequests(Arrays.asList(request1, request2));
+ this.mcmpHandler.sendRequests(EasyMock.capture(capturedRequests));
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+ EasyMock.expect(drm.lookupLocalReplicant(key)).andReturn(drmEntry);
+
+ EasyMock.expect(this.partition.getClusterNode()).andReturn(this.node);
+
+ EasyMock.expect(remoteState1.getState()).andReturn(MCMPServerState.State.OK);
+ EasyMock.expect(remoteState1.isEstablished()).andReturn(true);
+ EasyMock.expect(remoteState2.getState()).andReturn(MCMPServerState.State.DOWN);
+ EasyMock.expect(remoteState2.isEstablished()).andReturn(false);
+
+ EasyMock.expect(this.partition.getDistributedReplicantManager()).andReturn(drm);
+
+ drm.add(EasyMock.eq(key), EasyMock.capture(capturedEntry));
+
+ EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq("myservice"), EasyMock.eq("clusterStatusComplete"), EasyMock.capture(capturedArgs), EasyMock.aryEq(new Class[] { Map.class }), EasyMock.eq(true))).andReturn(null);
+
+ EasyMock.replay(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
+
+ this.listener.status(engine);
+
+ EasyMock.verify(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
+
+ List<MCMPRequest> requests = capturedRequests.getValue();
+
+ Assert.assertEquals(2, requests.size());
+
+ Assert.assertSame(MCMPRequestType.STATUS, requests.get(0).getRequestType());
+ Assert.assertFalse(requests.get(0).isWildcard());
+ Assert.assertEquals("host2", requests.get(0).getJvmRoute());
+ Assert.assertEquals(1, requests.get(0).getParameters().size());
+ Assert.assertEquals("20", requests.get(0).getParameters().get("Load"));
+
+ Assert.assertSame(MCMPRequestType.STATUS, requests.get(1).getRequestType());
+ Assert.assertFalse(requests.get(1).isWildcard());
+ Assert.assertEquals("host1", requests.get(1).getJvmRoute());
+ Assert.assertEquals(1, requests.get(1).getParameters().size());
+ Assert.assertEquals("10", requests.get(1).getParameters().get("Load"));
+
+ ModClusterServiceDRMEntry entry = capturedEntry.getValue();
+
+ Assert.assertSame(this.node, entry.getPeer());
+ Assert.assertEquals(states, entry.getMCMPServerStates());
+ Assert.assertTrue(entry.getJvmRoutes().isEmpty());
+
+ Object[] args = capturedArgs.getValue();
+ Assert.assertEquals(1, args.length);
+ Assert.assertTrue(args[0] instanceof Map);
+
+ Map<ClusterNode, PeerMCMPDiscoveryStatus> map = (Map<ClusterNode, PeerMCMPDiscoveryStatus>) args[0];
+
+ Assert.assertEquals(2, map.size());
+ Assert.assertTrue(map.containsKey(remoteNode1));
+ Assert.assertTrue(map.containsKey(remoteNode2));
+
+ PeerMCMPDiscoveryStatus status1 = map.get(remoteNode1);
+
+ Assert.assertSame(remoteNode1, status1.getPeer());
+ Assert.assertEquals(Collections.singleton(remoteState1), status1.getMCMPServerStates());
+ Assert.assertTrue(status1.getJvmRoutes().isEmpty());
+ Assert.assertNull(status1.getLatestDiscoveryEvent());
+
+ EasyMock.reset(this.lbfProvider, this.mcmpHandler, this.clusteredMCMPHandler, this.partition, drm, localState, this.node, remoteState1, remoteState2, remoteNode1, remoteNode2, engine);
+
+
+ // Test master status, but off-frequency
+ this.listener.setProcessStatusFrequency(2);
+
+ EasyMock.expect(engine.getName()).andReturn("engine");
+ EasyMock.expect(this.lbfProvider.getLoadBalanceFactor()).andReturn(10);
+
+ EasyMock.replay(this.lbfProvider, engine);
+
+ this.listener.status(engine);
+
+ EasyMock.verify(this.lbfProvider, engine);
+ EasyMock.reset(this.lbfProvider, engine);
+ }
+*/
+}
Property changes on: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HAModClusterListenerTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/META-INF/jboss-beans.xml
===================================================================
--- trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/META-INF/jboss-beans.xml 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/META-INF/jboss-beans.xml 2008-12-02 20:56:39 UTC (rev 2088)
@@ -17,7 +17,7 @@
<!-- Only needed if the org.jboss.web.tomcat.service.deployers.MicrocontainerIntegrationLifecycleListener
is enabled in the tomcat server.xml file.
-->
- <depends>ModClusterLifecycleListener</depends>
+ <depends>HAModClusterService</depends>
<!-- Inject the TomcatDeployer -->
<property name="tomcatDeployer"><inject bean="WarDeployer"/></property>
Modified: trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/server.xml
===================================================================
--- trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/server.xml 2008-12-02 20:18:18 UTC (rev 2087)
+++ trunk/mod_cluster/src/test/resources/test-configs/mod-cluster-jbossas/deploy/jbossweb.sar/server.xml 2008-12-02 20:56:39 UTC (rev 2088)
@@ -8,7 +8,7 @@
<!--Listener className="org.jboss.modcluster.ClusterListener"
advertise="true"/-->
<Listener className="org.jboss.web.tomcat.service.deployers.MicrocontainerIntegrationLifecycleListener"
- delegateBeanName="ModClusterLifecycleListener" />
+ delegateBeanName="HAModClusterService"/>
<Service name="jboss.web">
16 years
JBoss Native SVN: r2087 - in trunk/mod_cluster/src: test/java/org/jboss/modcluster/load and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 15:18:18 -0500 (Tue, 02 Dec 2008)
New Revision: 2087
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProvider.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProviderMBean.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/SimpleLoadBalanceFactorProviderTestCase.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java
Log:
Rename from Static* to Simple*, lbf is not really static - it can change at runtime.
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProvider.java (from rev 2086, trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProvider.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProvider.java 2008-12-02 20:18:18 UTC (rev 2087)
@@ -0,0 +1,53 @@
+/*
+ * 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.load.impl;
+
+
+/**
+ * A {@link LoadManagerImpl} that returns a static value.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class SimpleLoadBalanceFactorProvider implements SimpleLoadBalanceFactorProviderMBean
+{
+ private int loadBalanceFactor = 1;
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.LoadBalanceFactorProvider#getLoadBalanceFactor()
+ */
+ public int getLoadBalanceFactor()
+ {
+ return this.loadBalanceFactor;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProviderMBean#setLoadBalanceFactor(int)
+ */
+ public void setLoadBalanceFactor(int loadBalanceFactor)
+ {
+ this.loadBalanceFactor = loadBalanceFactor;
+ }
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProvider.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProviderMBean.java (from rev 2086, trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProviderMBean.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProviderMBean.java 2008-12-02 20:18:18 UTC (rev 2087)
@@ -0,0 +1,33 @@
+/*
+ * 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.load.impl;
+
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface SimpleLoadBalanceFactorProviderMBean extends LoadBalanceFactorProvider
+{
+ public void setLoadBalanceFactor(int loadBalanceFactor);
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/SimpleLoadBalanceFactorProviderMBean.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java 2008-12-02 20:16:15 UTC (rev 2086)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java 2008-12-02 20:18:18 UTC (rev 2087)
@@ -1,53 +0,0 @@
-/*
- * 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.load.impl;
-
-
-/**
- * A {@link LoadManagerImpl} that returns a static value.
- *
- * @author Brian Stansberry
- * @version $Revision$
- */
-public class StaticLoadBalanceFactorProvider implements StaticLoadBalanceFactorProviderMBean
-{
- private int loadBalanceFactor = 1;
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.LoadBalanceFactorProvider#getLoadBalanceFactor()
- */
- public int getLoadBalanceFactor()
- {
- return this.loadBalanceFactor;
- }
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProviderMBean#setLoadBalanceFactor(int)
- */
- public void setLoadBalanceFactor(int loadBalanceFactor)
- {
- this.loadBalanceFactor = loadBalanceFactor;
- }
-}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java 2008-12-02 20:16:15 UTC (rev 2086)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java 2008-12-02 20:18:18 UTC (rev 2087)
@@ -1,33 +0,0 @@
-/*
- * 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.load.impl;
-
-import org.jboss.modcluster.load.LoadBalanceFactorProvider;
-
-/**
- * @author Paul Ferraro
- *
- */
-public interface StaticLoadBalanceFactorProviderMBean extends LoadBalanceFactorProvider
-{
- public void setLoadBalanceFactor(int loadBalanceFactor);
-}
Copied: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/SimpleLoadBalanceFactorProviderTestCase.java (from rev 2078, trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java)
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/SimpleLoadBalanceFactorProviderTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/SimpleLoadBalanceFactorProviderTestCase.java 2008-12-02 20:18:18 UTC (rev 2087)
@@ -0,0 +1,49 @@
+/*
+ * 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.load;
+
+import org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SimpleLoadBalanceFactorProviderTestCase
+{
+ private SimpleLoadBalanceFactorProvider provider = new SimpleLoadBalanceFactorProvider();
+
+ @Test
+ public void getLoadBalanceFactor()
+ {
+ int factor = this.provider.getLoadBalanceFactor();
+
+ Assert.assertEquals(1, factor);
+
+ this.provider.setLoadBalanceFactor(3);
+
+ factor = this.provider.getLoadBalanceFactor();
+
+ Assert.assertEquals(3, factor);
+ }
+}
Property changes on: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/SimpleLoadBalanceFactorProviderTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java 2008-12-02 20:16:15 UTC (rev 2086)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/load/StaticLoadBalanceFactorProviderTestCase.java 2008-12-02 20:18:18 UTC (rev 2087)
@@ -1,49 +0,0 @@
-/*
- * 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.load;
-
-import org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProvider;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-public class StaticLoadBalanceFactorProviderTestCase
-{
- private StaticLoadBalanceFactorProvider provider = new StaticLoadBalanceFactorProvider();
-
- @Test
- public void getLoadBalanceFactor()
- {
- int factor = this.provider.getLoadBalanceFactor();
-
- Assert.assertEquals(1, factor);
-
- this.provider.setLoadBalanceFactor(3);
-
- factor = this.provider.getLoadBalanceFactor();
-
- Assert.assertEquals(3, factor);
- }
-}
16 years
JBoss Native SVN: r2086 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 15:16:15 -0500 (Tue, 02 Dec 2008)
New Revision: 2086
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java
Log:
Add mbean interface to allow changing lbf at runtime
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java 2008-12-02 20:08:49 UTC (rev 2085)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProvider.java 2008-12-02 20:16:15 UTC (rev 2086)
@@ -22,7 +22,6 @@
package org.jboss.modcluster.load.impl;
-import org.jboss.modcluster.load.LoadBalanceFactorProvider;
/**
* A {@link LoadManagerImpl} that returns a static value.
@@ -30,22 +29,25 @@
* @author Brian Stansberry
* @version $Revision$
*/
-public class StaticLoadBalanceFactorProvider implements LoadBalanceFactorProvider
+public class StaticLoadBalanceFactorProvider implements StaticLoadBalanceFactorProviderMBean
{
private int loadBalanceFactor = 1;
- // ------------------------------------------------------------- LoadManager
-
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.LoadBalanceFactorProvider#getLoadBalanceFactor()
+ */
public int getLoadBalanceFactor()
{
return this.loadBalanceFactor;
}
-
- // -------------------------------------------------------------- Properties
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.load.impl.StaticLoadBalanceFactorProviderMBean#setLoadBalanceFactor(int)
+ */
public void setLoadBalanceFactor(int loadBalanceFactor)
{
this.loadBalanceFactor = loadBalanceFactor;
}
-
}
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/StaticLoadBalanceFactorProviderMBean.java 2008-12-02 20:16:15 UTC (rev 2086)
@@ -0,0 +1,33 @@
+/*
+ * 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.load.impl;
+
+import org.jboss.modcluster.load.LoadBalanceFactorProvider;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface StaticLoadBalanceFactorProviderMBean extends LoadBalanceFactorProvider
+{
+ public void setLoadBalanceFactor(int loadBalanceFactor);
+}
16 years
JBoss Native SVN: r2085 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 15:08:49 -0500 (Tue, 02 Dec 2008)
New Revision: 2085
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java
Log:
Consolidate source->metric and metric->load-queue into one map.
Add getMetrics() method.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-12-02 19:24:44 UTC (rev 2084)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProvider.java 2008-12-02 20:08:49 UTC (rev 2085)
@@ -23,8 +23,9 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -33,6 +34,7 @@
import org.jboss.modcluster.load.LoadBalanceFactorProvider;
import org.jboss.modcluster.load.metric.LoadContext;
import org.jboss.modcluster.load.metric.LoadMetric;
+import org.jboss.modcluster.load.metric.LoadMetricMBean;
import org.jboss.modcluster.load.metric.LoadMetricSource;
/**
@@ -44,8 +46,7 @@
{
private final Logger log = Logger.getLogger(this.getClass());
- private final Map<LoadMetricSource<LoadContext>, Collection<LoadMetric<LoadContext>>> metrics = new LinkedHashMap<LoadMetricSource<LoadContext>, Collection<LoadMetric<LoadContext>>>();
- private final Map<LoadMetric<LoadContext>, List<Double>> loadHistory = new HashMap<LoadMetric<LoadContext>, List<Double>>();
+ private final Map<LoadMetricSource<LoadContext>, Map<LoadMetric<LoadContext>, List<Double>>> loadHistory = new LinkedHashMap<LoadMetricSource<LoadContext>, Map<LoadMetric<LoadContext>, List<Double>>>();
private volatile int decayFactor = 2;
private volatile int history = 9;
@@ -55,20 +56,40 @@
for (LoadMetric<LoadContext> metric: metrics)
{
LoadMetricSource<LoadContext> source = metric.getSource();
- Collection<LoadMetric<LoadContext>> sourceMetrics = this.metrics.get(source);
+ Map<LoadMetric<LoadContext>, List<Double>> sourceLoadHistory = this.loadHistory.get(source);
- if (sourceMetrics == null)
+ if (sourceLoadHistory == null)
{
- sourceMetrics = new ArrayList<LoadMetric<LoadContext>>();
- this.metrics.put(source, sourceMetrics);
+ sourceLoadHistory = new LinkedHashMap<LoadMetric<LoadContext>, List<Double>>();
+
+ this.loadHistory.put(source, sourceLoadHistory);
}
-
- sourceMetrics.add(metric);
+
+ sourceLoadHistory.put(metric, new ArrayList<Double>(this.history + 1));
}
}
/**
* @{inheritDoc}
+ * @see org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProviderMBean#getMetrics()
+ */
+ public Collection<LoadMetricMBean> getMetrics()
+ {
+ Collection<LoadMetricMBean> metrics = new LinkedList<LoadMetricMBean>();
+
+ for (Map<LoadMetric<LoadContext>, List<Double>> sourceLoadHistory: this.loadHistory.values())
+ {
+ for (LoadMetric<LoadContext> metric: sourceLoadHistory.keySet())
+ {
+ metrics.add(metric);
+ }
+ }
+
+ return Collections.unmodifiableCollection(metrics);
+ }
+
+ /**
+ * @{inheritDoc}
* @see org.jboss.modcluster.load.LoadBalanceFactorProvider#getLoadBalanceFactor()
*/
public synchronized int getLoadBalanceFactor()
@@ -76,15 +97,15 @@
int totalWeight = 0;
double totalWeightedLoad = 0;
- for (Map.Entry<LoadMetricSource<LoadContext>, Collection<LoadMetric<LoadContext>>> entry: this.metrics.entrySet())
+ for (Map.Entry<LoadMetricSource<LoadContext>, Map<LoadMetric<LoadContext>, List<Double>>> loadHistoryEntry: this.loadHistory.entrySet())
{
- LoadMetricSource<LoadContext> source = entry.getKey();
- Collection<LoadMetric<LoadContext>> metrics = entry.getValue();
+ LoadMetricSource<LoadContext> source = loadHistoryEntry.getKey();
+ Map<LoadMetric<LoadContext>, List<Double>> sourceLoadHistory = loadHistoryEntry.getValue();
boolean skip = true;
// Skip this source if all weights are 0
- for (LoadMetric<LoadContext> metric: metrics)
+ for (LoadMetric<LoadContext> metric: sourceLoadHistory.keySet())
{
skip = skip && (metric.getWeight() <= 0);
}
@@ -95,19 +116,23 @@
try
{
- for (LoadMetric<LoadContext> metric: metrics)
+ for (Map.Entry<LoadMetric<LoadContext>, List<Double>> entry: sourceLoadHistory.entrySet())
{
+ LoadMetric<LoadContext> metric = entry.getKey();
+
int weight = metric.getWeight();
if (weight > 0)
{
+ List<Double> metricLoadHistory = entry.getValue();
+
try
{
// Normalize load with respect to capacity
- List<Double> queue = this.recordLoad(metric, metric.getLoad(context) / metric.getCapacity());
+ this.recordLoad(metricLoadHistory, metric.getLoad(context) / metric.getCapacity());
totalWeight += weight;
- totalWeightedLoad += this.average(queue) * weight;
+ totalWeightedLoad += this.average(metricLoadHistory) * weight;
}
catch (Exception e)
{
@@ -130,18 +155,10 @@
return 100 - Math.max(0, Math.min(load, 100));
}
- private List<Double> recordLoad(LoadMetric<LoadContext> metric, double load)
+ private void recordLoad(List<Double> queue, double load)
{
- List<Double> queue = this.loadHistory.get(metric);
-
- if (queue == null)
+ if (!queue.isEmpty())
{
- queue = new ArrayList<Double>(this.history + 1);
-
- this.loadHistory.put(metric, queue);
- }
- else
- {
// History could have changed, so prune queue accordingly
for (int i = (queue.size() - 1); i >= this.history; --i)
{
@@ -149,10 +166,8 @@
}
}
- // Add new load to the front
+ // Add new load to the head
queue.add(0, new Double(load));
-
- return queue;
}
/**
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java 2008-12-02 19:24:44 UTC (rev 2084)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java 2008-12-02 20:08:49 UTC (rev 2085)
@@ -21,7 +21,10 @@
*/
package org.jboss.modcluster.load.impl;
+import java.util.Collection;
+import org.jboss.modcluster.load.metric.LoadMetricMBean;
+
/**
* @author Paul Ferraro
*
@@ -51,4 +54,10 @@
* @param decayFactor the new decay factor
*/
void setDecayFactor(int decayFactor);
+
+ /**
+ * Returns the load metrics registered with this provider
+ * @return a collection of load metrics
+ */
+ Collection<LoadMetricMBean> getMetrics();
}
16 years
JBoss Native SVN: r2084 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/load.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 14:24:44 -0500 (Tue, 02 Dec 2008)
New Revision: 2084
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/LoadBalanceFactorProviderFactory.java
Log:
Factory interface for creating LoadBalanceFactorProvider instances.
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/LoadBalanceFactorProviderFactory.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/LoadBalanceFactorProviderFactory.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/LoadBalanceFactorProviderFactory.java 2008-12-02 19:24:44 UTC (rev 2084)
@@ -0,0 +1,31 @@
+/*
+ * 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.load;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface LoadBalanceFactorProviderFactory
+{
+ LoadBalanceFactorProvider createLoadBalanceFactorProvider();
+}
16 years
JBoss Native SVN: r2083 - in trunk/mod_cluster/src/main/java/org/jboss/modcluster/load: metric and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 14:24:03 -0500 (Tue, 02 Dec 2008)
New Revision: 2083
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java
Log:
Revert configuration interface sharing
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java 2008-12-02 19:22:41 UTC (rev 2082)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/impl/DynamicLoadBalanceFactorProviderMBean.java 2008-12-02 19:24:03 UTC (rev 2083)
@@ -21,15 +21,26 @@
*/
package org.jboss.modcluster.load.impl;
-import org.jboss.modcluster.config.LoadBalanceFactorProviderConfiguration;
/**
* @author Paul Ferraro
*
*/
-public interface DynamicLoadBalanceFactorProviderMBean extends LoadBalanceFactorProviderConfiguration
+public interface DynamicLoadBalanceFactorProviderMBean
{
/**
+ * Returns the history count.
+ * @return a positive integer
+ */
+ int getHistory();
+
+ /**
+ * Returns the exponential decay factor.
+ * @return a positive integer
+ */
+ int getDecayFactor();
+
+ /**
* Sets the number of historical load values to consider when calculating the load balance factor.
* @param history
*/
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java 2008-12-02 19:22:41 UTC (rev 2082)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/load/metric/LoadMetricMBean.java 2008-12-02 19:24:03 UTC (rev 2083)
@@ -21,15 +21,26 @@
*/
package org.jboss.modcluster.load.metric;
-import org.jboss.modcluster.config.LoadMetricConfiguration;
-
-
/**
* @author Paul Ferraro
*
*/
-public interface LoadMetricMBean extends LoadMetricConfiguration
+public interface LoadMetricMBean
{
+ /**
+ * Returns the "weight" of this metric, i.e. significance of this load metric compared to the other metrics.
+ * @return the weight of the metric
+ */
+ int getWeight();
+
+ /**
+ * Returns the load capacity of this metric.
+ * Used to normalize the value returned by {@link #getLoad()} expressed as a percentage of the capacity, such that:
+ * 0 <= ({@link #getLoad()} / {@link #getCapacity()}) < 1
+ * @return the estimated capacity of this metric.
+ */
+ double getCapacity();
+
void setWeight(int weight);
void setCapacity(double capacity);
16 years
JBoss Native SVN: r2082 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 14:22:41 -0500 (Tue, 02 Dec 2008)
New Revision: 2082
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/GroupRpcResponse.java
Log:
Cosmetic
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/GroupRpcResponse.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/GroupRpcResponse.java 2008-12-02 15:45:51 UTC (rev 2081)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/GroupRpcResponse.java 2008-12-02 19:22:41 UTC (rev 2082)
@@ -25,10 +25,9 @@
import java.io.Serializable;
import org.jboss.ha.framework.interfaces.ClusterNode;
-import org.jboss.modcluster.ModClusterService;
/**
- * A response to a group RPC call made by {@link ModClusterService}.
+ * A response to a group RPC call made by {@link org.jboss.modcluster.ha.HAModClusterService}.
*
* @author Brian Stansberry
*/
@@ -48,5 +47,4 @@
{
return this.sender;
}
-
}
16 years
JBoss Native SVN: r2081 - trunk/mod_cluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-12-02 10:45:51 -0500 (Tue, 02 Dec 2008)
New Revision: 2081
Modified:
trunk/mod_cluster/.classpath
Log:
Refreshed dependencies
Modified: trunk/mod_cluster/.classpath
===================================================================
--- trunk/mod_cluster/.classpath 2008-12-02 15:44:00 UTC (rev 2080)
+++ trunk/mod_cluster/.classpath 2008-12-02 15:45:51 UTC (rev 2081)
@@ -5,18 +5,17 @@
<classpathentry kind="src" output="target/demo/classes" path="src/demo/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="M2_REPO/org/jboss/cluster/jboss-ha-server-api/1.1.0.GA/jboss-ha-server-api-1.1.0.GA.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/web/jbossweb/2.1.1.CR6/jbossweb-2.1.1.CR6.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar"/>
<classpathentry kind="var" path="M2_REPO/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar"/>
<classpathentry kind="var" path="M2_REPO/org/easymock/easymock/2.4/easymock-2.4.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-kernel/2.0.0.Beta17/jboss-kernel-2.0.0.Beta17.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar"/>
- <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/naming/jnp-client/5.0.0.CR2/jnp-client-5.0.0.CR2.jar" sourcepath="M2_REPO/org/jboss/naming/jnp-client/5.0.0.CR2/jnp-client-5.0.0.CR2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/jfree/jcommon/1.0.12/jcommon-1.0.12.jar"/>
<classpathentry kind="var" path="M2_REPO/jfree/jfreechart/1.0.9/jfreechart-1.0.9.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/web/jbossweb/2.1.1.GA/jbossweb-2.1.1.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/web/servlet-api/2.1.1.GA/servlet-api-2.1.1.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-kernel/2.0.2.GA/jboss-kernel-2.0.2.GA.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
16 years