Author: pferraro
Date: 2008-09-05 12:51:41 -0400 (Fri, 05 Sep 2008)
New Revision: 1782
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java
Log:
Extract interface from HASingletonAwareResetRequestSource so that ModClusterService can be
unit testing using a mock impl.
Let DefaultJBossEventWebEventHandler determine its AdvertiseListenerFactory impl.
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-05
14:47:50 UTC (rev 1781)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-05
16:51:41 UTC (rev 1782)
@@ -34,6 +34,7 @@
import org.jboss.logging.Logger;
import org.jboss.modcluster.advertise.AdvertiseListener;
import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
+import org.jboss.modcluster.advertise.impl.AdvertiseListenerFactoryImpl;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -70,7 +71,13 @@
// ----------------------------------------------------------- Constructors
- public DefaultJBossWebEventHandler(NodeConfiguration nodeConfiguration,
BalancerConfiguration balancerConfiguration,
+ public DefaultJBossWebEventHandler(NodeConfiguration nodeConfig, BalancerConfiguration
balancerConfig,
+ MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider)
+ {
+ this(nodeConfig, balancerConfig, mcmpHandler, loadBalanceFactorProvider, new
AdvertiseListenerFactoryImpl());
+ }
+
+ protected DefaultJBossWebEventHandler(NodeConfiguration nodeConfiguration,
BalancerConfiguration balancerConfiguration,
MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider,
AdvertiseListenerFactory listenerFactory)
{
this.nodeConfiguration = nodeConfiguration;
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-05
14:47:50 UTC (rev 1781)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-05
16:51:41 UTC (rev 1782)
@@ -46,7 +46,6 @@
import org.jboss.ha.framework.server.HAServiceImpl;
import org.jboss.ha.framework.server.HAServiceRpcHandler;
import org.jboss.ha.framework.server.HASingletonImpl;
-import org.jboss.modcluster.advertise.impl.AdvertiseListenerFactoryImpl;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.ModClusterConfig;
@@ -54,14 +53,8 @@
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.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.ha.rpc.BooleanGroupRpcResponse;
import org.jboss.modcluster.ha.rpc.ClusteredMCMPHandlerRpcHandler;
import org.jboss.modcluster.ha.rpc.GroupRpcResponse;
@@ -73,6 +66,13 @@
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.impl.DefaultMCMPHandler;
/**
@@ -147,12 +147,12 @@
this.setHAPartition(partition);
- this.resetRequestSource = new HASingletonAwareResetRequestSource(config, config,
this);
+ this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config,
config, this);
this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
// this.localHandler.init();
this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this);
this.loadManager = loadFactorProvider;
- this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config,
this.clusteredHandler, loadFactorProvider, new AdvertiseListenerFactoryImpl());
+ this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config,
this.clusteredHandler, loadFactorProvider);
this.domain = config.getDomain();
this.masterPerDomain = config.isMasterPerDomain();
@@ -695,7 +695,7 @@
}
}
- private void updateLocalDRM(ModClusterServiceDRMEntry ourNewStatus) throws Error
+ private void updateLocalDRM(ModClusterServiceDRMEntry ourNewStatus)
{
try
{
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-09-05
14:47:50 UTC (rev 1781)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-09-05
16:51:41 UTC (rev 1782)
@@ -19,149 +19,25 @@
* 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.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import org.apache.catalina.Server;
-import org.apache.catalina.util.StringManager;
-import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
-import org.jboss.logging.Logger;
-import org.jboss.modcluster.config.BalancerConfiguration;
-import org.jboss.modcluster.config.NodeConfiguration;
import org.jboss.modcluster.mcmp.MCMPRequest;
-import org.jboss.modcluster.mcmp.MCMPUtils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
-import org.jboss.modcluster.Constants;
-import org.jboss.modcluster.Utils;
-import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
-import org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler;
-import org.jboss.modcluster.ha.rpc.ThrowableGroupRpcResponse;
/**
- * {@link ResetRequestSource} that provides different reset requests
- * depending on whether or not it believes it is running on the singleton
- * master.
- *
- * @author Brian Stansberry
+ * @author Paul Ferraro
+ *
*/
-public class HASingletonAwareResetRequestSource implements ResetRequestSource
+public interface HASingletonAwareResetRequestSource extends ResetRequestSource
{
- static final String METHOD_NAME = "getResetRequests";
- static final Object[] ARGS = new Object[0];
- static final Class<?>[] TYPES = new Class[0];
-
- private static final Logger log =
Logger.getLogger(HASingletonAwareResetRequestSource.class);
-
- /**
- * The string manager for this package.
- */
- private final StringManager sm = StringManager.getManager(Constants.Package);
-
- private final NodeConfiguration nodeConfig;
- private final BalancerConfiguration balancerConfig;
- private final ResetRequestSourceRpcHandler<List<?>> rpcStub;
- private volatile boolean master;
- private volatile Server jbossWebServer;
-
- public HASingletonAwareResetRequestSource(NodeConfiguration nodeConfig,
BalancerConfiguration balancerConfig, HAServiceKeyProvider serviceKeyProvider)
- {
- this.nodeConfig = nodeConfig;
- this.balancerConfig = balancerConfig;
- this.rpcStub = new RpcStub(serviceKeyProvider);
- }
-
- public List<MCMPRequest> getResetRequests()
- {
- if (this.master)
- {
- List<MCMPRequest> resets = this.getLocalResetRequests();
- this.addRemoteRequests(resets);
- return resets;
- }
+ List<MCMPRequest> getLocalResetRequests();
- return Collections.emptyList();
- }
+ boolean isMasterNode();
- public List<MCMPRequest> getLocalResetRequests()
- {
- if (this.jbossWebServer == null)
- {
- return new ArrayList<MCMPRequest>();
- }
-
- return MCMPUtils.getResetRequests(this.jbossWebServer, this.nodeConfig,
this.balancerConfig);
- }
+ void setMasterNode(boolean master);
- public boolean isMasterNode()
- {
- return this.master;
- }
-
- public void setMasterNode(boolean master)
- {
- this.master = master;
- }
-
- public void setJbossWebServer(Server jbossWebServer)
- {
- this.jbossWebServer = jbossWebServer;
- }
-
- private void addRemoteRequests(List<MCMPRequest> resets)
- {
- List<?> responses = this.rpcStub.getResetRequests();
-
- for (Object response : responses)
- {
- if (response instanceof ResetRequestGroupRpcResponse)
- {
- resets.addAll(((ResetRequestGroupRpcResponse) response).getValue());
- }
- else if (response instanceof ThrowableGroupRpcResponse)
- {
- ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
- //FIXME what to do?
- log.warn(this.sm.getString("modcluster.error.rpc.known",
METHOD_NAME, tgrr.getSender()), tgrr.getValue());
- }
- else if (response instanceof Throwable)
- {
- log.warn(this.sm.getString("modcluster.error.rpc.unknown",
METHOD_NAME), (Throwable) response);
- }
- else
- {
- log.error(this.sm.getString("modcluster.error.rpc.unexpected",
response, METHOD_NAME));
- }
-
- }
- }
-
- private class RpcStub implements ResetRequestSourceRpcHandler<List<?>>
- {
- private final HAServiceKeyProvider serviceKeyProvider;
-
- public RpcStub(HAServiceKeyProvider serviceKeyProvider)
- {
- this.serviceKeyProvider = serviceKeyProvider;
- }
-
- /**
- * @see
org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
- */
- public List<?> getResetRequests()
- {
- try
- {
- return
this.serviceKeyProvider.getHAPartition().callMethodOnCluster(this.serviceKeyProvider.getHAServiceKey(),
METHOD_NAME, ARGS, TYPES, true);
- }
- catch (Exception e)
- {
- //FIXME what to do?
- throw Utils.convertToUnchecked(e);
- }
- }
- }
-}
+ void setJbossWebServer(Server jbossWebServer);
+}
\ No newline at end of file
Copied:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
(from rev 1774,
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java)
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
(rev 0)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-09-05
16:51:41 UTC (rev 1782)
@@ -0,0 +1,183 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.catalina.Server;
+import org.apache.catalina.util.StringManager;
+import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
+import org.jboss.logging.Logger;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+import org.jboss.modcluster.mcmp.MCMPRequest;
+import org.jboss.modcluster.mcmp.MCMPUtils;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.Utils;
+import org.jboss.modcluster.ha.rpc.ResetRequestGroupRpcResponse;
+import org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler;
+import org.jboss.modcluster.ha.rpc.ThrowableGroupRpcResponse;
+
+/**
+ * {@link ResetRequestSource} that provides different reset requests
+ * depending on whether or not it believes it is running on the singleton
+ * master.
+ *
+ * @author Brian Stansberry
+ */
+public class HASingletonAwareResetRequestSourceImpl implements
HASingletonAwareResetRequestSource
+{
+ static final String METHOD_NAME = "getResetRequests";
+ static final Object[] ARGS = new Object[0];
+ static final Class<?>[] TYPES = new Class[0];
+
+ private static final Logger log =
Logger.getLogger(HASingletonAwareResetRequestSourceImpl.class);
+
+ /**
+ * The string manager for this package.
+ */
+ private final StringManager sm = StringManager.getManager(Constants.Package);
+
+ private final NodeConfiguration nodeConfig;
+ private final BalancerConfiguration balancerConfig;
+ private final ResetRequestSourceRpcHandler<List<?>> rpcStub;
+ private volatile boolean master;
+ private volatile Server jbossWebServer;
+
+ public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig,
BalancerConfiguration balancerConfig, HAServiceKeyProvider serviceKeyProvider)
+ {
+ this.nodeConfig = nodeConfig;
+ this.balancerConfig = balancerConfig;
+ this.rpcStub = new RpcStub(serviceKeyProvider);
+ }
+
+ public List<MCMPRequest> getResetRequests()
+ {
+ if (this.master)
+ {
+ List<MCMPRequest> resets = this.getLocalResetRequests();
+ this.addRemoteRequests(resets);
+ return resets;
+ }
+
+ return Collections.emptyList();
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#getLocalResetRequests()
+ */
+ public List<MCMPRequest> getLocalResetRequests()
+ {
+ if (this.jbossWebServer == null)
+ {
+ return new ArrayList<MCMPRequest>();
+ }
+
+ return MCMPUtils.getResetRequests(this.jbossWebServer, this.nodeConfig,
this.balancerConfig);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#isMasterNode()
+ */
+ public boolean isMasterNode()
+ {
+ return this.master;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#setMasterNode(boolean)
+ */
+ public void setMasterNode(boolean master)
+ {
+ this.master = master;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#setJbossWebServer(org.apache.catalina.Server)
+ */
+ public void setJbossWebServer(Server jbossWebServer)
+ {
+ this.jbossWebServer = jbossWebServer;
+ }
+
+ private void addRemoteRequests(List<MCMPRequest> resets)
+ {
+ List<?> responses = this.rpcStub.getResetRequests();
+
+ for (Object response : responses)
+ {
+ if (response instanceof ResetRequestGroupRpcResponse)
+ {
+ resets.addAll(((ResetRequestGroupRpcResponse) response).getValue());
+ }
+ else if (response instanceof ThrowableGroupRpcResponse)
+ {
+ ThrowableGroupRpcResponse tgrr = (ThrowableGroupRpcResponse) response;
+ //FIXME what to do?
+ log.warn(this.sm.getString("modcluster.error.rpc.known",
METHOD_NAME, tgrr.getSender()), tgrr.getValue());
+ }
+ else if (response instanceof Throwable)
+ {
+ log.warn(this.sm.getString("modcluster.error.rpc.unknown",
METHOD_NAME), (Throwable) response);
+ }
+ else
+ {
+ log.error(this.sm.getString("modcluster.error.rpc.unexpected",
response, METHOD_NAME));
+ }
+
+ }
+ }
+
+ private class RpcStub implements ResetRequestSourceRpcHandler<List<?>>
+ {
+ private final HAServiceKeyProvider serviceKeyProvider;
+
+ public RpcStub(HAServiceKeyProvider serviceKeyProvider)
+ {
+ this.serviceKeyProvider = serviceKeyProvider;
+ }
+
+ /**
+ * @see
org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
+ */
+ public List<?> getResetRequests()
+ {
+ try
+ {
+ return
this.serviceKeyProvider.getHAPartition().callMethodOnCluster(this.serviceKeyProvider.getHAServiceKey(),
METHOD_NAME, ARGS, TYPES, true);
+ }
+ catch (Exception e)
+ {
+ //FIXME what to do?
+ throw Utils.convertToUnchecked(e);
+ }
+ }
+ }
+}
Property changes on:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
___________________________________________________________________
Name: svn:mergeinfo
+