JBoss Native SVN: r1984 - trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-22 12:23:30 -0400 (Wed, 22 Oct 2008)
New Revision: 1984
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
Log:
Unit tests pass again
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2008-10-22 16:21:27 UTC (rev 1983)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2008-10-22 16:23:30 UTC (rev 1984)
@@ -113,11 +113,8 @@
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host");
-
- EasyMock.expect(engine.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
@@ -136,15 +133,11 @@
EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- EasyMock.expect(context.isStarted()).andReturn(true);
-
EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.isStarted()).andReturn(true);
EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
EasyMock.replay(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
@@ -152,19 +145,11 @@
EasyMock.verify(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
- Assert.assertEquals(5, results.size());
+ Assert.assertEquals(4, results.size());
MCMPRequest request = results.get(0);
Map<String, String> parameters = request.getParameters();
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- request = results.get(1);
- parameters = request.getParameters();
-
Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
Assert.assertFalse(request.isWildcard());
Assert.assertEquals("host1", request.getJvmRoute());
@@ -186,7 +171,7 @@
Assert.assertEquals("6", parameters.get("WaitWorker"));
Assert.assertEquals("7", parameters.get("Maxattempts"));
- request = results.get(2);
+ request = results.get(1);
parameters = request.getParameters();
Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
@@ -196,8 +181,8 @@
Assert.assertEquals("/context", parameters.get("Context"));
Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
- Assert.assertSame(request1, results.get(3));
- Assert.assertSame(request2, results.get(4));
+ Assert.assertSame(request1, results.get(2));
+ Assert.assertSame(request2, results.get(3));
EasyMock.reset(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
@@ -231,11 +216,8 @@
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host");
-
- EasyMock.expect(engine.getService()).andReturn(service);
- EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
EasyMock.expect(this.nodeConfig.getDomain()).andReturn("domain");
EasyMock.expect(this.nodeConfig.getFlushPackets()).andReturn(Boolean.TRUE);
@@ -254,15 +236,11 @@
EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- EasyMock.expect(context.isStarted()).andReturn(true);
-
EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.isStarted()).andReturn(true);
EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
EasyMock.replay(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
@@ -270,16 +248,9 @@
EasyMock.verify(this.singleton, this.key, this.partition, server, service, engine, container, context, host, this.nodeConfig, this.balancerConfig);
- Assert.assertEquals(3, results.size());
+ Assert.assertEquals(2, results.size());
MCMPRequest request = results.get(0);
-
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host", request.getJvmRoute());
- Assert.assertTrue(request.getParameters().isEmpty());
-
- request = results.get(1);
Map<String, String> parameters = request.getParameters();
Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
@@ -303,7 +274,7 @@
Assert.assertEquals("6", parameters.get("WaitWorker"));
Assert.assertEquals("7", parameters.get("Maxattempts"));
- request = results.get(2);
+ request = results.get(1);
parameters = request.getParameters();
Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
16 years, 2 months
JBoss Native SVN: r1983 - in trunk/mod_cluster/src: test/java/org/jboss/modcluster and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-22 12:21:27 -0400 (Wed, 22 Oct 2008)
New Revision: 1983
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
Log:
Unit tests pass again
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-10-22 14:04:01 UTC (rev 1982)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/DefaultJBossWebEventHandler.java 2008-10-22 16:21:27 UTC (rev 1983)
@@ -146,19 +146,17 @@
{
this.checkInit();
- Service[] services = server.findServices();
- for (Service service: services)
+ for (Service service: server.findServices())
{
Engine engine = (Engine) service.getContainer();
this.config(engine);
- Container[] children = engine.findChildren();
- for (Container element: children)
+
+ for (Container host: engine.findChildren())
{
- Container[] children2 = element.findChildren();
- for (Container element2: children2)
+ for (Container context: host.findChildren())
{
- this.addContext((Context) element2);
+ this.addContext((Context) context);
}
}
}
@@ -172,20 +170,17 @@
{
this.checkInit();
- Service[] services = server.findServices();
- for (Service service : services)
+ for (Service service: server.findServices())
{
Engine engine = (Engine) service.getContainer();
this.removeAll(engine);
- Container[] children = engine.findChildren();
- for (Container element : children)
+ for (Container host: engine.findChildren())
{
- Container[] children2 = element.findChildren();
- for (Container element2 : children2)
+ for (Container context: host.findChildren())
{
- this.removeContext((Context) element2);
+ this.removeContext((Context) context);
}
}
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2008-10-22 14:04:01 UTC (rev 1982)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/DefaultJBossWebEventHandlerTestCase.java 2008-10-22 16:21:27 UTC (rev 1983)
@@ -28,8 +28,6 @@
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;
@@ -50,12 +48,16 @@
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPRequestType;
import org.jboss.modcluster.mcmp.MCMPServerState;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* @author Paul Ferraro
*
*/
-public class DefaultJBossWebEventHandlerTestCase extends TestCase
+@SuppressWarnings("boxing")
+public class DefaultJBossWebEventHandlerTestCase
{
private final NodeConfiguration nodeConfig = EasyMock.createStrictMock(NodeConfiguration.class);
private final BalancerConfiguration balancerConfig = EasyMock.createStrictMock(BalancerConfiguration.class);
@@ -70,13 +72,14 @@
* @{inheritDoc}
* @see junit.framework.TestCase#setUp()
*/
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void construct() throws Exception
{
this.handler = new DefaultJBossWebEventHandler(this.nodeConfig, this.balancerConfig, this.mcmpConfig, this.mcmpHandler, this.provider, this.listenerFactory);
}
- public void testInit() throws IOException
+ @Test
+ public void init() throws IOException
{
InetAddress localAddress = InetAddress.getLocalHost();
String localHostName = localAddress.getHostName();
@@ -153,7 +156,8 @@
EasyMock.reset(this.mcmpHandler, this.listenerFactory, this.mcmpConfig, listener);
}
- public void testShutdown() throws IOException
+ @Test
+ public void shutdown() throws IOException
{
// Test w/out advertise listener
this.mcmpHandler.shutdown();
@@ -203,79 +207,84 @@
EasyMock.reset(this.mcmpHandler, listener);
}
- public void testAddContext() throws IOException
+ @Test
+ public void addContext() throws IOException
{
Context context = EasyMock.createStrictMock(Context.class);
+ EasyMock.replay(context);
+
// Test not initialized
try
{
this.handler.addContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+ Host host = EasyMock.createStrictMock(Host.class);
+
// Test context not started
- Container container = EasyMock.createStrictMock(Container.class);
+ recordAddContext(context, host);
- recordAddContext(context, container);
+ EasyMock.replay(context, host);
- EasyMock.replay(context, container);
-
this.handler.addContext(context);
- EasyMock.verify(context, container);
- EasyMock.reset(context, container);
+ EasyMock.verify(context, host);
+ EasyMock.reset(context, host);
// 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.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(context.isStarted()).andReturn(true);
// Building request
- EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+ EasyMock.replay(this.mcmpHandler, context, engine, host);
this.handler.addContext(context);
- EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+ EasyMock.verify(this.mcmpHandler, context, engine, host);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
- EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ EasyMock.reset(this.mcmpHandler, context, engine, host);
}
private void recordAddContext(Context context, Container container)
@@ -283,211 +292,227 @@
// Expect log message
EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getName()).andReturn("parent-container");
+ EasyMock.expect(container.getName()).andReturn("host");
EasyMock.expect(context.isStarted()).andReturn(false);
}
- public void testStartContext() throws IOException
+ @Test
+ public void startContext() throws IOException
{
Context context = EasyMock.createStrictMock(Context.class);
+ EasyMock.replay(context);
+
// Test not initialized
try
{
this.handler.startContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
// 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");
-
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
// Building request
- EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+ EasyMock.replay(this.mcmpHandler, context, engine, host);
this.handler.startContext(context);
- EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+ EasyMock.verify(this.mcmpHandler, context, engine, host);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
- EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ EasyMock.reset(this.mcmpHandler, context, engine, host);
}
- public void testStopContext() throws IOException
+ @Test
+ public void stopContext() throws IOException
{
Context context = EasyMock.createStrictMock(Context.class);
+ EasyMock.replay(context);
+
// Test not initialized
try
{
this.handler.stopContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
-
- testInit();
+ EasyMock.verify(context);
+ EasyMock.reset(context);
+
+ init();
+
// 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");
-
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
// Building request
- EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+ EasyMock.replay(this.mcmpHandler, context, engine, host);
this.handler.stopContext(context);
- EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+ EasyMock.verify(this.mcmpHandler, context, engine, host);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.STOP_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
- EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ EasyMock.reset(this.mcmpHandler, context, engine, host);
}
- public void testRemoveContext() throws IOException
+ @Test
+ public void removeContext() throws IOException
{
Context context = EasyMock.createStrictMock(Context.class);
+ EasyMock.replay(context);
+
// Test not initialized
try
{
this.handler.removeContext(context);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
+
+ EasyMock.verify(context);
+ EasyMock.reset(context);
- testInit();
+ init();
// Test initialized - no jvm route
- Container container = EasyMock.createStrictMock(Container.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
+ Host host = EasyMock.createStrictMock(Host.class);
- this.recordRemoveContext(context, container, engine);
+ this.recordRemoveContext(context, host, engine);
- EasyMock.replay(context, container, engine);
+ EasyMock.replay(context, host, engine);
this.handler.removeContext(context);
- EasyMock.verify(context, container, engine);
- EasyMock.reset(context, container, engine);
+ EasyMock.verify(context, host, engine);
+ EasyMock.reset(context, host, 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(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getName()).andReturn("host");
+
+ // jvm route null check
+ EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
-
+
// Building request
- EasyMock.expect(context.getPath()).andReturn("/context");
EasyMock.expect(context.getParent()).andReturn(host);
+ EasyMock.expect(host.getParent()).andReturn(engine);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
+ EasyMock.expect(context.getPath()).andReturn("/context");
this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.replay(this.mcmpHandler, context, container, engine, host);
+ EasyMock.replay(this.mcmpHandler, context, engine, host);
this.handler.removeContext(context);
- EasyMock.verify(this.mcmpHandler, context, container, engine, host);
+ EasyMock.verify(this.mcmpHandler, context, engine, host);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(2, parameters.size());
+ Assert.assertEquals(2, parameters.size());
- assertEquals("/context", parameters.get("Context"));
- assertEquals("host,alias1,alias2", parameters.get("Alias"));
+ Assert.assertEquals("/context", parameters.get("Context"));
+ Assert.assertEquals("host,alias1,alias2", parameters.get("Alias"));
- EasyMock.reset(this.mcmpHandler, context, container, engine, host);
+ EasyMock.reset(this.mcmpHandler, context, engine, host);
}
private void recordRemoveContext(Context context, Container container, Engine engine)
@@ -502,23 +527,29 @@
EasyMock.expect(engine.getJvmRoute()).andReturn(null);
}
- public void testStatus() throws IOException
+ @Test
+ public void status() throws IOException
{
Engine engine = EasyMock.createStrictMock(Engine.class);
+
+ EasyMock.replay(engine);
// Test not initialized
try
{
this.handler.status(engine);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
+
+ EasyMock.verify(engine);
+ EasyMock.reset(engine);
- testInit();
+ init();
// Test initialized
Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
@@ -541,46 +572,51 @@
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.STATUS, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.STATUS, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(1, parameters.size());
- assertEquals("10", parameters.get("Load"));
+ Assert.assertEquals(1, parameters.size());
+ Assert.assertEquals("10", parameters.get("Load"));
EasyMock.reset(this.mcmpHandler, this.provider, engine);
}
- public void testStartServer() throws Exception
+ @Test
+ public void startServer() throws Exception
{
Server server = EasyMock.createStrictMock(Server.class);
+ EasyMock.replay(server);
+
// Test not initialized
try
{
this.handler.startServer(server);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ EasyMock.verify(server);
+ EasyMock.reset(server);
+ init();
+
// Test initialized
Service service = EasyMock.createStrictMock(Service.class);
Engine engine = EasyMock.createStrictMock(Engine.class);
- Container container = EasyMock.createStrictMock(Container.class);
+ Host host = EasyMock.createStrictMock(Host.class);
Context context = EasyMock.createStrictMock(Context.class);
Capture<MCMPRequest> capturedRequest = new Capture<MCMPRequest>();
Connector connector = new Connector("AJP/1.3");
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
-
EasyMock.expect(service.getContainer()).andReturn(engine);
// Expect log message
@@ -592,9 +628,9 @@
Set<MCMPServerState> states = Collections.emptySet();
EasyMock.expect(this.mcmpHandler.getProxyStates()).andReturn(states);
+ EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
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);
@@ -613,46 +649,47 @@
this.mcmpHandler.sendRequest(EasyMock.capture(capturedRequest));
- EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
- EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- this.recordAddContext(context, container);
+ EasyMock.expect(engine.findChildren()).andReturn(new Container[] { host });
+ EasyMock.expect(host.findChildren()).andReturn(new Container[] { context });
+ this.recordAddContext(context, host);
- EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+ EasyMock.replay(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, host, context);
this.handler.startServer(server);
- EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+ EasyMock.verify(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, host, context);
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.CONFIG, request.getRequestType());
- assertFalse(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
+ Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
+ Assert.assertFalse(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
Map<String, String> parameters = request.getParameters();
- assertEquals(16, parameters.size());
- assertEquals("127.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"));
+ Assert.assertEquals(16, parameters.size());
+ Assert.assertEquals("127.0.0.1", parameters.get("Host"));
+ Assert.assertEquals("0", parameters.get("Port"));
+ Assert.assertEquals("ajp", parameters.get("Type"));
+ Assert.assertEquals("domain", parameters.get("Domain"));
+ Assert.assertEquals("On", parameters.get("flushpackets"));
+ Assert.assertEquals("1", parameters.get("flushwait"));
+ Assert.assertEquals("2", parameters.get("ping"));
+ Assert.assertEquals("3", parameters.get("smax"));
+ Assert.assertEquals("4", parameters.get("ttl"));
+ Assert.assertEquals("5", parameters.get("Timeout"));
+ Assert.assertEquals("S", parameters.get("Balancer"));
+ Assert.assertEquals("No", parameters.get("StickySession"));
+ Assert.assertEquals("Yes", parameters.get("StickySessionRemove"));
+ Assert.assertEquals("No", parameters.get("StickySessionForce"));
+ Assert.assertEquals("6", parameters.get("WaitWorker"));
+ Assert.assertEquals("7", parameters.get("Maxattempts"));
- EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
+ EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, host, context);
}
- public void testStopServer() throws IOException
+ @Test
+ public void stopServer() throws IOException
{
Server server = EasyMock.createStrictMock(Server.class);
@@ -661,14 +698,14 @@
{
this.handler.stopServer(server);
- fail();
+ Assert.fail();
}
catch (IllegalStateException e)
{
// Expected
}
- testInit();
+ init();
// Test initialized
Service service = EasyMock.createStrictMock(Service.class);
@@ -699,10 +736,10 @@
MCMPRequest request = capturedRequest.getValue();
- assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- assertTrue(request.isWildcard());
- assertEquals("host1", request.getJvmRoute());
- assertTrue(request.getParameters().isEmpty());
+ Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
+ Assert.assertTrue(request.isWildcard());
+ Assert.assertEquals("host1", request.getJvmRoute());
+ Assert.assertTrue(request.getParameters().isEmpty());
EasyMock.reset(this.mcmpHandler, this.nodeConfig, this.balancerConfig, server, service, engine, container, context);
}
16 years, 2 months
JBoss Native SVN: r1982 - in trunk/mod_cluster/src/main/java/org/jboss/modcluster: mcmp and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-22 10:04:01 -0400 (Wed, 22 Oct 2008)
New Revision: 1982
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
Log:
Don't send uncessary REMOVE-APP * messages during reset
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 13:09:29 UTC (rev 1981)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 14:04:01 UTC (rev 1982)
@@ -116,7 +116,7 @@
* @param context
* @return
*/
- public static Set<String> getHosts(Context context)
+ public static Set<String> getAliases(Context context)
{
Host host = (Host) context.getParent();
String name = host.getName();
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2008-10-22 13:09:29 UTC (rev 1981)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2008-10-22 14:04:01 UTC (rev 1982)
@@ -200,21 +200,21 @@
private static MCMPRequest createRequest(MCMPRequestType type, Context context)
{
- return createContextRequest(type, Utils.getJvmRoute(context), Utils.getHosts(context), context.getPath());
+ return createContextRequest(type, Utils.getJvmRoute(context), Utils.getAliases(context), context.getPath());
}
- private static MCMPRequest createContextRequest(MCMPRequestType type, String jvmRoute, Set<String> hosts, String path)
+ private static MCMPRequest createContextRequest(MCMPRequestType type, String jvmRoute, Set<String> aliases, String path)
{
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("Context", "".equals(path) ? "/" : path);
StringBuilder builder = new StringBuilder();
- Iterator<String> iter = hosts.iterator();
- while (iter.hasNext())
+ Iterator<String> hosts = aliases.iterator();
+ while (hosts.hasNext())
{
- builder.append(iter.next());
- if (iter.hasNext())
+ builder.append(hosts.next());
+ if (hosts.hasNext())
{
builder.append(',');
}
@@ -277,12 +277,13 @@
requests.add(createConfigRequest(jvmRoute, service.findConnectors(), nodeConfig, balancerConfig));
ResetRequestSource.EngineStatus engineStatus = response.get(jvmRoute);
- Set<String> contexts = new HashSet<String>();
-
+ Map<String, ResetRequestSource.Status> contexts = Collections.emptyMap();
if (engineStatus != null)
{
- contexts.addAll(engineStatus.getContexts().keySet());
+ contexts = engineStatus.getContexts();
}
+
+ Set<String> oldContexts = new HashSet<String>(contexts.keySet());
for (Container child: engine.findChildren())
{
@@ -291,22 +292,22 @@
Context context = (Context) container;
String path = context.getPath();
- contexts.remove(path);
+ oldContexts.remove(path);
- ResetRequestSource.Status status = (engineStatus != null) ? engineStatus.getContexts().get(path) : null;
+ ResetRequestSource.Status status = contexts.get(path);
if (Utils.isContextStarted(context))
{
if (status != ResetRequestSource.Status.ENABLED)
{
- requests.add(createContextRequest(MCMPRequestType.ENABLE_APP, jvmRoute, Utils.getHosts(context), path));
+ requests.add(createContextRequest(MCMPRequestType.ENABLE_APP, jvmRoute, Utils.getAliases(context), path));
}
}
else
{
if (status == ResetRequestSource.Status.ENABLED)
{
- requests.add(createContextRequest(MCMPRequestType.STOP_APP, jvmRoute, Utils.getHosts(context), path));
+ requests.add(createContextRequest(MCMPRequestType.STOP_APP, jvmRoute, Utils.getAliases(context), path));
}
}
}
@@ -315,20 +316,21 @@
// Send REMOVE-APP requests for contexts that don't exist
if (engineStatus != null)
{
- Set<String> aliases = engineStatus.getAliases();
-
- for (String context: contexts)
+ if (oldContexts.size() == contexts.size())
{
- requests.add(createContextRequest(MCMPRequestType.REMOVE_APP, jvmRoute, aliases, context));
+ requests.add(createEngineRequest(MCMPRequestType.REMOVE_APP, jvmRoute));
}
+ else
+ {
+ Set<String> aliases = engineStatus.getAliases();
+
+ for (String context: contexts.keySet())
+ {
+ requests.add(createContextRequest(MCMPRequestType.REMOVE_APP, jvmRoute, aliases, context));
+ }
+ }
}
}
-
- // Add REMOVE-APP * for non-existing engines
- for (String jvmRoute: jvmRoutes)
- {
- requests.add(createEngineRequest(MCMPRequestType.REMOVE_APP, jvmRoute));
- }
return requests;
}
16 years, 2 months
JBoss Native SVN: r1981 - trunk/mod_cluster/test/java.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-10-22 09:09:29 -0400 (Wed, 22 Oct 2008)
New Revision: 1981
Modified:
trunk/mod_cluster/test/java/Advertize.java
Log:
Use same default as in mod_advertise.h
Modified: trunk/mod_cluster/test/java/Advertize.java
===================================================================
--- trunk/mod_cluster/test/java/Advertize.java 2008-10-22 09:08:01 UTC (rev 1980)
+++ trunk/mod_cluster/test/java/Advertize.java 2008-10-22 13:09:29 UTC (rev 1981)
@@ -6,14 +6,19 @@
{
public static void main(String[] args) throws Exception
{
- InetAddress group = InetAddress.getByName("232.0.0.2");
+ InetAddress group = InetAddress.getByName("224.0.1.105");
MulticastSocket s = new MulticastSocket(23364);
+ s.setTimeToLive(16);
s.joinGroup(group);
- byte[] buf = new byte[1000];
- DatagramPacket recv = new DatagramPacket(buf, buf.length);
- s.receive(recv);
- String data = new String(buf);
- System.out.println("received: " + data);
+ boolean ok = true;
+ System.out.println("ready waiting...");
+ while (ok) {
+ byte[] buf = new byte[1000];
+ DatagramPacket recv = new DatagramPacket(buf, buf.length);
+ s.receive(recv);
+ String data = new String(buf);
+ System.out.println("received: " + data);
+ }
s.leaveGroup(group);
}
}
16 years, 2 months
JBoss Native SVN: r1980 - sandbox/mod_jk.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-10-22 05:08:01 -0400 (Wed, 22 Oct 2008)
New Revision: 1980
Modified:
sandbox/mod_jk/TraceAna.java
Log:
Allow 0 offset value :-)
Modified: sandbox/mod_jk/TraceAna.java
===================================================================
--- sandbox/mod_jk/TraceAna.java 2008-10-22 09:07:12 UTC (rev 1979)
+++ sandbox/mod_jk/TraceAna.java 2008-10-22 09:08:01 UTC (rev 1980)
@@ -194,7 +194,7 @@
}
public static void main(String[] args) throws Exception {
- int offset = 0;
+ int offset = -1;
if (args.length < 1 && args.length > 2) {
System.err.println("missing command line arguments");
System.exit(1);
@@ -210,7 +210,7 @@
TraceAna buf = new TraceAna(8192);
/* Detect the "): 0000 " to find the offset of the dumped data */
String ins = in.readLine();
- if (offset == 0) {
+ if (offset == -1) {
offset = ins.indexOf("): 0000 ",0);
offset = offset + 11;
}
16 years, 2 months
JBoss Native SVN: r1979 - sandbox/mod_jk.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-10-22 05:07:12 -0400 (Wed, 22 Oct 2008)
New Revision: 1979
Added:
sandbox/mod_jk/PongClient.java
Log:
A client to test cping/pong timeouts.
Added: sandbox/mod_jk/PongClient.java
===================================================================
--- sandbox/mod_jk/PongClient.java (rev 0)
+++ sandbox/mod_jk/PongClient.java 2008-10-22 09:07:12 UTC (rev 1979)
@@ -0,0 +1,55 @@
+import java.io.*;
+import java.net.*;
+
+class PongClient {
+ public static void main(String[] argv)
+ {
+ int wait = 3000;
+ String host = "localhost";
+ if (argv.length == 2) {
+ wait = Integer.parseInt(argv[0]);
+ host = argv[1];
+ }
+ System.out.println("PongClient wait: " + wait + " to: " + host);
+ Socket clientSocket = null;
+ try {
+ clientSocket = new Socket(host, 8009);
+ } catch (IOException e) {
+ System.out.println("Could not connect on port: 8009");
+ System.exit(-1);
+ }
+ byte[] buf = new byte[1024];
+ int num;
+ byte cpong[] = { 'A' , 'B', '\0' , (byte)0x01 , (byte)0x09 };
+ byte cping[] = { (byte)0x12, (byte)0x34, '\0' , (byte)0x01 , (byte)0x0A };
+ InputStream clientInput = null;
+ OutputStream clientOutput = null;
+ try {
+ clientSocket.setSoTimeout(wait);
+ clientInput = clientSocket.getInputStream();
+ clientOutput = clientSocket.getOutputStream();
+
+ clientOutput.write(cping);
+
+ while ((num = clientInput.read(buf)) != -1) {
+ System.out.println(".");
+ int i;
+ for (i=0; i<cpong.length; i++)
+ if (cpong[i] != buf[i])
+ break;
+ if (i == cpong.length)
+ break; /* Done */
+ }
+ System.out.println("num " + num);
+ } catch (InterruptedIOException e) {
+ e.printStackTrace();
+ System.exit(-1);
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.out.println("Could not read from port: 8009");
+ System.exit(-1);
+ }
+
+
+ }
+}
16 years, 2 months
JBoss Native SVN: r1978 - sandbox/mod_jk.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-10-22 04:43:22 -0400 (Wed, 22 Oct 2008)
New Revision: 1978
Modified:
sandbox/mod_jk/PongServ.java
Log:
Oops wrong size.
Modified: sandbox/mod_jk/PongServ.java
===================================================================
--- sandbox/mod_jk/PongServ.java 2008-10-22 04:35:12 UTC (rev 1977)
+++ sandbox/mod_jk/PongServ.java 2008-10-22 08:43:22 UTC (rev 1978)
@@ -24,7 +24,7 @@
}
byte[] buf = new byte[1024];
int num;
- byte cpong[] = { 'A' , 'B', '\0' , (byte)0x02 , (byte)0x09 };
+ byte cpong[] = { 'A' , 'B', '\0' , (byte)0x01 , (byte)0x09 };
InputStream clientInput = null;
OutputStream clientOutput = null;
try {
16 years, 2 months
JBoss Native SVN: r1977 - in trunk/mod_cluster/src: main/java/org/jboss/modcluster/ha and 5 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-22 00:35:12 -0400 (Wed, 22 Oct 2008)
New Revision: 1977
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.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/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
Log:
Refactor ResetRequestSource again to include Aliases parsed from INFO-RSP.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ClusterListener.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -93,7 +93,7 @@
/**
* Reset configuration for a particular proxy following an error.
*/
- public List<MCMPRequest> getResetRequests(Map<String, Map<String, Status>> response)
+ public List<MCMPRequest> getResetRequests(Map<String, ResetRequestSource.EngineStatus> response)
{
return MCMPUtils.getResetRequests(response, ServerFactory.getServer(), this, this);
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -74,7 +74,7 @@
import org.jboss.modcluster.mcmp.MCMPServer;
import org.jboss.modcluster.mcmp.MCMPServerState;
import org.jboss.modcluster.mcmp.MCMPUtils;
-import org.jboss.modcluster.mcmp.ResetRequestSource.Status;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
import org.jboss.modcluster.mcmp.impl.DefaultMCMPHandler;
/**
@@ -523,7 +523,7 @@
boolean needReset = this.coord.clusteredHandler.getNeedsResetTransmission();
- Map<String, Map<String, Status>> map = Collections.emptyMap();
+ Map<String, ResetRequestSource.EngineStatus> map = Collections.emptyMap();
List<MCMPRequest> resetRequests = needReset ? this.coord.resetRequestSource.getLocalResetRequests(map) : null;
ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
@@ -662,7 +662,7 @@
/**
* @see org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
*/
- public GroupRpcResponse getResetRequests(Map<String, Map<String, Status>> response)
+ public GroupRpcResponse getResetRequests(Map<String, ResetRequestSource.EngineStatus> response)
{
ClusterNode node = ModClusterService.this.getHAPartition().getClusterNode();
List<MCMPRequest> requests = this.coord.resetRequestSource.getLocalResetRequests(response);
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -3,6 +3,10 @@
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
@@ -112,18 +116,21 @@
* @param context
* @return
*/
- public static String getHost(Context context)
+ public static Set<String> getHosts(Context context)
{
- StringBuilder result = new StringBuilder();
Host host = (Host) context.getParent();
- result.append(host.getName());
+ String name = host.getName();
String[] aliases = host.findAliases();
- for (String alias: aliases)
+
+ if (aliases.length == 0)
{
- result.append(',');
- result.append(alias);
+ return Collections.singleton(name);
}
- return result.toString();
+
+ Set<String> hosts = new LinkedHashSet<String>();
+ hosts.add(name);
+ hosts.addAll(Arrays.asList(aliases));
+ return hosts;
}
/**
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-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSource.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -34,7 +34,7 @@
*/
public interface HASingletonAwareResetRequestSource extends ResetRequestSource
{
- List<MCMPRequest> getLocalResetRequests(Map<String, Map<String, Status>> response);
+ List<MCMPRequest> getLocalResetRequests(Map<String, ResetRequestSource.EngineStatus> response);
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-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceImpl.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -77,7 +77,7 @@
this.rpcStub = new RpcStub(serviceKeyProvider);
}
- public List<MCMPRequest> getResetRequests(Map<String, Map<String, Status>> response)
+ public List<MCMPRequest> getResetRequests(Map<String, ResetRequestSource.EngineStatus> response)
{
if (this.singleton.isMasterNode())
{
@@ -93,7 +93,7 @@
* @{inheritDoc}
* @see org.jboss.modcluster.ha.HASingletonAwareResetRequestSource#getLocalResetRequests()
*/
- public List<MCMPRequest> getLocalResetRequests(Map<String, Map<String, Status>> response)
+ public List<MCMPRequest> getLocalResetRequests(Map<String, ResetRequestSource.EngineStatus> response)
{
if (this.jbossWebServer == null)
{
@@ -112,7 +112,7 @@
this.jbossWebServer = jbossWebServer;
}
- private void addRemoteRequests(List<MCMPRequest> resets, Map<String, Map<String, Status>> resp)
+ private void addRemoteRequests(List<MCMPRequest> resets, Map<String, ResetRequestSource.EngineStatus> resp)
{
List<?> responses = this.rpcStub.getResetRequests(resp);
@@ -152,7 +152,7 @@
/**
* @see org.jboss.modcluster.ha.rpc.ResetRequestSourceRpcHandler#getResetRequests()
*/
- public List<?> getResetRequests(Map<String, Map<String, Status>> response)
+ public List<?> getResetRequests(Map<String, ResetRequestSource.EngineStatus> response)
{
try
{
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/rpc/ResetRequestSourceRpcHandler.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -23,7 +23,7 @@
import java.util.Map;
-import org.jboss.modcluster.mcmp.ResetRequestSource.Status;
+import org.jboss.modcluster.mcmp.ResetRequestSource;
/**
@@ -32,5 +32,5 @@
*/
public interface ResetRequestSourceRpcHandler<T>
{
- T getResetRequests(Map<String, Map<String, Status>> response);
+ T getResetRequests(Map<String, ResetRequestSource.EngineStatus> response);
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPUtils.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -28,6 +28,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -199,16 +200,27 @@
private static MCMPRequest createRequest(MCMPRequestType type, Context context)
{
- return createContextRequest(type, Utils.getJvmRoute(context), Utils.getHost(context), context.getPath());
+ return createContextRequest(type, Utils.getJvmRoute(context), Utils.getHosts(context), context.getPath());
}
- private static MCMPRequest createContextRequest(MCMPRequestType type, String jvmRoute, String host, String path)
+ private static MCMPRequest createContextRequest(MCMPRequestType type, String jvmRoute, Set<String> hosts, String path)
{
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("Context", "".equals(path) ? "/" : path);
- parameters.put("Alias", host);
+ StringBuilder builder = new StringBuilder();
+ Iterator<String> iter = hosts.iterator();
+ while (iter.hasNext())
+ {
+ builder.append(iter.next());
+ if (iter.hasNext())
+ {
+ builder.append(',');
+ }
+ }
+ parameters.put("Alias", builder.toString());
+
return new MCMPRequest(type, false, jvmRoute, parameters);
}
@@ -250,7 +262,7 @@
/**
* Reset configuration for a particular proxy following an error.
*/
- public static List<MCMPRequest> getResetRequests(Map<String, Map<String, ResetRequestSource.Status>> response, Server server, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
+ public static List<MCMPRequest> getResetRequests(Map<String, ResetRequestSource.EngineStatus> response, Server server, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig)
{
List<MCMPRequest> requests = new ArrayList<MCMPRequest>();
Set<String> jvmRoutes = new HashSet<String>(response.keySet());
@@ -258,20 +270,18 @@
for (Service service: server.findServices())
{
Engine engine = (Engine) service.getContainer();
-
String jvmRoute = engine.getJvmRoute();
jvmRoutes.remove(jvmRoute);
requests.add(createConfigRequest(jvmRoute, service.findConnectors(), nodeConfig, balancerConfig));
- Map<String, ResetRequestSource.Status> contextStatusMap = response.get(jvmRoute);
-
+ ResetRequestSource.EngineStatus engineStatus = response.get(jvmRoute);
Set<String> contexts = new HashSet<String>();
- if (contextStatusMap != null)
+ if (engineStatus != null)
{
- contexts.addAll(contextStatusMap.keySet());
+ contexts.addAll(engineStatus.getContexts().keySet());
}
for (Container child: engine.findChildren())
@@ -279,34 +289,38 @@
for (Container container: child.findChildren())
{
Context context = (Context) container;
-
String path = context.getPath();
contexts.remove(path);
- ResetRequestSource.Status status = (contextStatusMap != null) ? contextStatusMap.get(path) : null;
+ ResetRequestSource.Status status = (engineStatus != null) ? engineStatus.getContexts().get(path) : null;
if (Utils.isContextStarted(context))
{
if (status != ResetRequestSource.Status.ENABLED)
{
- requests.add(createEnableAppRequest(context));
+ requests.add(createContextRequest(MCMPRequestType.ENABLE_APP, jvmRoute, Utils.getHosts(context), path));
}
}
else
{
if (status == ResetRequestSource.Status.ENABLED)
{
- requests.add(createStopAppRequest(context));
+ requests.add(createContextRequest(MCMPRequestType.STOP_APP, jvmRoute, Utils.getHosts(context), path));
}
}
}
}
// Send REMOVE-APP requests for contexts that don't exist
- for (String context: contexts)
+ if (engineStatus != null)
{
- requests.add(createContextRequest(MCMPRequestType.REMOVE_APP, jvmRoute, "", context));
+ Set<String> aliases = engineStatus.getAliases();
+
+ for (String context: contexts)
+ {
+ requests.add(createContextRequest(MCMPRequestType.REMOVE_APP, jvmRoute, aliases, context));
+ }
}
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/ResetRequestSource.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Source for a list of requests that should be sent to an httpd-side
@@ -40,6 +41,12 @@
ENABLED, DISABLED, STOPPED
}
+ interface EngineStatus
+ {
+ Set<String> getAliases();
+ Map<String, Status> getContexts();
+ }
+
/**
* Gets a list of requests that should be sent to an httpd-side
* mod_cluster instance when an {@link MCMPHandler} determines that
@@ -48,5 +55,5 @@
* @param response a parsed INFO-RSP, expressed as the context status per context path, per jvmRoute
* @return a list of requests. Will not return <code>null</code>.
*/
- List<MCMPRequest> getResetRequests(Map<String, Map<String, Status>> response);
+ List<MCMPRequest> getResetRequests(Map<String, EngineStatus> response);
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -63,7 +63,6 @@
import org.jboss.modcluster.mcmp.MCMPURLEncoder;
import org.jboss.modcluster.mcmp.MCMPUtils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
-import org.jboss.modcluster.mcmp.MCMPServerState.State;
/**
* Default implementation of {@link MCMPHandler}.
@@ -289,7 +288,7 @@
{
for (Proxy proxy: this.proxies)
{
- if (proxy.getState() == State.OK)
+ if (proxy.getState() == MCMPServerState.State.OK)
{
proxy.setState(Proxy.State.ERROR);
}
@@ -458,9 +457,9 @@
if (sendResetRequests)
{
- Map<String, Map<String, ResetRequestSource.Status>> responseMap = this.parseInfoResponse(response);
+ Map<String, ResetRequestSource.EngineStatus> parsedResponse = this.parseInfoResponse(response);
- this.sendRequests(this.resetRequestSource.getResetRequests(responseMap));
+ this.sendRequests(this.resetRequestSource.getResetRequests(parsedResponse));
}
}
}
@@ -472,12 +471,12 @@
}
}
- private Map<String, Map<String, ResetRequestSource.Status>> parseInfoResponse(String response)
+ private Map<String, ResetRequestSource.EngineStatus> parseInfoResponse(String response)
{
if (response == null) return Collections.emptyMap();
- Map<String, Map<String, ResetRequestSource.Status>> result = new HashMap<String, Map<String, ResetRequestSource.Status>>();
- Map<String, ResetRequestSource.Status> contextMap = null;
+ Map<String, ResetRequestSource.EngineStatus> result = new HashMap<String, ResetRequestSource.EngineStatus>();
+ ResetRequestSource.EngineStatus engineStatus = null;
for (String line: response.split("\r\n|\r|\n"))
{
@@ -496,16 +495,39 @@
if ("Name".equals(key))
{
- contextMap = new HashMap<String, ResetRequestSource.Status>();
- result.put(entry.substring(index + 1).trim(), contextMap);
+ engineStatus = new EngineStatusImpl();
+ result.put(entry.substring(index + 1).trim(), engineStatus);
break;
}
}
}
}
+ else if (line.startsWith("Vhost:"))
+ {
+ if (engineStatus == null) throw new IllegalStateException();
+
+ String[] entries = line.split(",");
+
+ for (int i = 1; i < entries.length; ++i)
+ {
+ String entry = entries[i];
+ int index = entry.indexOf(':');
+
+ if (index >= 0)
+ {
+ String key = entry.substring(0, index).trim();
+
+ if ("Alias".equals(key))
+ {
+ engineStatus.getAliases().add(entry.substring(index + 1).trim());
+ break;
+ }
+ }
+ }
+ }
else if (line.startsWith("Context:"))
{
- if (contextMap == null) throw new IllegalStateException();
+ if (engineStatus == null) throw new IllegalStateException();
String[] entries = line.split(",");
String context = null;
@@ -532,7 +554,7 @@
}
}
- contextMap.put(context, status);
+ engineStatus.getContexts().put(context, status);
}
}
@@ -1134,4 +1156,28 @@
return sb.toString();
}
}
+
+ class EngineStatusImpl implements ResetRequestSource.EngineStatus
+ {
+ private Set<String> aliases = new LinkedHashSet<String>();
+ private Map<String, ResetRequestSource.Status> contexts = new HashMap<String, ResetRequestSource.Status>();
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.ResetRequestSource.EngineStatus#getAliases()
+ */
+ public Set<String> getAliases()
+ {
+ return this.aliases;
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.ResetRequestSource.EngineStatus#getContexts()
+ */
+ public Map<String, ResetRequestSource.Status> getContexts()
+ {
+ return this.contexts;
+ }
+ }
}
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ClusterListenerTestCase.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -95,43 +95,30 @@
EasyMock.expect(server.findServices()).andReturn(new Service[] { service });
EasyMock.expect(service.getContainer()).andReturn(engine);
-
- // create remove-all request
EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
-
- // create config request
- EasyMock.expect(engine.getService()).andReturn(service);
EasyMock.expect(service.findConnectors()).andReturn(new Connector[] { connector });
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
EasyMock.expect(engine.findChildren()).andReturn(new Container[] { container });
EasyMock.expect(container.findChildren()).andReturn(new Container[] { context });
- EasyMock.expect(context.isStarted()).andReturn(true);
-
- // create enable-app request
EasyMock.expect(context.getPath()).andReturn("/context");
+ EasyMock.expect(context.isStarted()).andReturn(true);
EasyMock.expect(context.getParent()).andReturn(host);
EasyMock.expect(host.getName()).andReturn("host");
EasyMock.expect(host.findAliases()).andReturn(new String[] { "alias1", "alias2" });
- EasyMock.expect(context.getParent()).andReturn(container);
- EasyMock.expect(container.getParent()).andReturn(engine);
- EasyMock.expect(engine.getJvmRoute()).andReturn("host1");
EasyMock.replay(server, service, engine, container, context, host);
- Map<String, Map<String, ResetRequestSource.Status>> emptyResponseMap = Collections.emptyMap();
+ Map<String, ResetRequestSource.EngineStatus> emptyResponseMap = Collections.emptyMap();
List<MCMPRequest> requests = this.listener.getResetRequests(emptyResponseMap);
EasyMock.verify(server, service, engine, container, context, host);
+
+ Assert.assertEquals(2, requests.size());
MCMPRequest request = requests.get(0);
Map<String, String> parameters = request.getParameters();
- Assert.assertSame(MCMPRequestType.REMOVE_APP, request.getRequestType());
- Assert.assertTrue(request.isWildcard());
- Assert.assertEquals("host1", request.getJvmRoute());
-
- request = requests.get(1);
+ request = requests.get(0);
parameters = request.getParameters();
Assert.assertSame(MCMPRequestType.CONFIG, request.getRequestType());
@@ -155,7 +142,7 @@
Assert.assertEquals("6", parameters.get("WaitWorker"));
Assert.assertEquals("7", parameters.get("Maxattempts"));
- request = requests.get(2);
+ request = requests.get(1);
parameters = request.getParameters();
Assert.assertSame(MCMPRequestType.ENABLE_APP, request.getRequestType());
Modified: trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java
===================================================================
--- trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2008-10-22 02:21:19 UTC (rev 1976)
+++ trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/HASingletonAwareResetRequestSourceTestCase.java 2008-10-22 04:35:12 UTC (rev 1977)
@@ -82,7 +82,7 @@
EasyMock.replay(this.singleton, this.key, this.partition);
- Map<String, Map<String, ResetRequestSource.Status>> emptyResponseMap = Collections.emptyMap();
+ Map<String, ResetRequestSource.EngineStatus> emptyResponseMap = Collections.emptyMap();
List<MCMPRequest> results = this.source.getResetRequests(emptyResponseMap);
EasyMock.verify(this.singleton, this.key, this.partition);
@@ -211,7 +211,7 @@
@Test
public void getLocalResetRequests() throws Exception
{
- Map<String, Map<String, ResetRequestSource.Status>> emptyResponseMap = Collections.emptyMap();
+ Map<String, ResetRequestSource.EngineStatus> emptyResponseMap = Collections.emptyMap();
// Test w/out server
List<MCMPRequest> results = this.source.getLocalResetRequests(emptyResponseMap);
16 years, 2 months
JBoss Native SVN: r1976 - trunk/mod_cluster/src/main/java/org/jboss/modcluster.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 22:21:19 -0400 (Tue, 21 Oct 2008)
New Revision: 1976
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
Log:
Tone down status log to debug
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-10-22 02:19:54 UTC (rev 1975)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/ModClusterService.java 2008-10-22 02:21:19 UTC (rev 1976)
@@ -721,7 +721,7 @@
@Override
public void status(Engine engine)
{
- log.info(this.coord.sm.getString("modcluster.engine.status", engine.getName()));
+ log.debug(this.coord.sm.getString("modcluster.engine.status", engine.getName()));
this.coord.latestLoad = this.getLoadBalanceFactor();
16 years, 2 months
JBoss Native SVN: r1975 - in trunk/mod_cluster/src/main/java/org/jboss/modcluster: mcmp and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: pferraro
Date: 2008-10-21 22:19:54 -0400 (Tue, 21 Oct 2008)
New Revision: 1975
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java
Log:
Code cleanup.
Create factory method for MCMPURLEncoder in Util.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 02:15:23 UTC (rev 1974)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 02:19:54 UTC (rev 1975)
@@ -13,6 +13,9 @@
import org.apache.tomcat.util.IntrospectionUtils;
import org.jboss.logging.Logger;
import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
+import org.jboss.modcluster.mcmp.impl.MCMPJBURLEncoder;
+import org.jboss.modcluster.mcmp.impl.MCMPTCURLEncoder;
public class Utils
{
@@ -22,7 +25,7 @@
private enum ServerType
{
- JBOSSWEB, TC6
+ JBOSSWEB, TOMCAT6
}
private static final ServerType serverType = getServerType();
@@ -37,7 +40,7 @@
}
}
- return ServerType.TC6;
+ return ServerType.TOMCAT6;
}
/**
@@ -131,23 +134,18 @@
*/
public static boolean isContextStarted(Context context)
{
- return (serverType == ServerType.TC6) ? true : context.isStarted();
+ return (serverType == ServerType.TOMCAT6) ? true : context.isStarted();
}
/**
- * Tell if running under JBossWEB
- * @return true running under JBossWEB/AS5.0x. False TC6 or AS4.2.x AS4.3.x
+ * MCMPURLEncoder factory
+ * @return the appropriate MCMPURLEncoder for this server
*/
- public static boolean isJBossWEB()
- {
- return (serverType == ServerType.JBOSSWEB);
- }
-/*
public static MCMPURLEncoder createMCMPURLEncoder()
{
return (serverType == ServerType.JBOSSWEB) ? new MCMPJBURLEncoder() : new MCMPTCURLEncoder();
}
-*/
+
public static void establishJvmRouteAndConnectorAddress(Engine engine, MCMPHandler mcmpHandler) throws IOException
{
Connector connector = findProxyConnector(engine.getService().findConnectors());
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java (from rev 1967, trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java (rev 0)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java 2008-10-22 02:19:54 UTC (rev 1975)
@@ -0,0 +1,42 @@
+/*
+ * 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.mcmp;
+
+import java.io.IOException;
+
+/**
+ * Allow to use TC and JBoss url converter.
+ *
+ * @author Jean-Frederic Clere
+ */
+public interface MCMPURLEncoder
+{
+ /** Add parameter to the buffer */
+ void encodeParameter(String key, String value, boolean hasNext) throws IOException;
+
+ /** buffer of the encoded data */
+ char[] getBuffer();
+
+ /** length of the encoded data */
+ int getLength();
+}
Property changes on: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22 02:15:23 UTC (rev 1974)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22 02:19:54 UTC (rev 1975)
@@ -60,6 +60,7 @@
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPServerState;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
import org.jboss.modcluster.mcmp.MCMPUtils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
import org.jboss.modcluster.mcmp.MCMPServerState.State;
@@ -638,19 +639,14 @@
String jvmRoute = request.getJvmRoute();
Map<String, String> parameters = request.getParameters();
- MCMPURLEncoder body = null;
+ MCMPURLEncoder encoder = Utils.createMCMPURLEncoder();
// First, encode the POST body
try
{
- if (Utils.isJBossWEB())
- body = new MCMPJBURLEncoder();
- else
- body = new MCMPTCURLEncoder();
-
if (jvmRoute != null)
{
- body.encodeParameter(this.sm, "JVMRoute", jvmRoute, !parameters.isEmpty());
+ encoder.encodeParameter("JVMRoute", jvmRoute, !parameters.isEmpty());
}
Iterator<Map.Entry<String, String>> entries = parameters.entrySet().iterator();
@@ -659,7 +655,7 @@
{
Map.Entry<String, String> entry = entries.next();
- body.encodeParameter(this.sm, entry.getKey(), entry.getValue(), entries.hasNext());
+ encoder.encodeParameter(entry.getKey(), entry.getValue(), entries.hasNext());
}
}
catch (IOException e)
@@ -720,11 +716,11 @@
writer.write(builder.toString());
writer.write("\r\n");
- writer.write("Content-Length: " + body.getLength() + "\r\n");
+ writer.write("Content-Length: " + encoder.getLength() + "\r\n");
writer.write("User-Agent: ClusterListener/1.0\r\n");
writer.write("Connection: Keep-Alive\r\n");
writer.write("\r\n");
- writer.write(body.getBuffer(), body.getStart(), body.getLength());
+ writer.write(encoder.getBuffer());
writer.write("\r\n");
writer.flush();
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java 2008-10-22 02:15:23 UTC (rev 1974)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java 2008-10-22 02:19:54 UTC (rev 1975)
@@ -24,9 +24,11 @@
import java.io.IOException;
+import org.apache.catalina.util.StringManager;
import org.apache.tomcat.util.buf.CharChunk;
import org.apache.tomcat.util.buf.UEncoder;
-import org.apache.catalina.util.StringManager;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
/**
* Allow to use TC and JBoss url converter.
@@ -34,27 +36,42 @@
* @author Jean-Frederic Clere
*/
public class MCMPJBURLEncoder implements MCMPURLEncoder
-{
+{
+ private static StringManager sm = StringManager.getManager(Constants.Package);
+
+ private final CharChunk body;
+ private final UEncoder encoder;
- private CharChunk body = null;
- private UEncoder encoder;
+ public MCMPJBURLEncoder()
+ {
+ this.encoder = new UEncoder();
- public MCMPJBURLEncoder() throws IOException {
- encoder = new UEncoder();
-
- body = encoder.encodeURL("", 0, 0);
- body.recycle();
+ try
+ {
+ this.body = this.encoder.encodeURL("", 0, 0);
+ this.body.recycle();
+ }
+ catch (IOException e)
+ {
+ // Cannot happen
+ throw new RuntimeException(e);
+ }
}
- /* Add parameter to the buffer */
- public void encodeParameter(StringManager sm, String key, String value, boolean hasNext) throws IOException {
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#encodeParameter(org.apache.catalina.util.StringManager, java.lang.String, java.lang.String, boolean)
+ */
+ public void encodeParameter(String key, String value, boolean hasNext) throws IOException
+ {
if (value == null)
{
throw new IllegalArgumentException(sm.getString("modcluster.error.nullAttribute", key));
}
- encoder.encodeURL(key, 0, key.length()).append('=');
+ this.encoder.encodeURL(key, 0, key.length()).append('=');
- CharChunk body = encoder.encodeURL(value, 0, value.length());
+ CharChunk body = this.encoder.encodeURL(value, 0, value.length());
if (hasNext)
{
@@ -62,18 +79,21 @@
}
}
- /* Return the length of the encoded data */
- public int getLength() {
- return body.getLength();
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getLength()
+ */
+ public int getLength()
+ {
+ return this.body.getLength();
}
- /* Return the length of the encoded data */
- public int getStart() {
- return body.getStart();
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getBuffer()
+ */
+ public char[] getBuffer()
+ {
+ return this.body.getBuffer();
}
-
- /* buffer of the encoded data */
- public char[] getBuffer() {
- return body.getBuffer();
- }
}
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java 2008-10-22 02:15:23 UTC (rev 1974)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java 2008-10-22 02:19:54 UTC (rev 1975)
@@ -22,14 +22,15 @@
package org.jboss.modcluster.mcmp.impl;
+import java.io.CharArrayWriter;
import java.io.IOException;
-import java.io.CharArrayWriter;
import java.io.Writer;
import java.lang.reflect.Method;
-
+import org.apache.catalina.util.StringManager;
import org.apache.tomcat.util.buf.UEncoder;
-import org.apache.catalina.util.StringManager;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
/**
* Allow to use TC and JBoss url converter.
@@ -37,75 +38,84 @@
* @author Jean-Frederic Clere
*/
public class MCMPTCURLEncoder implements MCMPURLEncoder
-{
+{
+ private static final Method urlEncodeMethod;
- private CharArrayWriter body = null;
- private UEncoder encoder = null;
- private char[] buff = null;
-
- private static Method method = null;
-
- static {
- try {
- Class [] classes = new Class[2];
- classes[0] = java.io.Writer.class;
- classes[1] = java.lang.String.class;
- method = Class.forName("org.apache.tomcat.util.buf.UEncoder").getMethod("urlEncode", classes);
- } catch (Exception ex) {
+ static
+ {
+ try
+ {
+ urlEncodeMethod = UEncoder.class.getMethod("urlEncode", Writer.class, String.class);
}
+ catch (NoSuchMethodException e)
+ {
+ throw new IllegalStateException(e);
+ }
}
- MCMPTCURLEncoder() {
- encoder = new UEncoder();
+ private static final StringManager sm = StringManager.getManager(Constants.Package);
+
+ private final CharArrayWriter writer;
+ private final UEncoder encoder;
- body = new CharArrayWriter();
+ public MCMPTCURLEncoder()
+ {
+ this.encoder = new UEncoder();
+ this.writer = new CharArrayWriter();
}
- /* Add parameter to the buffer */
- public void encodeParameter(StringManager sm, String key, String value, boolean hasNext) throws IOException {
- Object [] objects = new Object[2];
- objects[0] = body;
- objects[1] = key;
+
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#encodeParameter(org.apache.catalina.util.StringManager, java.lang.String, java.lang.String, boolean)
+ */
+ public void encodeParameter(String key, String value, boolean hasNext) throws IOException
+ {
if (value == null)
{
throw new IllegalArgumentException(sm.getString("modcluster.error.nullAttribute", key));
}
- try {
- method.invoke(encoder, objects);
- } catch (Exception ex) {
- body.write(key);
+ try
+ {
+ urlEncodeMethod.invoke(this.encoder, this.writer, key);
}
- body.write('=');
+ catch (Exception e)
+ {
+ this.writer.write(key);
+ }
+
+ this.writer.write('=');
- objects[1] = value;
- try {
- method.invoke(encoder, objects);
- } catch (Exception ex) {
- body.write(value);
+ try
+ {
+ urlEncodeMethod.invoke(this.encoder, this.writer, value);
}
+ catch (Exception e)
+ {
+ this.writer.write(value);
+ }
if (hasNext)
{
- body.write('&');
+ this.writer.write('&');
}
}
- /* Return the length of the encoded data */
- public int getLength() {
- if (buff == null)
- buff = body.toCharArray();
- return buff.length;
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getLength()
+ */
+ public int getLength()
+ {
+ return this.writer.size();
}
- /* Return the start of the encoded data */
- public int getStart() {
- return 0;
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getBuffer()
+ */
+ public char[] getBuffer()
+ {
+ return this.writer.toCharArray();
}
-
- /* buffer of the encoded data */
- public char[] getBuffer() {
- if (buff == null)
- buff = body.toCharArray();
- return buff;
- }
}
Deleted: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java 2008-10-22 02:15:23 UTC (rev 1974)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java 2008-10-22 02:19:54 UTC (rev 1975)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.modcluster.mcmp.impl;
-
-import java.io.IOException;
-import org.apache.catalina.util.StringManager;
-
-/**
- * Allow to use TC and JBoss url converter.
- *
- * @author Jean-Frederic Clere
- */
-public interface MCMPURLEncoder
-{
-
- /* Add parameter to the buffer */
- void encodeParameter(StringManager sm, String key, String value, boolean hasNext) throws IOException;
-
- /* Return the length of the encoded data */
- int getLength();
-
- /* Return the start of the encoded data */
- int getStart();
-
- /* buffer of the encoded data */
- char[] getBuffer();
-}
16 years, 2 months