Author: gertv
Date: Fri Mar 25 22:06:02 2011
New Revision: 1085578
URL: http://svn.apache.org/viewvc?rev=1085578&view=rev
Log:
SMX4NMR-253: Allow configuring endpoint channel through properties at
registration time
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ChannelImplTest.java
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java
servicemix/smx4/nmr/trunk/pom.xml
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java?rev=1085578&r1=1085577&r2=1085578&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java
Fri Mar 25 22:06:02 2011
@@ -311,4 +311,12 @@ public class ChannelImpl implements Inte
}
}
+ /**
+ * Provide access to the underlying Executor
+ *
+ * @return the excecutor instance
+ */
+ protected final Executor getExecutor() {
+ return executor;
+ }
}
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java?rev=1085578&r1=1085577&r2=1085578&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
Fri Mar 25 22:06:02 2011
@@ -120,7 +120,7 @@ public class EndpointRegistryImpl implem
name = EXECUTOR_DEFAULT;
}
name = EXECUTOR_PREFIX + name;
- Executor executor = executorFactory.createExecutor(name);
+ Executor executor = executorFactory.createExecutor(name,
(Map<String, Object>) properties);
// Create channel
ChannelImpl channel = new ChannelImpl(wrapper, executor, nmr);
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ChannelImplTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ChannelImplTest.java?rev=1085578&r1=1085577&r2=1085578&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ChannelImplTest.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ChannelImplTest.java
Fri Mar 25 22:06:02 2011
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
+import org.apache.servicemix.executors.ExecutorFactory;
import org.apache.servicemix.nmr.api.NMR;
import org.apache.servicemix.nmr.api.Channel;
import org.apache.servicemix.nmr.api.Pattern;
@@ -175,6 +176,31 @@ public class ChannelImplTest extends Tes
assertNotNull(ep2.exchange);
assertEquals(Status.Error, e.getStatus());
}
+
+ /**
+ * Test to ensure that adding additional configuration properties to the
endpoint registration properties
+ * does not interfere with normal exchange routing
+ *
+ * @throws Exception
+ */
+ public void testSendToEndpointWithAdditionalConfig() throws Exception {
+ nmr.getEndpointRegistry().register(new PingPongEndpoint(),
+
ServiceHelper.createMap(Endpoint.NAME, "pingpong",
+
ExecutorFactory.CORE_POOL_SIZE, "10"));
+
+ Channel channel = nmr.createChannel();
+ Exchange exchange = channel.createExchange(Pattern.InOut);
+ exchange.getIn().setBody(PingPongEndpoint.PING);
+
exchange.setTarget(nmr.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME,
"pingpong")));
+
+ channel.sendSync(exchange);
+
+ assertEquals(Status.Active, exchange.getStatus());
+ assertEquals(PingPongEndpoint.PONG, exchange.getOut().getBody());
+
+ exchange.setStatus(Status.Done);
+ channel.send(exchange);
+ }
public void testChangeThreadNameForSyncExchange() throws Exception {
final BlockingEndpoint blocking = new BlockingEndpoint(1);
@@ -247,6 +273,27 @@ public class ChannelImplTest extends Tes
}
}
+
+ protected static class PingPongEndpoint implements Endpoint {
+
+ protected static final String PING = "ping";
+ protected static final String PONG = "pong";
+
+ private Channel channel;
+
+ public void setChannel(Channel channel) {
+ this.channel = channel;
+ }
+
+ public synchronized void process(Exchange exchange) {
+ if (exchange.getStatus() == Status.Active) {
+ if (PING.equals(exchange.getIn().getBody(String.class))) {
+ exchange.getOut().setBody("pong");
+ channel.send(exchange);
+ }
+ }
+ }
+ }
private static class BlockingEndpoint implements Endpoint {
Modified:
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java?rev=1085578&r1=1085577&r2=1085578&view=diff
==============================================================================
---
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java
(original)
+++
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java
Fri Mar 25 22:06:02 2011
@@ -16,6 +16,7 @@
*/
package org.apache.servicemix.nmr.core;
+import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -23,6 +24,9 @@ import java.util.concurrent.CountDownLat
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
+import org.apache.servicemix.executors.ExecutorFactory;
+import org.apache.servicemix.executors.impl.ExecutorConfig;
+import org.apache.servicemix.executors.impl.ExecutorImpl;
import org.apache.servicemix.nmr.api.Channel;
import org.apache.servicemix.nmr.api.Endpoint;
import org.apache.servicemix.nmr.api.EndpointRegistry;
@@ -172,6 +176,31 @@ public class EndpointRegistryImplTest ex
assertFalse(endpoints.iterator().hasNext());
}
+ /**
+ * Test to ensure that the underlying executor can be configured by adding
additional properties when registering
+ * the endpoint
+ */
+ public void testConfigureChannelOnRegistration() throws Exception {
+ DummyEndpoint endpoint = new DummyEndpoint();
+ registry.register(endpoint, ServiceHelper.createMap(Endpoint.NAME,
"some.endpoint.name",
+
ExecutorFactory.CORE_POOL_SIZE, "12"));
+
+
+ // a bit of reflection magic to find the executor config
+ Field field = ExecutorImpl.class.getDeclaredField("config");
+ field.setAccessible(true);
+ ExecutorConfig config = (ExecutorConfig)
field.get(endpoint.channel.getExecutor());
+
+ // ensure that we have the core pool size value we requested
+ assertEquals(12, config.getCorePoolSize());
+
+ // let's make sure the endpoint is still available under the intended
name
+ InternalReference reference =
+ (InternalReference)
registry.lookup(ServiceHelper.createMap(Endpoint.NAME, "some.endpoint.name"));
+ assertNotNull(reference.choose(registry));
+ assertTrue(reference.choose(registry).iterator().hasNext());
+ }
+
private Endpoint createWiredEndpoint(Map<String, Object> from) {
return createWiredEndpoint(from,
ServiceHelper.createMap(Endpoint.SERVICE_NAME, "test:service",
Endpoint.ENDPOINT_NAME, "endpoint"));
Modified: servicemix/smx4/nmr/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/pom.xml?rev=1085578&r1=1085577&r2=1085578&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/pom.xml Fri Mar 25 22:06:02 2011
@@ -99,7 +99,7 @@
<servicemix-shared.version>${servicemix.components.version}</servicemix-shared.version>
<servicemix.legal.version>1.0</servicemix.legal.version>
<servicemix.specs.version>1.7.0</servicemix.specs.version>
- <servicemix-utils.version>1.4.0</servicemix-utils.version>
+ <servicemix-utils.version>1.5.0-SNAPSHOT</servicemix-utils.version>
<!-- Spring -->
<spring.version>3.0.5.RELEASE</spring.version>