JBoss Native SVN: r1789 - trunk/mod_cluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-09 16:30:06 -0400 (Tue, 09 Sep 2008)
New Revision: 1789
Modified:
trunk/mod_cluster/pom.xml
Log:
Added servlet-api as test dependency.
Modified: trunk/mod_cluster/pom.xml
===================================================================
--- trunk/mod_cluster/pom.xml 2008-09-09 18:25:16 UTC (rev 1788)
+++ trunk/mod_cluster/pom.xml 2008-09-09 20:30:06 UTC (rev 1789)
@@ -55,17 +55,17 @@
</dependency>
<dependency>
- <groupId>org.jboss.microcontainer</groupId>
- <artifactId>jboss-kernel</artifactId>
- <version>2.0.0.Beta14</version>
- </dependency>
-
- <dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ <version>2.0.0.Beta14</version>
+ </dependency>
+
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
@@ -79,6 +79,12 @@
<version>2.4</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
15 years, 8 months
JBoss Native SVN: r1788 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/ha and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-09 14:25:16 -0400 (Tue, 09 Sep 2008)
New Revision: 1788
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
Log:
Replace copy of the master flag with a formal view of singleton master status.
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-08 16:23:59 UTC (rev 1787)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-09 18:25:16 UTC (rev 1788)
@@ -147,10 +147,10 @@
this.setHAPartition(partition);
- this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this);
+ this.resetRequestSource = new HASingletonAwareResetRequestSourceImpl(config, config, this, this);
this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource);
// this.localHandler.init();
- this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this);
+ this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this);
this.loadManager = loadFactorProvider;
this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config, this.clusteredHandler, loadFactorProvider);
this.domain = config.getDomain();
@@ -339,6 +339,7 @@
if (this.isMasterNode())
{
this.statusCount = (this.statusCount + 1) % this.processStatusFrequency;
+
if (this.statusCount == 0)
{
this.updateClusterStatus();
@@ -370,25 +371,11 @@
@Override
public void startSingleton()
{
- super.startSingleton();
-
- this.clusteredHandler.setMasterNode(true);
- this.resetRequestSource.setMasterNode(true);
-
// Ensure we do a full status on the next event
this.statusCount = this.processStatusFrequency - 1;
}
@Override
- public void stopSingleton()
- {
- super.stopSingleton();
-
- this.clusteredHandler.setMasterNode(false);
- this.resetRequestSource.setMasterNode(false);
- }
-
- @Override
@Inject(fromContext = FromContext.NAME)
public void setServiceHAName(String haName)
{
@@ -462,7 +449,7 @@
List<ClusterNode> narrowed = new ArrayList<ClusterNode>(candidates.size());
ModClusterServiceDRMEntry champion = null;
- for (ModClusterServiceDRMEntry candidate : candidates)
+ for (ModClusterServiceDRMEntry candidate: candidates)
{
if (champion == null)
{
@@ -505,7 +492,7 @@
HAPartition partition = this.getHAPartition();
List<ModClusterServiceDRMEntry> replicants = partition.getDistributedReplicantManager().lookupReplicants(this.getHAServiceKey());
Map<ClusterNode, ModClusterServiceDRMEntry> nonresponsive = new HashMap<ClusterNode, ModClusterServiceDRMEntry>();
- for (ModClusterServiceDRMEntry replicant : replicants)
+ for (ModClusterServiceDRMEntry replicant: replicants)
{
nonresponsive.put(replicant.getPeer(), replicant);
}
@@ -525,7 +512,7 @@
Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses = new HashMap<ClusterNode, PeerMCMPDiscoveryStatus>();
boolean resync = false;
- for (Object response : responses)
+ for (Object response: responses)
{
if (response instanceof ModClusterServiceStateGroupRpcResponse)
{
@@ -534,7 +521,7 @@
// Check for discovery events we haven't processed
MCMPServerDiscoveryEvent latestEvent = latestEvents.get(cn);
- for (MCMPServerDiscoveryEvent toCheck : mcssgrr.getUnacknowledgedEvents())
+ for (MCMPServerDiscoveryEvent toCheck: mcssgrr.getUnacknowledgedEvents())
{
if (latestEvent != null && latestEvent.getEventIndex() <= toCheck.getEventIndex())
{
@@ -567,7 +554,7 @@
if (removed != null)
{
Integer lbf = new Integer(mcssgrr.getLoadBalanceFactor());
- for (String jvmRoute : removed.getJvmRoutes())
+ for (String jvmRoute: removed.getJvmRoutes())
{
loadBalanceFactors.put(jvmRoute, lbf);
}
@@ -603,12 +590,12 @@
// Add error-state objects for non-responsive peers
Integer lbf = new Integer(0);
- for (Map.Entry<ClusterNode, ModClusterServiceDRMEntry> entry : nonresponsive.entrySet())
+ 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())
+ for (String jvmRoute: entry.getValue().getJvmRoutes())
{
loadBalanceFactors.put(jvmRoute, lbf);
}
@@ -621,7 +608,7 @@
// Pass along the LBF values
List<MCMPRequest> statusRequests = new ArrayList<MCMPRequest>();
- for (Map.Entry<String, Integer> entry : loadBalanceFactors.entrySet())
+ for (Map.Entry<String, Integer> entry: loadBalanceFactors.entrySet())
{
statusRequests.add(MCMPUtils.createStatusRequest(entry.getKey(), entry.getValue().intValue()));
}
@@ -631,8 +618,7 @@
this.notifyClusterStatusComplete(masterList, statuses);
}
- private void notifyClusterStatusComplete(Set<MCMPServerState> masterList,
- Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
+ private void notifyClusterStatusComplete(Set<MCMPServerState> masterList, Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses)
{
HAPartition partition = this.getHAPartition();
@@ -641,10 +627,12 @@
ModClusterServiceDRMEntry ourCurrentStatus = (ModClusterServiceDRMEntry) partition.getDistributedReplicantManager().lookupLocalReplicant(this.getHAServiceKey());
allStatuses.add(ourCurrentStatus);
- boolean othersFirst = this.narrowCandidateList(allStatuses).contains(partition.getClusterNode());
- ModClusterServiceDRMEntry ourNewStatus = new ModClusterServiceDRMEntry(partition.getClusterNode(), masterList);
- boolean updated = (ourNewStatus.equals(ourCurrentStatus) == false);
+ ClusterNode node = partition.getClusterNode();
+ boolean othersFirst = this.narrowCandidateList(allStatuses).contains(node);
+ ModClusterServiceDRMEntry ourNewStatus = new ModClusterServiceDRMEntry(node, masterList);
+ boolean updated = !ourNewStatus.equals(ourCurrentStatus);
+
if (othersFirst)
{
this.clusterStatusComplete(statuses);
@@ -664,7 +652,7 @@
this.clusterStatusComplete(statuses);
}
}
-
+
/**
* @see org.jboss.modcluster.ha.rpc.ModClusterServiceRpcHandler#clusterStatusComplete(java.util.Map)
*/
@@ -719,13 +707,9 @@
/*
public GroupRpcResponse getLocalAddress() throws IOException
{
- if (this.coord.isMasterNode())
- {
- return new InetAddressGroupRpcResponse(this.coord.getHAPartition().getClusterNode(),
- this.coord.localHandler.getLocalAddress());
- }
+ if (!this.coord.isMasterNode()) return null;
- return null;
+ return new InetAddressGroupRpcResponse(this.coord.getHAPartition().getClusterNode(), this.coord.localHandler.getLocalAddress());
}
*/
/**
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java 2008-09-08 16:23:59 UTC (rev 1787)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java 2008-09-09 18:25:16 UTC (rev 1788)
@@ -46,9 +46,6 @@
void recordResetTransmission();
void recordResetSuccess();
- boolean isMasterNode();
- void setMasterNode(boolean master);
-
String getHAServiceName();
String getPartitionName();
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2008-09-08 16:23:59 UTC (rev 1787)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2008-09-09 18:25:16 UTC (rev 1788)
@@ -34,6 +34,7 @@
import org.apache.catalina.util.StringManager;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
+import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.logging.Logger;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.mcmp.AbstractMCMPHandler;
@@ -64,11 +65,11 @@
final HAServiceKeyProvider serviceKeyProvider;
private final MCMPHandler localHandler;
+ private final HASingletonMBean singleton;
private final ClusteredMCMPHandlerRpcHandler rpcStub = new RpcStub();
// private AdvertiseListener advertiseListener;
private volatile String haServiceName;
- private volatile boolean masterNode = false;
@GuardedBy("errorState")
private final List<Boolean> errorState = new ArrayList<Boolean>();
@@ -83,24 +84,15 @@
*/
final StringManager sm = StringManager.getManager(Constants.Package);
- public ClusteredMCMPHandlerImpl(MCMPHandler localHandler, HAServiceKeyProvider serviceKeyProvider)
+ public ClusteredMCMPHandlerImpl(MCMPHandler localHandler, HASingletonMBean singleton, HAServiceKeyProvider serviceKeyProvider)
{
this.localHandler = localHandler;
+ this.singleton = singleton;
this.serviceKeyProvider = serviceKeyProvider;
}
// --------------------------------------------------- ClusteredMCMPHandler
-
- public boolean isMasterNode()
- {
- return this.masterNode;
- }
- public void setMasterNode(boolean masterNode)
- {
- this.masterNode = masterNode;
- }
-
/**
* @{inheritDoc}
* @see org.jboss.modcluster.ha.ClusteredMCMPHandler#getHAServiceName()
@@ -243,7 +235,7 @@
*/
public synchronized void addProxy(InetAddress address, int port)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.addProxy(address, port);
}
@@ -268,7 +260,7 @@
*/
public synchronized void removeProxy(InetAddress address, int port)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.removeProxy(address, port);
}
@@ -298,7 +290,7 @@
public String getProxyConfiguration()
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
return this.localHandler.getProxyConfiguration();
}
@@ -312,7 +304,7 @@
public void init(List<AddressPort> initialProxies)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.init(initialProxies);
}
@@ -332,7 +324,7 @@
public boolean isProxyHealthOK()
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
return this.localHandler.isProxyHealthOK();
}
@@ -348,7 +340,7 @@
{
this.recordRequestFailure();
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.markProxiesInError();
}
@@ -362,7 +354,7 @@
public void reset()
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.reset();
}
@@ -376,7 +368,7 @@
public void sendRequest(MCMPRequest request)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.sendRequest(request);
}
@@ -390,7 +382,7 @@
public void sendRequests(List<MCMPRequest> requests)
{
- if (this.isMasterNode())
+ if (this.singleton.isMasterNode())
{
this.localHandler.sendRequests(requests);
}
@@ -574,36 +566,4 @@
throw new IllegalStateException(ClusteredMCMPHandlerImpl.this.sm.getString("modcluster.error.rpc.noresp", methodName));
}
}
-
- private enum State
- {
- OK(false), REQUIRES_RESET(true), RESET_PENDING(true);
-
- private boolean error;
-
- State(boolean error)
- {
- this.error = error;
- }
-
- public boolean isError()
- {
- return this.error;
- }
-
- public State error()
- {
- return REQUIRES_RESET;
- }
-
- public State resetStart()
- {
- return this == REQUIRES_RESET ? RESET_PENDING : this;
- }
-
- public State resetEnd()
- {
- return this == RESET_PENDING ? OK : this;
- }
- }
}
\ No newline at end of file
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-08 16:23:59 UTC (rev 1787)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-09-09 18:25:16 UTC (rev 1788)
@@ -35,9 +35,5 @@
{
List<MCMPRequest> getLocalResetRequests();
- boolean isMasterNode();
-
- void setMasterNode(boolean master);
-
void setJbossWebServer(Server jbossWebServer);
}
\ No newline at end of file
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-09-08 16:23:59 UTC (rev 1787)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-09-09 18:25:16 UTC (rev 1788)
@@ -29,6 +29,7 @@
import org.apache.catalina.Server;
import org.apache.catalina.util.StringManager;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
+import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.logging.Logger;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -63,20 +64,21 @@
private final NodeConfiguration nodeConfig;
private final BalancerConfiguration balancerConfig;
+ private final HASingletonMBean singleton;
private final ResetRequestSourceRpcHandler<List<?>> rpcStub;
- private volatile boolean master;
private volatile Server jbossWebServer;
- public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, HAServiceKeyProvider serviceKeyProvider)
+ public HASingletonAwareResetRequestSourceImpl(NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, HASingletonMBean singleton, HAServiceKeyProvider serviceKeyProvider)
{
this.nodeConfig = nodeConfig;
this.balancerConfig = balancerConfig;
+ this.singleton = singleton;
this.rpcStub = new RpcStub(serviceKeyProvider);
}
public List<MCMPRequest> getResetRequests()
{
- if (this.master)
+ if (this.singleton.isMasterNode())
{
List<MCMPRequest> resets = this.getLocalResetRequests();
this.addRemoteRequests(resets);
@@ -102,24 +104,6 @@
/**
* @{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)
@@ -159,7 +143,7 @@
{
private final HAServiceKeyProvider serviceKeyProvider;
- public RpcStub(HAServiceKeyProvider serviceKeyProvider)
+ RpcStub(HAServiceKeyProvider serviceKeyProvider)
{
this.serviceKeyProvider = serviceKeyProvider;
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2008-09-08 16:23:59 UTC (rev 1787)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2008-09-09 18:25:16 UTC (rev 1788)
@@ -36,6 +36,7 @@
import org.jboss.ha.framework.interfaces.ClusterNode;
import org.jboss.ha.framework.interfaces.HAPartition;
import org.jboss.ha.framework.interfaces.HAServiceKeyProvider;
+import org.jboss.ha.framework.interfaces.HASingletonMBean;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.ha.ClusteredMCMPHandler;
import org.jboss.modcluster.ha.ClusteredMCMPHandlerImpl;
@@ -60,8 +61,9 @@
private MCMPHandler localHandler = EasyMock.createStrictMock(MCMPHandler.class);
private HAServiceKeyProvider keyProvider = EasyMock.createStrictMock(HAServiceKeyProvider.class);
private HAPartition partition = EasyMock.createStrictMock(HAPartition.class);
+ private HASingletonMBean singleton = EasyMock.createStrictMock(HASingletonMBean.class);
- private ClusteredMCMPHandler handler = new ClusteredMCMPHandlerImpl(this.localHandler, this.keyProvider);
+ private ClusteredMCMPHandler handler = new ClusteredMCMPHandlerImpl(this.localHandler, this.singleton, this.keyProvider);
public void testGetPartitionName()
{
@@ -91,23 +93,23 @@
List<AddressPort> list = Collections.singletonList(new AddressPort(address, port));
// Test master case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.init(list);
- EasyMock.replay(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.replay(this.localHandler, this.singleton, this.keyProvider, this.partition);
this.handler.init(list);
- EasyMock.verify(this.localHandler, this.keyProvider, this.partition);
- EasyMock.reset(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.verify(this.localHandler, this.singleton, this.keyProvider, this.partition);
+ EasyMock.reset(this.localHandler, this.singleton, this.keyProvider, this.partition);
// Test non-master case
- this.handler.setMasterNode(false);
-
Capture<List<AddressPort>> capturedList = new Capture<List<AddressPort>>();
Capture<Object[]> capturedEvents = new Capture<Object[]>();
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
this.localHandler.init(EasyMock.capture(capturedList));
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
@@ -118,11 +120,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key), EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents), EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.replay(this.localHandler, this.singleton, this.keyProvider, this.partition);
this.handler.init(list);
- EasyMock.verify(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.verify(this.localHandler, this.singleton, this.keyProvider, this.partition);
assertNotNull(capturedList.getValue());
assertTrue(capturedList.getValue().isEmpty());
@@ -144,7 +146,7 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.localHandler, this.keyProvider, this.partition);
+ EasyMock.reset(this.localHandler, this.singleton, this.keyProvider, this.partition);
}
public void testUpdateServersFromMasterNode() throws Exception
@@ -175,15 +177,15 @@
EasyMock.expect(this.localHandler.getProxyStates()).andReturn(states);
- EasyMock.replay(this.localHandler, server, state);
+ EasyMock.replay(this.localHandler, this.singleton, server, state);
Set<MCMPServerState> result = this.handler.updateServersFromMasterNode(Collections.singleton(server));
- EasyMock.verify(this.localHandler, server, state);
+ EasyMock.verify(this.localHandler, this.singleton, server, state);
assertSame(states, result);
- EasyMock.reset(this.localHandler, server, state);
+ EasyMock.reset(this.localHandler, this.singleton, server, state);
}
public void testGetConfiguration()
@@ -192,15 +194,15 @@
EasyMock.expect(this.localHandler.getConfiguration()).andReturn(configuration);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
MCMPHandlerConfiguration result = this.handler.getConfiguration();
- EasyMock.verify(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
assertSame(configuration, result);
- EasyMock.reset(this.localHandler);
+ EasyMock.reset(this.localHandler, this.singleton);
}
public void testAddProxy() throws Exception
@@ -209,39 +211,43 @@
int port = 0;
// Test master use case
- this.handler.setMasterNode(true);
+ // Test MCMPHandler.addProxy(String)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
- // Test MCMPHandler.addProxy(String)
this.localHandler.addProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.addProxy(address.getHostName() + ":" + port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.addProxy(String, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+
this.localHandler.addProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.addProxy(address.getHostName(), port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+
this.localHandler.addProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.addProxy(address, port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int, boolean)
@@ -256,13 +262,13 @@
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
Capture<Object[]> capturedEvents = new Capture<Object[]>();
ClusterNode node = EasyMock.createMock(ClusterNode.class);
// Test MCMPHandler.addProxy(String)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -271,11 +277,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key), EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents), EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.addProxy(address.getHostName() + ":" + port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
List<MCMPServerDiscoveryEvent> events = this.handler.getPendingDiscoveryEvents();
@@ -294,10 +300,12 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.addProxy(String, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -306,11 +314,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key), EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents), EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.addProxy(address.getHostName(), port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
events = this.handler.getPendingDiscoveryEvents();
@@ -329,10 +337,12 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -341,11 +351,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key), EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents), EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.addProxy(address, port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
events = this.handler.getPendingDiscoveryEvents();
@@ -364,7 +374,7 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.addProxy(InetAddress, int, boolean)
@@ -384,38 +394,40 @@
int port = 0;
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
// Test MCMPHandler.removeProxy(String, int)
this.localHandler.removeProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.removeProxy(address.getHostName(), port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test MCMPHandler.removeProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+
this.localHandler.removeProxy(address, port);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.removeProxy(address, port);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
Capture<Object[]> capturedEvents = new Capture<Object[]>();
ClusterNode node = EasyMock.createMock(ClusterNode.class);
// Test MCMPHandler.removeProxy(String, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -424,11 +436,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key), EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents), EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.removeProxy(address.getHostName(), port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
List<MCMPServerDiscoveryEvent> events = this.handler.getPendingDiscoveryEvents();
@@ -447,10 +459,12 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
// Test MCMPHandler.removeProxy(InetAddress, int)
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.partition.getClusterNode()).andReturn(node);
@@ -459,11 +473,11 @@
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.eq(key), EasyMock.eq("mcmpServerDiscoveryEvent"), EasyMock.capture(capturedEvents), EasyMock.aryEq(new Class[] { MCMPServerDiscoveryEvent.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.removeProxy(address, port);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
events = this.handler.getPendingDiscoveryEvents();
@@ -482,7 +496,7 @@
assertEquals(1, capturedEvents.getValue().length);
assertSame(event, capturedEvents.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testGetProxyStates()
@@ -524,149 +538,149 @@
String configuration = "configuration";
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
EasyMock.expect(this.localHandler.getProxyConfiguration()).andReturn(configuration);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
String result = this.handler.getProxyConfiguration();
- EasyMock.verify(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
assertSame(configuration, result);
- EasyMock.reset(this.localHandler);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key), EasyMock.eq("getProxyConfiguration"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new StringGroupRpcResponse(node, configuration))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
result = this.handler.getProxyConfiguration();
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertSame(configuration, result);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testIsProxyHealthOK() throws Exception
{
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
EasyMock.expect(this.localHandler.isProxyHealthOK()).andReturn(true);
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
boolean result = this.handler.isProxyHealthOK();
- EasyMock.verify(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
assertTrue(result);
- EasyMock.reset(this.localHandler);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key), EasyMock.eq("isProxyHealthOk"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new BooleanGroupRpcResponse(node, true))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
result = this.handler.isProxyHealthOK();
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertTrue(result);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testMarkProxiesInError() throws Exception
{
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.markProxiesInError();
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.markProxiesInError();
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key), EasyMock.eq("markProxiesInError"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new BooleanGroupRpcResponse(node, true))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.markProxiesInError();
- EasyMock.verify(this.keyProvider, this.partition);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testReset() throws Exception
{
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.reset();
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.reset();
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
-
String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key), EasyMock.eq("reset"), EasyMock.aryEq(new Object[0]), EasyMock.aryEq(new Class[0]), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new BooleanGroupRpcResponse(node, true))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.reset();
- EasyMock.verify(this.keyProvider, this.partition);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testSendRequest() throws Exception
@@ -674,41 +688,42 @@
MCMPRequest request = new MCMPRequest(MCMPRequestType.INFO, false, Collections.singletonMap("name", "value"));
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.sendRequest(EasyMock.same(request));
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.sendRequest(request);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
+ String key = "key";
- String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
Capture<Object[]> captured = new Capture<Object[]>();
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key), EasyMock.eq("sendRequest"), EasyMock.capture(captured), EasyMock.aryEq(new Class[] { MCMPRequest.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.sendRequest(request);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertNotNull(captured.getValue());
assertEquals(1, captured.getValue().length);
assertSame(request, captured.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testSendRequests() throws Exception
@@ -716,41 +731,42 @@
List<MCMPRequest> requests = Collections.emptyList();
// Test master use case
- this.handler.setMasterNode(true);
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
this.localHandler.sendRequests(EasyMock.same(requests));
- EasyMock.replay(this.localHandler);
+ EasyMock.replay(this.localHandler, this.singleton);
this.handler.sendRequests(requests);
- EasyMock.verify(this.localHandler);
- EasyMock.reset(this.localHandler);
+ EasyMock.verify(this.localHandler, this.singleton);
+ EasyMock.reset(this.localHandler, this.singleton);
// Test non-master use case
- this.handler.setMasterNode(false);
+ String key = "key";
- String key = "key";
ClusterNode node = EasyMock.createMock(ClusterNode.class);
Capture<Object[]> captured = new Capture<Object[]>();
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(false);
+
EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
EasyMock.expect(this.keyProvider.getHAServiceKey()).andReturn(key);
EasyMock.expect(this.partition.callMethodOnCluster(EasyMock.same(key), EasyMock.eq("sendRequests"), EasyMock.capture(captured), EasyMock.aryEq(new Class[] { List.class }), EasyMock.eq(false), EasyMock.isA(GroupRpcResponseFilter.class))).andReturn(new ArrayList<GroupRpcResponse>(Collections.singleton(new GroupRpcResponse(node))));
- EasyMock.replay(this.keyProvider, this.partition);
+ EasyMock.replay(this.keyProvider, this.partition, this.singleton);
this.handler.sendRequests(requests);
- EasyMock.verify(this.keyProvider, this.partition);
+ EasyMock.verify(this.keyProvider, this.partition, this.singleton);
assertNotNull(captured.getValue());
assertEquals(1, captured.getValue().length);
assertSame(requests, captured.getValue()[0]);
- EasyMock.reset(this.keyProvider, this.partition);
+ EasyMock.reset(this.keyProvider, this.partition, this.singleton);
}
public void testShutdown()
15 years, 8 months
JBoss Native SVN: r1787 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-09-08 12:23:59 -0400 (Mon, 08 Sep 2008)
New Revision: 1787
Modified:
trunk/build/unix/build.sh
Log:
Done use database and ldap for jboss native.
Modified: trunk/build/unix/build.sh
===================================================================
--- trunk/build/unix/build.sh 2008-09-08 13:54:16 UTC (rev 1786)
+++ trunk/build/unix/build.sh 2008-09-08 16:23:59 UTC (rev 1787)
@@ -720,11 +720,20 @@
# Build apr-util
# $1 directory of the sources directory
# $2 static or shared
+# $3 true or false (use database and ldap).
buildapu()
{
apu_srcdir=$1
apu_static=$2
+ apu_util=$3
+ if $apu_util ; then
+ apu_conf="--with-dbm=sdbm"
+ else
+ # dissable database and ldap...
+ apu_conf="--without-pgsql --without-mysql --without-sqlite3 -without-sqlite2 --with-dbm=sdbm --without-ldap-lib"
+ fi
+
if $apu_static ; then
apu_common_dir=${build_common_dir}-static
else
@@ -753,7 +762,7 @@
)
else
(cd ${apu_srcdir}
- ./configure ${add_conf} --with-apr=${apu_common_dir} --prefix=${apu_common_dir} --with-expat=builtin --with-dbm=sdbm || exit 1
+ ./configure ${add_conf} --with-apr=${apu_common_dir} --prefix=${apu_common_dir} --with-expat=builtin ${apu_conf} || exit 1
echo "Building APR utilities ${apu_version} ..."
make || exit 1
make install || exit 1
@@ -939,9 +948,15 @@
fi
fi
if $has_apu; then
- buildapu srclib/apr-util-${apu_version} false || return 1
+ apu_util=true
+ case $PACKAGE in
+ jboss-native)
+ apu_util=false
+ ;;
+ esac
+ buildapu srclib/apr-util-${apu_version} false $apu_util || return 1
if $has_static ; then
- buildapu srclib/apr-util-${apu_version} true || return 1
+ buildapu srclib/apr-util-${apu_version} true $apu_util || return 1
fi
fi
fi
15 years, 8 months
JBoss Native SVN: r1786 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-09-08 09:54:16 -0400 (Mon, 08 Sep 2008)
New Revision: 1786
Modified:
trunk/build/unix/package.list
Log:
Use the tc-native possible release.
Modified: trunk/build/unix/package.list
===================================================================
--- trunk/build/unix/package.list 2008-09-08 13:41:19 UTC (rev 1785)
+++ trunk/build/unix/package.list 2008-09-08 13:54:16 UTC (rev 1786)
@@ -4,7 +4,7 @@
jboss-native|2.0.2|TOMCAT_NATIVE_1_1_11|apr:v:1.2.9|apu:v:1.2.8|api:v:1.2.1|ssl:v:0.9.8e|zlib:v:1.2.3
jboss-native|2.0.3|TOMCAT_NATIVE_1_1_12|apr:v:1.2.8|apu:v:1.2.8|api:v:1.2.1|ssl:v:0.9.8e|zlib:v:1.2.3
jboss-native|2.0.4|TOMCAT_NATIVE_1_1_13|apr:v:1.2.8|apu:v:1.2.8|api:v:1.2.1|ssl:v:0.9.8e|zlib:v:1.2.3
-jboss-native|2.0.5-dev|trunk|apr:v:1.2.8|apu:v:1.2.8|api:v:1.2.1|ssl:v:0.9.8h|zlib:v:1.2.3
+jboss-native|2.0.5|TOMCAT_NATIVE_1_1_15|apr:v:1.2.8|apu:v:1.2.8|api:v:1.2.1|ssl:v:0.9.8h|zlib:v:1.2.3
# SIGHT
jboss-sight|1.0.0|trunk|apr:v:1.2.9|apu:v:1.2.8|api:v:1.2.1
jboss-sight|1.0.1|trunk|apr:v:1.2.8|apu:v:1.2.8|api:v:1.2.1
15 years, 8 months
JBoss Native SVN: r1784 - in trunk/build/unix: util and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-09-08 04:33:13 -0400 (Mon, 08 Sep 2008)
New Revision: 1784
Modified:
trunk/build/unix/buildtest.jboss-native.sh
trunk/build/unix/util/buildroot.hpux.sh
Log:
Improve the hp-ux test environment.
Modified: trunk/build/unix/buildtest.jboss-native.sh
===================================================================
--- trunk/build/unix/buildtest.jboss-native.sh 2008-09-05 16:56:33 UTC (rev 1783)
+++ trunk/build/unix/buildtest.jboss-native.sh 2008-09-08 08:33:13 UTC (rev 1784)
@@ -71,6 +71,7 @@
chmod a+x ${base}/${root}/jbossas/${JBOSSDIR}/bin/jshutdown.sh
# start the jboss
+echo "Doing CHROOT in ${base}/${root}"
sudo /usr/sbin/chroot ${base}/${root} jbossas/${JBOSSDIR}/bin/run.sh -b ${IPLOCAL} > ${base}/${root}/jboss.out.txt &
sleep 60
Modified: trunk/build/unix/util/buildroot.hpux.sh
===================================================================
--- trunk/build/unix/util/buildroot.hpux.sh 2008-09-05 16:56:33 UTC (rev 1783)
+++ trunk/build/unix/util/buildroot.hpux.sh 2008-09-08 08:33:13 UTC (rev 1784)
@@ -23,7 +23,7 @@
#
# Build a chrootable environment.
# $1 : Directory where the chroot will takes place.
-tools="/bin/bash /etc/passwd /etc/group /etc/hosts /etc/netconfig /etc/resolv.conf /usr/lib/dld.sl /usr/lib/hpux32/uld.so /usr/lib/hpux32/dld.so /usr/lib/hpux32/libm.so.1 /usr/lib/hpux32/libpthread.so.1 /usr/lib/hpux32/libnss_dns.so.1 /usr/lib/libm.2 /usr/lib/libpthread.1 /usr/lib/libnss_dns.1"
+tools="/bin/bash /etc/passwd /etc/group /etc/hosts /etc/netconfig /etc/resolv.conf /usr/lib/dld.sl /usr/lib/hpux32/uld.so /usr/lib/hpux32/dld.so /usr/lib/hpux32/libm.so.1 /usr/lib/hpux32/libpthread.so.1 /usr/lib/hpux32/libnss_dns.so.1 /usr/lib/libm.2 /usr/lib/libpthread.1 /usr/lib/libnss_dns.1 /usr/lib/libCsup.2 /usr/lib/libcl.2 /usr/lib/libisamstub.1 /usr/lib/librt.2"
depfiles="/bin/sh /usr/bin/test /usr/bin/dirname /usr/bin/basename /usr/bin/uname /usr/bin/grep /usr/bin/sh /usr/bin/expr /usr/bin/false /usr/bin/true"
# tools are the tools we need for the tests.
# depfiles are files the packages needed (to be generated).
15 years, 8 months
JBoss Native SVN: r1783 - trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-05 12:56:33 -0400 (Fri, 05 Sep 2008)
New Revision: 1783
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java
Log:
Remove stray System.out
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java 2008-09-05 16:51:41 UTC (rev 1782)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java 2008-09-05 16:56:33 UTC (rev 1783)
@@ -497,15 +497,12 @@
}
if (server != null && status > 0)
{
- if (AdvertiseListenerImpl.this.md != null)
+ /* We need a digest to match */
+ if (!AdvertiseListenerImpl.this.verifyDigest(digest, server_name, date_str))
{
- /* We need a digest to match */
- if (!AdvertiseListenerImpl.this.verifyDigest(digest, server_name, date_str))
- {
- System.out.println("Digest mismatch");
- continue;
- }
+ continue;
}
+
server.setDate(date);
boolean rc = server.setStatus(status, status_desc);
if (added)
15 years, 8 months
JBoss Native SVN: r1782 - in trunk/mod_cluster/src/main/java/org/jboss/modcluster: ha and 1 other directory.
by jbossnative-commits@lists.jboss.org
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
+
15 years, 8 months
JBoss Native SVN: r1781 - trunk/mod_cluster/src/test/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-05 10:47:50 -0400 (Fri, 05 Sep 2008)
New Revision: 1781
Added:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
Log:
Unit test for DefaultJBossWebEventHandler
Added: trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java (rev 0)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2008-09-05 14:47:50 UTC (rev 1781)
@@ -0,0 +1,805 @@
+/*
+ * 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.io.IOException;
+import java.net.InetAddress;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+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.modcluster.advertise.AdvertiseListener;
+import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
+import org.jboss.modcluster.config.BalancerConfiguration;
+import org.jboss.modcluster.config.MCMPHandlerConfiguration;
+import org.jboss.modcluster.config.NodeConfiguration;
+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;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class DefaultJBossWebEventHandlerTestCase extends TestCase
+{
+ private final NodeConfiguration nodeConfig = EasyMock.createStrictMock(NodeConfiguration.class);
+ private final BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
+ private final MCMPHandler mcmpHandler = EasyMock.createStrictMock(MCMPHandler.class);
+ private final LoadBalanceFactorProvider provider = EasyMock.createStrictMock(LoadBalanceFactorProvider.class);
+ private final AdvertiseListenerFactory listenerFactory = EasyMock.createStrictMock(AdvertiseListenerFactory.class);
+
+ private JBossWebEventHandler handler;
+
+ /**
+ * @{inheritDoc}
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception
+ {
+ this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpHandler, this.provider, this.listenerFactory);
+ }
+
+ public void testInit() throws IOException
+ {
+ InetAddress localAddress = InetAddress.getLocalHost();
+ String localHostName = localAddress.getHostName();
+
+ MCMPHandlerConfiguration config = EasyMock.createStrictMock(MCMPHandlerConfiguration.class);
+ AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
+
+ // Test advertise = false
+ EasyMock.expect(this.mcmpHandler.getConfiguration()).andReturn(config);
+ EasyMock.expect(config.getProxyList()).andReturn(localHostName);
+
+ this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(config.getAdvertise()).andReturn(Boolean.FALSE);
+
+ EasyMock.replay(this.mcmpHandler, config, listener);
+
+ this.handler.init();
+
+ EasyMock.verify(this.mcmpHandler, config, listener);
+ EasyMock.reset(this.mcmpHandler, config, listener);
+
+
+ // Test advertise = true
+ EasyMock.expect(this.mcmpHandler.getConfiguration()).andReturn(config);
+ EasyMock.expect(config.getProxyList()).andReturn(localHostName);
+
+ this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(config.getAdvertise()).andReturn(Boolean.TRUE);
+
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler)).andReturn(listener);
+
+ listener.start();
+
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, config, listener);
+
+ this.handler.init();
+
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, config, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, config, listener);
+
+
+ // Test advertise = null, proxies configured
+ EasyMock.expect(this.mcmpHandler.getConfiguration()).andReturn(config);
+ EasyMock.expect(config.getProxyList()).andReturn(localHostName);
+
+ this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(config.getAdvertise()).andReturn(null);
+
+ EasyMock.replay(this.mcmpHandler, config, listener);
+
+ this.handler.init();
+
+ EasyMock.verify(this.mcmpHandler, config, listener);
+ EasyMock.reset(this.mcmpHandler, config, listener);
+
+
+ // Test advertise = null, no proxies configured
+ EasyMock.expect(this.mcmpHandler.getConfiguration()).andReturn(config);
+ EasyMock.expect(config.getProxyList()).andReturn(null);
+
+ List<AddressPort> emptyList = Collections.emptyList();
+
+ this.mcmpHandler.init(emptyList);
+
+ EasyMock.expect(config.getAdvertise()).andReturn(null);
+
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler)).andReturn(listener);
+
+ listener.start();
+
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, config, listener);
+
+ this.handler.init();
+
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, config, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, config, listener);
+ }
+
+ public void testShutdown() throws IOException
+ {
+ // Test w/out advertise listener
+ this.mcmpHandler.shutdown();
+
+ EasyMock.replay(this.mcmpHandler);
+
+ this.handler.shutdown();
+
+ EasyMock.verify(this.mcmpHandler);
+ EasyMock.reset(this.mcmpHandler);
+
+
+ // Test w/advertise listener
+ // First init() to create listener
+ InetAddress localAddress = InetAddress.getLocalHost();
+ String localHostName = localAddress.getHostName();
+
+ MCMPHandlerConfiguration config = EasyMock.createStrictMock(MCMPHandlerConfiguration.class);
+ AdvertiseListener listener = EasyMock.createStrictMock(AdvertiseListener.class);
+
+ EasyMock.expect(this.mcmpHandler.getConfiguration()).andReturn(config);
+ EasyMock.expect(config.getProxyList()).andReturn(localHostName);
+
+ this.mcmpHandler.init(Collections.singletonList(new AddressPort(localAddress, 8000)));
+
+ EasyMock.expect(config.getAdvertise()).andReturn(Boolean.TRUE);
+
+ EasyMock.expect(this.listenerFactory.createListener(this.mcmpHandler)).andReturn(listener);
+
+ listener.start();
+
+ EasyMock.replay(this.mcmpHandler, this.listenerFactory, config, listener);
+
+ this.handler.init();
+
+ EasyMock.verify(this.mcmpHandler, this.listenerFactory, config, listener);
+ EasyMock.reset(this.mcmpHandler, this.listenerFactory, config, listener);
+
+ // Now test shutdown()
+ listener.destroy();
+
+ this.mcmpHandler.shutdown();
+
+ EasyMock.replay(this.mcmpHandler, listener);
+
+ this.handler.shutdown();
+
+ EasyMock.verify(this.mcmpHandler, listener);
+ EasyMock.reset(this.mcmpHandler, listener);
+ }
+
+ public void testAddContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.addContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test context not started
+ Container container = EasyMock.createStrictMock(Container.class);
+
+ recordAddContext(context, container);
+
+ EasyMock.replay(context, container);
+
+ this.handler.addContext(context);
+
+ EasyMock.verify(context, container);
+ EasyMock.reset(context, container);
+
+ // Test context started
+ 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(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ EasyMock.expect(context.isStarted()).andReturn(true);
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+
+ this.handler.addContext(context);
+
+ EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ }
+
+ 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);
+ }
+
+ public void testStartContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.startContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test initialized
+ Container container = EasyMock.createStrictMock(Container.class);
+ 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(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+
+ this.handler.startContext(context);
+
+ EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ }
+
+ public void testStopContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.stopContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test initialized
+ Container container = EasyMock.createStrictMock(Container.class);
+ 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(container);
+ EasyMock.expect(container.getName()).andReturn("parent-container");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+
+ this.handler.stopContext(context);
+
+ EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ }
+
+ public void testRemoveContext() throws IOException
+ {
+ Context context = EasyMock.createStrictMock(Context.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.removeContext(context);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test initialized - no jvm route
+ Container container = EasyMock.createStrictMock(Container.class);
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ this.recordRemoveContext(context, container, engine);
+
+ EasyMock.replay(context, container, engine);
+
+ this.handler.removeContext(context);
+
+ EasyMock.verify(context, container, engine);
+ EasyMock.reset(context, container, engine);
+
+
+ // Test initialized - jvm route exists
+ 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(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("host1");
+
+ // Building request
+ EasyMock.expect(context.getParent()).andReturn(container);
+ EasyMock.expect(container.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+ EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+
+ this.handler.removeContext(context);
+
+ EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(3, parameters.size());
+
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("/context", parameters.get("Context"));
+ assertEquals("host,alias1,alias2", parameters.get("Alias"));
+
+ EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ }
+
+ 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);
+ }
+
+ public void testConfig() throws Exception
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+ Service service = EasyMock.createStrictMock(Service.class);
+
+ Capture<MCMPRequest> capturedRequest = recordConfig(engine, service);
+
+ EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, engine, service);
+
+ this.handler.config(engine);
+
+ EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, engine, service);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(17, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("172.0.0.1", parameters.get("Host"));
+ assertEquals("0", parameters.get("Port"));
+ assertEquals("ajp", parameters.get("Type"));
+ assertEquals("domain", parameters.get("Domain"));
+ assertEquals("On", parameters.get("flushpackets"));
+ assertEquals("1", parameters.get("flushwait"));
+ assertEquals("2", parameters.get("ping"));
+ assertEquals("3", parameters.get("smax"));
+ assertEquals("4", parameters.get("ttl"));
+ assertEquals("5", parameters.get("Timeout"));
+ assertEquals("S", parameters.get("Balancer"));
+ assertEquals("No", parameters.get("StickySession"));
+ assertEquals("Yes", parameters.get("StickySessionRemove"));
+ assertEquals("No", parameters.get("StickySessionForce"));
+ assertEquals("6", parameters.get("WaitWorker"));
+ assertEquals("7", parameters.get("Maxattempts"));
+
+ EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, engine, service);
+ }
+
+ private Capture<MCMPRequest> recordConfig(Engine engine, Service service) throws Exception
+ {
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+ Connector connector = new Connector("AJP/1.3");
+
+ // 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.getService()).andReturn(service);
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ 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.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ return capturedRequest;
+ }
+
+ public void testRemoveAll() throws IOException
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.removeAll(engine);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test initialized - no jvm route
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn(null);
+
+ EasyMock.replay(engine);
+
+ this.handler.removeAll(engine);
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
+
+
+ // Test initialized - jvm route exists
+ Capture<MCMPRequest> capturedRequest = this.recordRemoveAll(engine);
+
+ EasyMock.replay(this.mcmpHandler, engine);
+
+ this.handler.removeAll(engine);
+
+ EasyMock.verify(this.mcmpHandler, engine);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ assertTrue(request.isWildcard());
+ assertEquals(Collections.singletonMap("JVMRoute", "host1"), request.getParameters());
+
+ EasyMock.reset(this.mcmpHandler, engine);
+ }
+
+ private Capture<MCMPRequest> recordRemoveAll(Engine engine)
+ {
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
+
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1").times(2);
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ return capturedRequest;
+ }
+
+ public void testStatus() throws IOException
+ {
+ Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.removeAll(engine);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test initialized
+ Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
+
+ // Expect log message
+ EasyMock.expect(engine.getName()).andReturn("engine");
+
+ this.mcmpHandler.status();
+
+ EasyMock.expect(this.provider.getLoadBalanceFactor()).andReturn(10);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+
+ this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
+
+ EasyMock.replay(this.mcmpHandler, this.provider, engine);
+
+ this.handler.status(engine);
+
+ EasyMock.verify(this.mcmpHandler, this.provider, engine);
+
+ MCMPRequest request = capturedRequest.getValue();
+
+ assertSame(MCMPRequestType.STATUS, request.getRequestType());
+ assertFalse(request.isWildcard());
+
+ Map<String, String> parameters = request.getParameters();
+
+ assertEquals(2, parameters.size());
+ assertEquals("host1", parameters.get("JVMRoute"));
+ assertEquals("10", parameters.get("Load"));
+
+ EasyMock.reset(this.mcmpHandler, this.provider, engine);
+ }
+
+ public void testStartServer() throws Exception
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.startServer(server);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test initialized
+ Service service1 = EasyMock.createStrictMock(Service.class);
+ Service service2 = EasyMock.createStrictMock(Service.class);
+ Engine engine1 = EasyMock.createStrictMock(Engine.class);
+ Engine engine2 = EasyMock.createStrictMock(Engine.class);
+ Container container1 = EasyMock.createStrictMock(Container.class);
+ Container container2 = EasyMock.createStrictMock(Container.class);
+ Context context1 = EasyMock.createStrictMock(Context.class);
+ Context context2 = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service1, service2 });
+
+ EasyMock.expect(service1.getContainer()).andReturn(engine1);
+ this.recordConfig(engine1, service1);
+ EasyMock.expect(engine1.findChildren()).andReturn(new Container[] { container1 });
+ EasyMock.expect(container1.findChildren()).andReturn(new Container[] { context1 });
+ this.recordAddContext(context1, container1);
+
+ EasyMock.expect(service2.getContainer()).andReturn(engine2);
+ this.recordConfig(engine2, service2);
+ EasyMock.expect(engine2.findChildren()).andReturn(new Container[] { container2 });
+ EasyMock.expect(container2.findChildren()).andReturn(new Container[] { context2 });
+ this.recordAddContext(context2, container2);
+
+ EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+
+ this.handler.startServer(server);
+
+ EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ }
+
+ public void testStopServer() throws IOException
+ {
+ Server server = EasyMock.createStrictMock(Server.class);
+
+ // Test not initialized
+ try
+ {
+ this.handler.stopServer(server);
+
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // Expected
+ }
+
+ testInit();
+
+ // Test initialized
+ Service service1 = EasyMock.createStrictMock(Service.class);
+ Service service2 = EasyMock.createStrictMock(Service.class);
+ Engine engine1 = EasyMock.createStrictMock(Engine.class);
+ Engine engine2 = EasyMock.createStrictMock(Engine.class);
+ Container container1 = EasyMock.createStrictMock(Container.class);
+ Container container2 = EasyMock.createStrictMock(Container.class);
+ Context context1 = EasyMock.createStrictMock(Context.class);
+ Context context2 = EasyMock.createStrictMock(Context.class);
+
+ EasyMock.expect(server.findServices()).andReturn(new Service[] { service1, service2 });
+
+ EasyMock.expect(service1.getContainer()).andReturn(engine1);
+ this.recordRemoveAll(engine1);
+ EasyMock.expect(engine1.findChildren()).andReturn(new Container[] { container1 });
+ EasyMock.expect(container1.findChildren()).andReturn(new Container[] { context1 });
+ this.recordRemoveContext(context1, container1, engine1);
+
+ EasyMock.expect(service2.getContainer()).andReturn(engine2);
+ this.recordRemoveAll(engine2);
+ EasyMock.expect(engine2.findChildren()).andReturn(new Container[] { container2 });
+ EasyMock.expect(container2.findChildren()).andReturn(new Container[] { context2 });
+ this.recordRemoveContext(context2, container2, engine2);
+
+ EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+
+ this.handler.stopServer(server);
+
+ EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service1, service2, engine1, engine2, container1, container2, context1, context2);
+ }
+}
\ No newline at end of file
15 years, 8 months
JBoss Native SVN: r1780 - in trunk/mod_cluster/src/main/java/org/jboss/modcluster: advertise and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-09-05 10:47:30 -0400 (Fri, 05 Sep 2008)
New Revision: 1780
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListenerFactory.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseEventType.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerFactoryImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertisedServer.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseEventType.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertisedServer.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/advertise/AdvertiseListener.java
Log:
Extract interface from AdvertiseListener and create factory to decouple implementation from DefaultJBossWebEventHandler. DefaultJBossWebEventHandler and AdvertiseListener can now be unit tested independently.
Code cleanup.
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:44:11 UTC (rev 1779)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -30,10 +30,10 @@
import org.apache.catalina.Engine;
import org.apache.catalina.Server;
import org.apache.catalina.Service;
-import org.apache.catalina.core.StandardContext;
import org.apache.catalina.util.StringManager;
import org.jboss.logging.Logger;
import org.jboss.modcluster.advertise.AdvertiseListener;
+import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
import org.jboss.modcluster.config.BalancerConfiguration;
import org.jboss.modcluster.config.MCMPHandlerConfiguration;
import org.jboss.modcluster.config.NodeConfiguration;
@@ -62,7 +62,8 @@
private final BalancerConfiguration balancerConfiguration;
private final MCMPHandler mcmpHandler;
private final LoadBalanceFactorProvider loadBalanceFactorProvider;
-
+ private final AdvertiseListenerFactory listenerFactory;
+
private boolean init;
private AdvertiseListener advertiseListener;
@@ -70,12 +71,13 @@
// ----------------------------------------------------------- Constructors
public DefaultJBossWebEventHandler(NodeConfiguration nodeConfiguration, BalancerConfiguration balancerConfiguration,
- MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider)
+ MCMPHandler mcmpHandler, LoadBalanceFactorProvider loadBalanceFactorProvider, AdvertiseListenerFactory listenerFactory)
{
this.nodeConfiguration = nodeConfiguration;
this.balancerConfiguration = balancerConfiguration;
this.mcmpHandler = mcmpHandler;
this.loadBalanceFactorProvider = loadBalanceFactorProvider;
+ this.listenerFactory = listenerFactory;
}
// ---------------------------------------------------- JBossWebEventHandler
@@ -88,9 +90,19 @@
Boolean advertise = handlerConfig.getAdvertise();
- if (Boolean.TRUE.equals(advertise) || (advertise == null && initialProxies.size() == 0))
+ if (Boolean.TRUE.equals(advertise) || (advertise == null && initialProxies.isEmpty()))
{
- this.advertiseListener = new AdvertiseListener(this.mcmpHandler);
+ this.advertiseListener = this.listenerFactory.createListener(this.mcmpHandler);
+
+ try
+ {
+ this.advertiseListener.start();
+ }
+ catch (IOException e)
+ {
+ // TODO What now?
+ log.error(e.getMessage(), e);
+ }
}
this.init = true;
@@ -112,16 +124,16 @@
this.checkInit();
Service[] services = server.findServices();
- for (Service service : services)
+ for (Service service: services)
{
Engine engine = (Engine) service.getContainer();
this.config(engine);
Container[] children = engine.findChildren();
- for (Container element : children)
+ for (Container element: children)
{
Container[] children2 = element.findChildren();
- for (Container element2 : children2)
+ for (Container element2: children2)
{
this.addContext((Context) element2);
}
@@ -140,8 +152,11 @@
Service[] services = server.findServices();
for (Service service : services)
{
- this.removeAll((Engine) service.getContainer());
- Container[] children = service.getContainer().findChildren();
+ Engine engine = (Engine) service.getContainer();
+
+ this.removeAll(engine);
+
+ Container[] children = engine.findChildren();
for (Container element : children)
{
Container[] children2 = element.findChildren();
@@ -164,12 +179,13 @@
}
catch (Exception e)
{
+ e.printStackTrace();
this.mcmpHandler.markProxiesInError();
log.info(this.sm.getString("modcluster.error.addressJvmRoute"), e);
return;
}
- MCMPRequest request = MCMPUtils.createConfigRequest(engine, this.getNodeConfiguration(), this.getBalancerConfiguration());
+ MCMPRequest request = MCMPUtils.createConfigRequest(engine, this.nodeConfiguration, this.balancerConfiguration);
// Send CONFIG request
this.mcmpHandler.sendRequest(request);
@@ -179,7 +195,7 @@
{
this.checkInit();
- log.debug(this.sm.getString("modcluster.context.enable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
+ log.debug(this.sm.getString("modcluster.context.enable", context.getPath(), context.getParent().getName()));
// Send ENABLE-APP if state is started
if (context.isStarted())
@@ -215,7 +231,7 @@
{
this.checkInit();
- log.debug(this.sm.getString("modcluster.context.disable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
+ log.debug(this.sm.getString("modcluster.context.disable", context.getPath(), context.getParent().getName()));
// JVMRoute can be null here if nothing was ever initialized
if (Utils.getJvmRoute(context) != null)
@@ -249,7 +265,7 @@
this.mcmpHandler.status();
// Send STATUS request
- int lbf = this.getLoadBalanceFactorProvider().getLoadBalanceFactor();
+ int lbf = this.loadBalanceFactorProvider.getLoadBalanceFactor();
MCMPRequest request = MCMPUtils.createStatusRequest(engine, lbf);
this.mcmpHandler.sendRequest(request);
}
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:44:11 UTC (rev 1779)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -46,6 +46,7 @@
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;
@@ -151,7 +152,7 @@
// this.localHandler.init();
this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this);
this.loadManager = loadFactorProvider;
- this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config, this.clusteredHandler, loadFactorProvider);
+ this.eventHandlerDelegate = new DefaultJBossWebEventHandler(config, config, this.clusteredHandler, loadFactorProvider, new AdvertiseListenerFactoryImpl());
this.domain = config.getDomain();
this.masterPerDomain = config.isMasterPerDomain();
@@ -184,6 +185,7 @@
HASingletonAwareResetRequestSource resetRequestSource,
ClusteredMCMPHandler clusteredHandler,
LoadBalanceFactorProvider loadManager,
+ JBossWebEventHandler eventHandler,
HASingletonElectionPolicy electionPolicy)
{
super(new HAServiceEventFactory());
@@ -195,6 +197,7 @@
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");
+ assert eventHandler != null : this.sm.getString("modcluster.error.iae.null", "eventHandler");
this.setHAPartition(partition);
@@ -202,7 +205,7 @@
this.resetRequestSource = resetRequestSource;
this.clusteredHandler = clusteredHandler;
this.loadManager = loadManager;
- this.eventHandlerDelegate = new DefaultJBossWebEventHandler(nodeConfig, balancerConfig, clusteredHandler, loadManager);
+ this.eventHandlerDelegate = eventHandler;
this.domain = nodeConfig.getDomain();
this.masterPerDomain = mcmpHandlerConfig.isMasterPerDomain();
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseEventType.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseEventType.java 2008-09-05 14:44:11 UTC (rev 1779)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseEventType.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -1,62 +0,0 @@
-/*
- *
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- */
-
-package org.jboss.modcluster.advertise;
-
-/**
- * Set what type of event the AdvertiseEvent signals.
- * @param type The type of event. One of:
- * <PRE>
- * ON_NEW_SERVER -- New AdvertisedServer detected
- * ON_STATUS_CHANGE -- AdvertisedServer server changed status
- * </PRE>
- */
-public enum AdvertiseEventType
-{
- /** New AdvertisedServer detected */
- ON_NEW_SERVER( 0),
- /** AdvertisedServer server changed status */
- ON_STATUS_CHANGE( 1);
-
- private int value;
- private AdvertiseEventType(int v)
- {
- value = v;
- }
-
- public int valueOf()
- {
- return value;
- }
-
- public static AdvertiseEventType valueOf(int value)
- {
- for (AdvertiseEventType e : values()) {
- if (e.value == value)
- return e;
- }
- throw new IllegalArgumentException("Invalid initializer: " + value);
- }
-
-}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListener.java 2008-09-05 14:44:11 UTC (rev 1779)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListener.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -1,479 +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.
*
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+ * This 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 library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * This 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.
*
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
+ * 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.advertise;
import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.InetAddress;
-import java.net.MulticastSocket;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Locale;
-import org.apache.catalina.util.StringManager;
-import org.jboss.logging.Logger;
-import org.jboss.modcluster.config.MCMPHandlerConfiguration;
-import org.jboss.modcluster.mcmp.MCMPHandler;
-import org.jboss.modcluster.Constants;
-
-
-/** AdvertiseListener
- * Listens for Advertise messages from mod_cluster
+/**
+ * @author Paul Ferraro
*
- * @author Mladen Turk
- *
*/
-public class AdvertiseListener
+public interface AdvertiseListener
{
- /** Default port for listening Advertise messages.
- */
- public static int DEFAULT_PORT = 23364;
- /** Default Multicast group address for listening Advertise messages.
- */
- public static String DEFAULT_GROUP = "224.0.1.105";
+ /**
+ * Start the Listener, creating listener thread.
+ */
+ void start() throws IOException;
- private static final Logger log = Logger.getLogger(AdvertiseListener.class);
-
- private static String RFC_822_FMT = "EEE, d MMM yyyy HH:mm:ss Z";
- private int advertisePort = DEFAULT_PORT;
- private String groupAddress = DEFAULT_GROUP;
- private MulticastSocket ms;
- private SimpleDateFormat df;
- private boolean listening = true;
- private boolean initialized = false;
- private boolean running = false;
- private boolean paused = false;
- private boolean daemon = true;
- private byte [] secure = new byte[16];
- private String securityKey = null;
- private MessageDigest md = null;
+ /**
+ * Pause the listener, which will make it stop accepting new advertise
+ * messages.
+ */
+ void pause();
- private HashMap<String, AdvertisedServer> servers;
+ /**
+ * Resume the listener, which will make it start accepting new advertise
+ * messages again.
+ */
+ void resume();
- private MCMPHandler commHandler;
- private Thread workerThread;
-
- /**
- * The string manager for this package.
- */
- private StringManager sm = StringManager.getManager(Constants.Package);
+ /**
+ * Stop the endpoint. This will cause all processing threads to stop.
+ */
+ void stop();
-
- private static void digestString(MessageDigest md, String s)
- {
- int len = s.length();
- byte [] b = new byte[len];
- for (int i = 0; i < len; i++) {
- char c = s.charAt(i);
- if (c < 127)
- b[i] = (byte)c;
- else
- b[i] = '?';
- }
- md.update(b);
- }
-
- /** Create AdvertiseListener instance
- * @param eventHandler The event handler that will be used for
- * status and new server notifications.
- */
- public AdvertiseListener(MCMPHandler commHandler)
- {
- df = new SimpleDateFormat(RFC_822_FMT, Locale.US);
- servers = new HashMap<String, AdvertisedServer>();
- this.commHandler = commHandler;
-
- MCMPHandlerConfiguration config = commHandler.getConfiguration();
-
- if (config.getAdvertiseGroupAddress() != null) {
- setGroupAddress(config.getAdvertiseGroupAddress());
- }
- if (config.getAdvertisePort() > 0) {
- setAdvertisePort(config.getAdvertisePort());
- }
- try {
- if (config.getAdvertiseSecurityKey() != null) {
- setSecurityKey(config.getAdvertiseSecurityKey());
- }
- start();
- } catch (IOException e) {
- log.error(sm.getString("modcluster.error.startListener"), e);
- } catch (NoSuchAlgorithmException e) {
- // Should never happen
- log.error(sm.getString("modcluster.error.startListener"), e);
- }
- }
-
- /**
- * The default is true - the control thread will be
- * in daemon mode. If set to false, the control thread
- * will not be daemon - and will keep the process alive.
- */
- public void setDaemon(boolean b)
- {
- daemon = b;
- }
-
- public boolean getDaemon()
- {
- return daemon;
- }
-
- /** Set Advertise security key
- * @param key The key to use.<br/>
- * Security key must match the AdvertiseKey
- * on the advertised server.
- */
- public void setSecurityKey(String key)
- throws NoSuchAlgorithmException
- {
- securityKey = key;
- if (md == null)
- md = MessageDigest.getInstance("MD5");
- }
-
- /** Set Advertise port
- * @param port The UDP port to use.
- */
- public void setAdvertisePort(int port)
- {
- advertisePort = port;
- }
-
- public int getAdvertisePort()
- {
- return advertisePort;
- }
-
- /** Set Advertise Multicaset group address
- * @param address The IP or host address to use.
- */
- public void setGroupAddress(String address)
- {
- groupAddress = address;
- }
-
- /** Get Advertise Multicaset group address
- */
- public String getGroupAddress()
- {
- return groupAddress;
- }
-
- /** Get Collection of all AdvertisedServer instances.
- */
- public Collection<AdvertisedServer> getServers()
- {
- return servers.values();
- }
-
- /** Get AdvertiseServer server.
- * @param name Server name to get.
- */
- public AdvertisedServer getServer(String name)
- {
- return servers.get(name);
- }
-
- /** Remove the AdvertisedServer from the collection.
- * @param server Server to remove.
- */
- public void removeServer(AdvertisedServer server)
- {
- servers.remove(server);
- }
-
- private void init()
- throws IOException
- {
- ms = new MulticastSocket(advertisePort);
- ms.setTimeToLive(16);
- ms.joinGroup(InetAddress.getByName(groupAddress));
- initialized = true;
- }
-
- private void interruptDatagramReader()
- {
- if (!initialized)
- return;
- try {
- // Restrict to localhost.
- ms.setTimeToLive(0);
- DatagramPacket dp = new DatagramPacket(secure, secure.length,
- InetAddress.getByName(groupAddress),
- advertisePort);
- ms.send(dp);
- } catch (IOException e) {
- // Ignore
- }
- }
-
- /** Start the Listener, creating listener thread.
- */
- public void start()
- throws IOException
- {
- if (!initialized) {
- init();
- }
- if (!running) {
- SecureRandom random = new SecureRandom();
- random.nextBytes(secure);
- secure[0] = 0;
- running = true;
- paused = false;
- listening = true;
- AdvertiseListenerWorker aw = new AdvertiseListenerWorker();
- workerThread = new Thread(aw);
- workerThread.setDaemon(daemon);
- workerThread.start();
- }
- }
-
- /**
- * Pause the listener, which will make it stop accepting new advertise
- * messages.
- */
- public void pause()
- {
- if (running && !paused) {
- paused = true;
- interruptDatagramReader();
- }
- }
-
-
- /**
- * Resume the listener, which will make it start accepting new advertise
- * messages again.
- */
- public void resume()
- {
- if (running && paused) {
- // Genererate new private secure
- SecureRandom random = new SecureRandom();
- random.nextBytes(secure);
- secure[0] = 0;
- paused = false;
- }
- }
-
-
- /**
- * Stop the endpoint. This will cause all processing threads to stop.
- */
- public void stop()
- {
- if (running) {
- running = false;
- interruptDatagramReader();
- workerThread = null;
- }
- }
-
-
- /**
- * Deallocate listener and close sockets.
- */
- public void destroy()
- throws IOException
- {
- if (running) {
- stop();
- }
- if (initialized) {
- ms.leaveGroup(InetAddress.getByName(groupAddress));
- ms.close();
- initialized = false;
- ms = null;
- }
- }
-
- private boolean verifyDigest(String digest, String server, String date)
- {
- if (md == null)
- return true;
- md.reset();
- digestString(md, securityKey);
- digestString(md, date);
- digestString(md, server);
- byte [] our = md.digest();
- byte [] dst = new byte[digest.length() * 2];
- for (int i = 0, j = 0; i < digest.length(); i++) {
- char ch = digest.charAt(i);
- dst[j++] = (byte)((ch >= 'A') ? ((ch & 0xdf) - 'A') + 10 : (ch - '0'));
- }
- return true;
- }
-
- /**
- * True if listener is accepting the advetise messages.<br/>
- * If false it means that listener is experiencing some
- * network problems if running.
- */
- public boolean isListening()
- {
- return listening;
- }
-
-
- // ------------------------------------ AdvertiseListenerWorker Inner Class
- private class AdvertiseListenerWorker implements Runnable
- {
-
- protected AdvertiseListenerWorker()
- {
- // Nothing
- }
- /**
- * The background thread that listens for incoming Advertise packets
- * and hands them off to an appropriate AdvertiseEvent handler.
- */
- public void run() {
- byte[] buffer = new byte[512];
- // Loop until we receive a shutdown command
- while (running) {
- // Loop if endpoint is paused
- while (paused) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // Ignore
- }
- }
- try {
- DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
- ms.receive(dp);
- if (!running)
- break;
- byte [] data = dp.getData();
- boolean intr = false;
- if (dp.getLength() == secure.length) {
- int i;
- for (i = 0; i < secure.length; i++) {
- if (data[i] != secure[i])
- break;
- }
- if (i == secure.length)
- intr = true;
- }
- if (intr)
- continue;
- String s = new String(data, 0, dp.getLength(), "8859_1");
- if (!s.startsWith("HTTP/1."))
- continue;
-
- String [] headers = s.split("\r\n");
- String date_str = null;
- Date date = null;
- int status = 0;
- String status_desc = null;
- String digest = null;
- String server_name = null;
- AdvertisedServer server = null;
- boolean added = false;
- for (int i = 0; i < headers.length; i++) {
- if (i == 0) {
- String [] sline = headers[i].split(" ", 3);
- if (sline == null || sline.length != 3)
- break;
- status = Integer.parseInt(sline[1]);
- if (status < 100)
- break;
- status_desc = sline[2];
- }
- else {
- String [] hdrv = headers[i].split(": ", 2);
- if (hdrv == null || hdrv.length != 2)
- break;
- if (hdrv[0].equals("Date")) {
- date_str = hdrv[1];
- try {
- date = df.parse(date_str);
- } catch (ParseException e) {
- date = new Date();
- }
- }
- else if (hdrv[0].equals("Digest")) {
- digest = hdrv[1];
- }
- else if (hdrv[0].equals("Server")) {
- server_name = hdrv[1];
- server = servers.get(server_name);
- if (server == null) {
- server = new AdvertisedServer(server_name);
- added = true;
- }
- }
- else if (server != null) {
- server.setParameter(hdrv[0], hdrv[1]);
- }
- }
- }
- if (server != null && status > 0) {
- if (md != null) {
- /* We need a digest to match */
- if (!verifyDigest(digest, server_name, date_str)) {
- System.out.println("Digest mismatch");
- continue;
- }
- }
- server.setDate(date);
- boolean rc = server.setStatus(status, status_desc);
- if (added) {
- servers.put(server_name, server);
- // Call the new server callback
- //eventHandler.onEvent(AdvertiseEventType.ON_NEW_SERVER, server);
- String proxy = server.getParameter(AdvertisedServer.MANAGER_ADDRESS);
- if (proxy != null) {
- commHandler.addProxy(proxy);
- }
- }
- else if (rc) {
- // Call the status change callback
- //eventHandler.onEvent(AdvertiseEventType.ON_STATUS_CHANGE, server);
- }
- }
- listening = true;
- } catch (IOException e) {
- // Do not blow the CPU in case of communication error
- listening = false;
- try {
- Thread.sleep(100);
- } catch (InterruptedException x) {
- // Ignore
- }
- }
- }
- }
- }
-
-}
+ /**
+ * Deallocate listener and close sockets.
+ */
+ void destroy() throws IOException;
+}
\ No newline at end of file
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListenerFactory.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListenerFactory.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListenerFactory.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -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.advertise;
+
+import org.jboss.modcluster.mcmp.MCMPHandler;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface AdvertiseListenerFactory
+{
+ public AdvertiseListener createListener(MCMPHandler handler);
+}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertisedServer.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertisedServer.java 2008-09-05 14:44:11 UTC (rev 1779)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertisedServer.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -1,122 +0,0 @@
-/*
- *
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- */
-
-package org.jboss.modcluster.advertise;
-
-import java.util.Date;
-import java.util.HashMap;
-
-/**
- * Advertised server instance
- *
- * @author Mladen Turk
- *
- */
-public class AdvertisedServer
-{
- private String server;
- private Date date;
- private int status;
- private String status_desc;
- private HashMap<String, String> headers;
-
- /** Manager-Address header */
- public static String MANAGER_ADDRESS = "X-Manager-Address";
- /** Manager-Url header */
- public static String MANAGER_URL = "X-Manager-Url";
- /** Manager-Protocol header */
- public static String MANAGER_PROTOCOL = "X-Manager-Protocol";
- /** Manager-Version header */
- public static String MANAGER_VERSION = "X-Manager-Version";
- /** Manager-Host header */
- public static String MANAGER_HOST = "X-Manager-Host";
-
- protected AdvertisedServer(String server)
- {
- this.server = server;
- headers = new HashMap<String, String>();
- }
-
- protected boolean setStatus(int status, String desc)
- {
- boolean rv = false;
- status_desc = desc;
- if (this.status == 0 ) {
- // First time
- this.status = status;
- }
- else if (this.status != status) {
- this.status = status;
- rv = true;
- }
- return rv;
- }
-
- /** Set the Date of the last Advertise message
- */
- protected void setDate(Date date)
- {
- this.date = date;
- }
-
- /** Set the Header
- */
- protected void setParameter(String name, String value)
- {
- headers.put(name, value);
- }
-
- /** Get Date of the last Advertise message
- */
- public Date getDate()
- {
- return date;
- }
-
- /** Get Status code of the last Advertise message
- */
- public int getStatusCode()
- {
- return status;
- }
-
- /** Get Status description of the last Advertise message
- */
- public String getStatusDescription()
- {
- return status_desc;
- }
-
- /** Get Advertise parameter
- */
- public String getParameter(String name)
- {
- return headers.get(name);
- }
-
- public String toString()
- {
- return server;
- }
-}
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseEventType.java (from rev 1774, trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseEventType.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseEventType.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseEventType.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -0,0 +1,63 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.modcluster.advertise.impl;
+
+/**
+ * Set what type of event the AdvertiseEvent signals.
+ * @param type The type of event. One of:
+ * <PRE>
+ * ON_NEW_SERVER -- New AdvertisedServer detected
+ * ON_STATUS_CHANGE -- AdvertisedServer server changed status
+ * </PRE>
+ */
+public enum AdvertiseEventType
+{
+ /** New AdvertisedServer detected */
+ ON_NEW_SERVER(0),
+ /** AdvertisedServer server changed status */
+ ON_STATUS_CHANGE(1);
+
+ private int value;
+
+ private AdvertiseEventType(int v)
+ {
+ this.value = v;
+ }
+
+ public int valueOf()
+ {
+ return this.value;
+ }
+
+ public static AdvertiseEventType valueOf(int value)
+ {
+ for (AdvertiseEventType e : values())
+ {
+ if (e.value == value) return e;
+ }
+
+ throw new IllegalArgumentException("Invalid initializer: " + value);
+ }
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseEventType.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerFactoryImpl.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerFactoryImpl.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerFactoryImpl.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -0,0 +1,43 @@
+/*
+ * 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.advertise.impl;
+
+import org.jboss.modcluster.advertise.AdvertiseListener;
+import org.jboss.modcluster.advertise.AdvertiseListenerFactory;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class AdvertiseListenerFactoryImpl implements AdvertiseListenerFactory
+{
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.advertise.AdvertiseListenerFactory#createListener(org.jboss.modcluster.mcmp.MCMPHandler)
+ */
+ public AdvertiseListener createListener(MCMPHandler handler)
+ {
+ return new AdvertiseListenerImpl(handler);
+ }
+}
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java (from rev 1774, trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertiseListener.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -0,0 +1,540 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.modcluster.advertise.impl;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.UnknownHostException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.catalina.util.StringManager;
+import org.jboss.logging.Logger;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.advertise.AdvertiseListener;
+import org.jboss.modcluster.config.MCMPHandlerConfiguration;
+import org.jboss.modcluster.mcmp.MCMPHandler;
+
+/**
+ * Listens for Advertise messages from mod_cluster
+ *
+ * @author Mladen Turk
+ *
+ */
+public class AdvertiseListenerImpl implements AdvertiseListener
+{
+ /** Default port for listening Advertise messages. */
+ public static int DEFAULT_PORT = 23364;
+ /** Default Multicast group address for listening Advertise messages. */
+ public static String DEFAULT_GROUP = "224.0.1.105";
+
+ private static final Logger log = Logger.getLogger(AdvertiseListenerImpl.class);
+ private static final String RFC_822_FMT = "EEE, d MMM yyyy HH:mm:ss Z";
+
+ private int advertisePort = DEFAULT_PORT;
+ private InetAddress groupAddress = null;
+
+ MulticastSocket ms;
+
+ private boolean initialized = false;
+ volatile boolean listening = true;
+ final AtomicBoolean running = new AtomicBoolean(false);
+ final AtomicBoolean paused = new AtomicBoolean(false);
+ private boolean daemon = true;
+
+ private final byte[] secure = new byte[16];
+ private String securityKey = null;
+ MessageDigest md = null;
+
+ final Map<String, AdvertisedServer> servers = new HashMap<String, AdvertisedServer>();
+ final MCMPHandler commHandler;
+
+ private Thread workerThread;
+
+ /**
+ * The string manager for this package.
+ */
+ private StringManager sm = StringManager.getManager(Constants.Package);
+
+ private static void digestString(MessageDigest md, String s)
+ {
+ int len = s.length();
+ byte[] b = new byte[len];
+ for (int i = 0; i < len; i++)
+ {
+ char c = s.charAt(i);
+ if (c < 127)
+ {
+ b[i] = (byte) c;
+ }
+ else
+ {
+ b[i] = '?';
+ }
+ }
+ md.update(b);
+ }
+
+ /**
+ * Create AdvertiseListener instance
+ * @param eventHandler The event handler that will be used for
+ * status and new server notifications.
+ */
+ public AdvertiseListenerImpl(MCMPHandler commHandler)
+ {
+ this.commHandler = commHandler;
+
+ MCMPHandlerConfiguration config = commHandler.getConfiguration();
+
+ try
+ {
+ this.setGroupAddress(config.getAdvertiseGroupAddress());
+ this.setAdvertisePort(config.getAdvertisePort());
+ this.setSecurityKey(config.getAdvertiseSecurityKey());
+ }
+ catch (IOException e)
+ {
+ log.error(this.sm.getString("modcluster.error.startListener"), e);
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ // Should never happen
+ log.error(this.sm.getString("modcluster.error.startListener"), e);
+ }
+ }
+
+ /**
+ * The default is true - the control thread will be
+ * in daemon mode. If set to false, the control thread
+ * will not be daemon - and will keep the process alive.
+ */
+ public void setDaemon(boolean b)
+ {
+ this.daemon = b;
+ }
+
+ public boolean getDaemon()
+ {
+ return this.daemon;
+ }
+
+ /** Set Advertise security key
+ * @param key The key to use.<br/>
+ * Security key must match the AdvertiseKey
+ * on the advertised server.
+ */
+ public void setSecurityKey(String key) throws NoSuchAlgorithmException
+ {
+ this.securityKey = key;
+ if (this.md == null)
+ {
+ this.md = MessageDigest.getInstance("MD5");
+ }
+ }
+
+ /** Set Advertise port
+ * @param port The UDP port to use.
+ */
+ public void setAdvertisePort(int port)
+ {
+ this.advertisePort = (port > 0) ? port : DEFAULT_PORT;
+ }
+
+ public int getAdvertisePort()
+ {
+ return this.advertisePort;
+ }
+
+ /** Set Advertise Multicaset group address
+ * @param address The IP or host address to use.
+ * @throws UnknownHostException
+ */
+ public void setGroupAddress(String address) throws UnknownHostException
+ {
+ this.groupAddress = InetAddress.getByName((address != null) ? address : DEFAULT_GROUP);
+ }
+
+ /** Get Advertise Multicaset group address
+ */
+ public String getGroupAddress()
+ {
+ return this.groupAddress.getHostAddress();
+ }
+
+ /** Get Collection of all AdvertisedServer instances.
+ */
+ public Collection<AdvertisedServer> getServers()
+ {
+ return this.servers.values();
+ }
+
+ /** Get AdvertiseServer server.
+ * @param name Server name to get.
+ */
+ public AdvertisedServer getServer(String name)
+ {
+ return this.servers.get(name);
+ }
+
+ /** Remove the AdvertisedServer from the collection.
+ * @param server Server to remove.
+ */
+ public void removeServer(AdvertisedServer server)
+ {
+ this.servers.remove(server);
+ }
+
+ private synchronized void init() throws IOException
+ {
+ if (!this.initialized)
+ {
+ this.ms = new MulticastSocket(this.advertisePort);
+ this.ms.setTimeToLive(16);
+ this.ms.joinGroup(this.groupAddress);
+
+ this.initialized = true;
+ }
+ }
+
+ private void interruptDatagramReader()
+ {
+ if (!this.initialized) return;
+
+ try
+ {
+ // Restrict to localhost.
+ this.ms.setTimeToLive(0);
+ DatagramPacket dp = new DatagramPacket(this.secure, this.secure.length, this.groupAddress, this.advertisePort);
+ this.ms.send(dp);
+ }
+ catch (IOException e)
+ {
+ // Ignore
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.advertise.AdvertiseListener#start()
+ */
+ public void start() throws IOException
+ {
+ this.init();
+
+ if (this.running.compareAndSet(false, true))
+ {
+ SecureRandom random = new SecureRandom();
+
+ synchronized (this.secure)
+ {
+ random.nextBytes(this.secure);
+ this.secure[0] = 0;
+ }
+
+ this.paused.set(false);
+ this.listening = true;
+
+ AdvertiseListenerWorker aw = new AdvertiseListenerWorker();
+ this.workerThread = new Thread(aw);
+ this.workerThread.setDaemon(this.daemon);
+ this.workerThread.start();
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.advertise.AdvertiseListener#pause()
+ */
+ public void pause()
+ {
+ if (this.running.get() && this.paused.compareAndSet(false, true))
+ {
+ this.interruptDatagramReader();
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.advertise.AdvertiseListener#resume()
+ */
+ public void resume()
+ {
+ if (this.running.get() && this.paused.compareAndSet(true, false))
+ {
+ // Genererate new private secure
+ SecureRandom random = new SecureRandom();
+
+ synchronized (this.secure)
+ {
+ random.nextBytes(this.secure);
+ this.secure[0] = 0;
+ }
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.advertise.AdvertiseListener#stop()
+ */
+ public void stop()
+ {
+ if (this.running.compareAndSet(true, false))
+ {
+ this.interruptDatagramReader();
+ this.workerThread = null;
+ }
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.advertise.AdvertiseListener#destroy()
+ */
+ public void destroy() throws IOException
+ {
+ this.stop();
+
+ if (this.initialized)
+ {
+ this.ms.leaveGroup(this.groupAddress);
+ this.ms.close();
+ this.initialized = false;
+ this.ms = null;
+ }
+ }
+
+ // TODO This isn't correct - it always returns true!
+ boolean verifyDigest(String digest, String server, String date)
+ {
+ if (this.md == null) return true;
+
+ this.md.reset();
+ digestString(this.md, this.securityKey);
+ digestString(this.md, date);
+ digestString(this.md, server);
+ byte[] our = this.md.digest();
+ byte[] dst = new byte[digest.length() * 2];
+ for (int i = 0, j = 0; i < digest.length(); i++)
+ {
+ char ch = digest.charAt(i);
+ dst[j++] = (byte) ((ch >= 'A') ? ((ch & 0xdf) - 'A') + 10 : (ch - '0'));
+ }
+ return true;
+ }
+
+ /**
+ * True if listener is accepting the advetise messages.<br/>
+ * If false it means that listener is experiencing some
+ * network problems if running.
+ */
+ public boolean isListening()
+ {
+ return this.listening;
+ }
+
+ boolean matchesSecure(DatagramPacket dp)
+ {
+ byte[] data = dp.getData();
+
+ synchronized (this.secure)
+ {
+ if (dp.getLength() != this.secure.length) return false;
+
+ for (int i = 0; i < this.secure.length; i++)
+ {
+ if (data[i] != this.secure[i])
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ // ------------------------------------ AdvertiseListenerWorker Inner Class
+ class AdvertiseListenerWorker implements Runnable
+ {
+ private DateFormat df = new SimpleDateFormat(RFC_822_FMT, Locale.US);
+
+ /**
+ * The background thread that listens for incoming Advertise packets
+ * and hands them off to an appropriate AdvertiseEvent handler.
+ */
+ public void run()
+ {
+ byte[] buffer = new byte[512];
+ // Loop until we receive a shutdown command
+ while (AdvertiseListenerImpl.this.running.get())
+ {
+ // Loop if endpoint is paused
+ while (AdvertiseListenerImpl.this.paused.get())
+ {
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ try
+ {
+ DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
+ AdvertiseListenerImpl.this.ms.receive(dp);
+ if (!AdvertiseListenerImpl.this.running.get())
+ {
+ break;
+ }
+
+ if (AdvertiseListenerImpl.this.matchesSecure(dp)) continue;
+
+ byte[] data = dp.getData();
+
+ String s = new String(data, 0, dp.getLength(), "8859_1");
+ if (!s.startsWith("HTTP/1."))
+ {
+ continue;
+ }
+
+ String[] headers = s.split("\r\n");
+ String date_str = null;
+ Date date = null;
+ int status = 0;
+ String status_desc = null;
+ String digest = null;
+ String server_name = null;
+ AdvertisedServer server = null;
+ boolean added = false;
+ for (int i = 0; i < headers.length; i++)
+ {
+ if (i == 0)
+ {
+ String[] sline = headers[i].split(" ", 3);
+ if (sline == null || sline.length != 3)
+ {
+ break;
+ }
+ status = Integer.parseInt(sline[1]);
+ if (status < 100)
+ {
+ break;
+ }
+ status_desc = sline[2];
+ }
+ else
+ {
+ String[] hdrv = headers[i].split(": ", 2);
+ if (hdrv == null || hdrv.length != 2)
+ {
+ break;
+ }
+ if (hdrv[0].equals("Date"))
+ {
+ date_str = hdrv[1];
+ try
+ {
+ date = this.df.parse(date_str);
+ }
+ catch (ParseException e)
+ {
+ date = new Date();
+ }
+ }
+ else if (hdrv[0].equals("Digest"))
+ {
+ digest = hdrv[1];
+ }
+ else if (hdrv[0].equals("Server"))
+ {
+ server_name = hdrv[1];
+ server = AdvertiseListenerImpl.this.servers.get(server_name);
+ if (server == null)
+ {
+ server = new AdvertisedServer(server_name);
+ added = true;
+ }
+ }
+ else if (server != null)
+ {
+ server.setParameter(hdrv[0], hdrv[1]);
+ }
+ }
+ }
+ if (server != null && status > 0)
+ {
+ if (AdvertiseListenerImpl.this.md != null)
+ {
+ /* We need a digest to match */
+ if (!AdvertiseListenerImpl.this.verifyDigest(digest, server_name, date_str))
+ {
+ System.out.println("Digest mismatch");
+ continue;
+ }
+ }
+ server.setDate(date);
+ boolean rc = server.setStatus(status, status_desc);
+ if (added)
+ {
+ AdvertiseListenerImpl.this.servers.put(server_name, server);
+ // Call the new server callback
+ //eventHandler.onEvent(AdvertiseEventType.ON_NEW_SERVER, server);
+ String proxy = server.getParameter(AdvertisedServer.MANAGER_ADDRESS);
+ if (proxy != null)
+ {
+ AdvertiseListenerImpl.this.commHandler.addProxy(proxy);
+ }
+ }
+ else if (rc)
+ {
+ // Call the status change callback
+ //eventHandler.onEvent(AdvertiseEventType.ON_STATUS_CHANGE, server);
+ }
+ }
+ AdvertiseListenerImpl.this.listening = true;
+ }
+ catch (IOException e)
+ {
+ // Do not blow the CPU in case of communication error
+ AdvertiseListenerImpl.this.listening = false;
+ Thread.yield();
+ }
+ }
+ }
+ }
+
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertiseListenerImpl.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertisedServer.java (from rev 1774, trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/AdvertisedServer.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertisedServer.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertisedServer.java 2008-09-05 14:47:30 UTC (rev 1780)
@@ -0,0 +1,123 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.modcluster.advertise.impl;
+
+import java.util.Date;
+import java.util.HashMap;
+
+/**
+ * Advertised server instance
+ *
+ * @author Mladen Turk
+ */
+public class AdvertisedServer
+{
+ /** Manager-Address header */
+ public static String MANAGER_ADDRESS = "X-Manager-Address";
+ /** Manager-Url header */
+ public static String MANAGER_URL = "X-Manager-Url";
+ /** Manager-Protocol header */
+ public static String MANAGER_PROTOCOL = "X-Manager-Protocol";
+ /** Manager-Version header */
+ public static String MANAGER_VERSION = "X-Manager-Version";
+ /** Manager-Host header */
+ public static String MANAGER_HOST = "X-Manager-Host";
+
+ private String server;
+ private Date date;
+ private int status;
+ private String status_desc;
+ private HashMap<String, String> headers = new HashMap<String, String>();
+
+ protected AdvertisedServer(String server)
+ {
+ this.server = server;
+ }
+
+ protected boolean setStatus(int status, String desc)
+ {
+ boolean rv = false;
+ this.status_desc = desc;
+ if (this.status == 0)
+ {
+ // First time
+ this.status = status;
+ }
+ else if (this.status != status)
+ {
+ this.status = status;
+ rv = true;
+ }
+ return rv;
+ }
+
+ /** Set the Date of the last Advertise message
+ */
+ protected void setDate(Date date)
+ {
+ this.date = date;
+ }
+
+ /** Set the Header
+ */
+ protected void setParameter(String name, String value)
+ {
+ this.headers.put(name, value);
+ }
+
+ /** Get Date of the last Advertise message
+ */
+ public Date getDate()
+ {
+ return this.date;
+ }
+
+ /** Get Status code of the last Advertise message
+ */
+ public int getStatusCode()
+ {
+ return this.status;
+ }
+
+ /** Get Status description of the last Advertise message
+ */
+ public String getStatusDescription()
+ {
+ return this.status_desc;
+ }
+
+ /** Get Advertise parameter
+ */
+ public String getParameter(String name)
+ {
+ return this.headers.get(name);
+ }
+
+ @Override
+ public String toString()
+ {
+ return this.server;
+ }
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/advertise/impl/AdvertisedServer.java
___________________________________________________________________
Name: svn:mergeinfo
+
15 years, 8 months