You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2007/03/22 17:11:22 UTC
svn commit: r521319 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/impl/
camel-jbi/src/main/java/org/apache/camel/component/jbi/
camel-jms/src/main/java/org/apache/camel/component/jms/ c...
Author: jstrachan
Date: Thu Mar 22 09:11:21 2007
New Revision: 521319
URL: http://svn.apache.org/viewvc?view=rev&rev=521319
Log:
improved the Mina component so that it is capable of creating different connectors/acceptors using the URI; also added Exception to the activation methods
Added:
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java (with props)
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java (with props)
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java (contents, props changed)
- copied, changed from r521303, activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
Removed:
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Endpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java
activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
activemq/camel/trunk/camel-mina/pom.xml
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu Mar 22 09:11:21 2007
@@ -68,7 +68,7 @@
/**
* Activates all the starting endpoints in that were added as routes.
*/
- public void activateEndpoints();
+ public void activateEndpoints() throws Exception;
/**
* Deactivates all the starting endpoints in that were added as routes.
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Endpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Endpoint.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Endpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Endpoint.java Thu Mar 22 09:11:21 2007
@@ -56,7 +56,7 @@
*
* @throws IllegalStateException if the Endpoint has already been activated.
*/
- void activate(Processor<E> processor) throws IllegalStateException;
+ void activate(Processor<E> processor) throws Exception;
/**
* Called by the container when the endpoint is deactivated
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Thu Mar 22 09:11:21 2007
@@ -115,7 +115,7 @@
/**
* Activates all the starting endpoints in that were added as routes.
*/
- public void activateEndpoints() {
+ public void activateEndpoints() throws Exception {
for (Map.Entry<Endpoint, Processor> entry : routes.entrySet()) {
Endpoint endpoint = entry.getKey();
Processor processor = entry.getValue();
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java Thu Mar 22 09:11:21 2007
@@ -23,6 +23,7 @@
import org.apache.camel.util.ObjectHelper;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.io.IOException;
/**
* A default endpoint useful for implementation inheritence
@@ -78,7 +79,7 @@
return getContext().getExchangeConverter().convertTo(type, exchange);
}
- public void activate(Processor<E> inboundProcessor) {
+ public void activate(Processor<E> inboundProcessor) throws Exception {
if (activated.compareAndSet(false, true)) {
deactivated.set(false);
this.inboundProcessor = inboundProcessor;
@@ -117,7 +118,7 @@
/**
* Called at most once by the container to activate the endpoint
*/
- protected void doActivate() {
+ protected void doActivate() throws Exception {
}
/**
Modified: activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java (original)
+++ activemq/camel/trunk/camel-jbi/src/main/java/org/apache/camel/component/jbi/JbiEndpoint.java Thu Mar 22 09:11:21 2007
@@ -40,7 +40,7 @@
}
@Override
- protected void doActivate() {
+ protected void doActivate() throws Exception {
super.doActivate();
Processor<JbiExchange> processor = getInboundProcessor();
Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java (original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java Thu Mar 22 09:11:21 2007
@@ -106,7 +106,7 @@
// Implementation methods
//-------------------------------------------------------------------------
- protected void doActivate() {
+ protected void doActivate() throws Exception {
super.doActivate();
listenerContainer.afterPropertiesSet();
listenerContainer.initialize();
Modified: activemq/camel/trunk/camel-mina/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/pom.xml?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-mina/pom.xml (original)
+++ activemq/camel/trunk/camel-mina/pom.xml Thu Mar 22 09:11:21 2007
@@ -18,7 +18,7 @@
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
@@ -41,8 +41,8 @@
</dependency>
<dependency>
- <groupId>org.apache.mina</groupId>
- <artifactId>mina-java5</artifactId>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-java5</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -56,4 +56,32 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <childDelegation>false</childDelegation>
+ <useFile>true</useFile>
+
+ <!--
+ <systemProperties>
+ <property>
+ <name>org.apache.camel.foo</name>
+ <value>bar</value>
+ </property>
+ </systemProperties>
+ -->
+
+ <includes>
+ <include>**/*Test.*</include>
+ </includes>
+ <excludes>
+ <exclude>**/MinaTcpTest.*</exclude>
+ <exclude>**/MinaMulticastTest.*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java (original)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java Thu Mar 22 09:11:21 2007
@@ -19,14 +19,22 @@
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultComponent;
-import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+import org.apache.mina.transport.socket.nio.DatagramConnector;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketConnector;
import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
import org.apache.mina.transport.vmpipe.VmPipeAddress;
import org.apache.mina.transport.vmpipe.VmPipeConnector;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -43,27 +51,50 @@
super(context);
}
- public synchronized MinaEndpoint createEndpoint(String uri, String[] urlParts) throws IOException {
+ public synchronized MinaEndpoint createEndpoint(String uri, String[] urlParts) throws IOException, URISyntaxException {
MinaEndpoint endpoint = map.get(uri);
if (endpoint == null) {
- IoAcceptor acceptor = new VmPipeAcceptor();
- endpoint = new MinaEndpoint(uri, getContext(), acceptor);
+ String remainingUrl = uri.substring("mina:".length());
+ URI u = new URI(remainingUrl);
- VmPipeAddress address = new VmPipeAddress(8080);
-
- // Set up server
- acceptor.bind(address, endpoint.getServerHandler());
-
- // Connect to the server.
- VmPipeConnector connector = new VmPipeConnector();
- ConnectFuture future = connector.connect(address, endpoint.getClientHandler());
- future.join();
- IoSession session = future.getSession();
-
- endpoint.setSession(session);
+ String protocol = u.getScheme();
+ if (protocol.equals("tcp")) {
+ endpoint = createSocketEndpoint(uri, u);
+ }
+ else if (protocol.equals("udp") || protocol.equals("mcast") || protocol.equals("multicast")) {
+ endpoint = createDatagramEndpoint(uri, u);
+ }
+ else if (protocol.equals("vm")) {
+ endpoint = createVmEndpoint(uri, u);
+ }
+ else {
+ throw new IOException("Unrecognised MINA protocol: " + protocol + " for uri: " + uri);
+ }
map.put(uri, endpoint);
}
return endpoint;
+ }
+
+ protected MinaEndpoint createVmEndpoint(String uri, URI connectUri) {
+ IoAcceptor acceptor = new VmPipeAcceptor();
+ SocketAddress address = new VmPipeAddress(connectUri.getPort());
+ IoConnector connector = new VmPipeConnector();
+
+ return new MinaEndpoint(uri, getContext(), address, acceptor, connector);
+ }
+
+ protected MinaEndpoint createSocketEndpoint(String uri, URI connectUri) {
+ IoAcceptor acceptor = new SocketAcceptor();
+ SocketAddress address = new InetSocketAddress(connectUri.getHost(), connectUri.getPort());
+ IoConnector connector = new SocketConnector();
+ return new MinaEndpoint(uri, getContext(), address, acceptor, connector);
+ }
+
+ protected MinaEndpoint createDatagramEndpoint(String uri, URI connectUri) {
+ IoAcceptor acceptor = new DatagramAcceptor();
+ SocketAddress address = new InetSocketAddress(connectUri.getHost(), connectUri.getPort());
+ IoConnector connector = new DatagramConnector();
+ return new MinaEndpoint(uri, getContext(), address, acceptor, connector);
}
}
Modified: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java (original)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java Thu Mar 22 09:11:21 2007
@@ -19,23 +19,39 @@
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
-import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.support.BaseIoConnector;
+import org.apache.mina.transport.vmpipe.VmPipeConnector;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.net.SocketAddress;
+import java.io.IOException;
/**
* @version $Revision$
*/
public class MinaEndpoint extends DefaultEndpoint<MinaExchange> {
+ private static final transient Log log = LogFactory.getLog(MinaEndpoint.class);
+
private IoSession session;
private IoHandler serverHandler;
private IoHandler clientHandler;
private final IoAcceptor acceptor;
+ private final SocketAddress address;
+ private final IoConnector connector;
- public MinaEndpoint(String endpointUri, CamelContext container, IoAcceptor acceptor) {
+
+ public MinaEndpoint(String endpointUri, CamelContext container, SocketAddress address, IoAcceptor acceptor, IoConnector connector) {
super(endpointUri, container);
+ this.address = address;
this.acceptor = acceptor;
+ this.connector = connector;
}
public void onExchange(MinaExchange exchange) {
@@ -43,7 +59,7 @@
if (body == null) {
System.out.println("#### No payload for exchange: " + exchange);
}
- session.write(body);
+ getSession().write(body);
}
public MinaExchange createExchange() {
@@ -72,6 +88,7 @@
}
public IoSession getSession() {
+ // TODO lazy create if no inbound processor attached?
return session;
}
@@ -79,9 +96,37 @@
this.session = session;
}
-
// Implementation methods
//-------------------------------------------------------------------------
+
+ @Override
+ protected void doActivate() throws Exception {
+ super.doActivate();
+
+ if (getInboundProcessor() != null) {
+ // lets initiate the server
+
+ if (log.isDebugEnabled()) {
+ log.debug("Binding to server address: " + address + " using acceptor: " + acceptor);
+ }
+
+ acceptor.bind(address, getServerHandler());
+ }
+ setSession(createSession());
+ }
+
+ /**
+ * Initiates the client connection for outbound communication
+ */
+ protected IoSession createSession() {
+ if (log.isDebugEnabled()) {
+ log.debug("Creating connector to address: " + address + " using connector: " + connector);
+ }
+ ConnectFuture future = connector.connect(address, getClientHandler());
+ future.join();
+ return future.getSession();
+ }
+
@Override
protected void doDeactivate() {
Modified: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java?view=diff&rev=521319&r1=521318&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java (original)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java Thu Mar 22 09:11:21 2007
@@ -25,6 +25,7 @@
import java.util.concurrent.Callable;
import java.io.IOException;
+import java.net.URISyntaxException;
/**
* An implementation of {@link EndpointResolver} that creates
@@ -53,7 +54,7 @@
* Finds the {@link MinaEndpoint} specified by the uri. If the {@link MinaEndpoint} or it's associated
* {@see QueueComponent} object do not exist, they will be created.
*/
- public MinaEndpoint resolveEndpoint(CamelContext container, String uri) throws IOException {
+ public MinaEndpoint resolveEndpoint(CamelContext container, String uri) throws IOException, URISyntaxException {
String[] urlParts = getEndpointId(uri);
MinaComponent component = resolveMinaComponent(container, urlParts[0]);
return component.createEndpoint(uri, urlParts);
Added: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java?view=auto&rev=521319
==============================================================================
--- activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java (added)
+++ activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java Thu Mar 22 09:11:21 2007
@@ -0,0 +1,28 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mina;
+
+/**
+ * @version $Revision$
+ */
+public class MinaMulticastTest extends MinaVmTest {
+ @Override
+ protected void setUp() throws Exception {
+ uri = "mina:multicast://224.1.2.3:6255";
+ super.setUp();
+ }}
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaMulticastTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java?view=auto&rev=521319
==============================================================================
--- activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java (added)
+++ activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java Thu Mar 22 09:11:21 2007
@@ -0,0 +1,29 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mina;
+
+/**
+ * @version $Revision$
+ */
+public class MinaTcpTest extends MinaVmTest {
+ @Override
+ protected void setUp() throws Exception {
+ uri = "mina:tcp://localhost:6123";
+ super.setUp();
+ }
+}
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java (from r521303, activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java?view=diff&rev=521319&p1=activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java&r1=521303&p2=activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java&r2=521319
==============================================================================
--- activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java (original)
+++ activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java Thu Mar 22 09:11:21 2007
@@ -18,44 +18,29 @@
package org.apache.camel.component.mina;
import junit.framework.TestCase;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
import org.apache.camel.Endpoint;
import org.apache.camel.Message;
+import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
/**
* @version $Revision$
*/
-public class MinaTest extends TestCase {
- public void testMinaRoute() throws Exception {
- final CountDownLatch latch = new CountDownLatch(1);
-
- CamelContext container = new DefaultCamelContext();
+public class MinaVmTest extends TestCase {
+ protected CamelContext container = new DefaultCamelContext();
+ protected CountDownLatch latch = new CountDownLatch(1);
+ protected MinaExchange receivedExchange;
+ protected String uri = "mina:vm://localhost:8080";
- // lets add some routes
- container.setRoutes(new RouteBuilder() {
- public void configure() {
- from("mina:vm:8080").process(new Processor<MinaExchange>() {
- public void onExchange(MinaExchange e) {
- System.out.println("Received exchange: " + e.getIn());
- latch.countDown();
- }
- });
- }
- });
-
-
- container.activateEndpoints();
+ public void testMinaRoute() throws Exception {
// now lets fire in a message
- Endpoint<MinaExchange> endpoint = container.resolveEndpoint("mina:vm:8080");
+ Endpoint<MinaExchange> endpoint = container.resolveEndpoint(uri);
MinaExchange exchange = endpoint.createExchange();
Message message = exchange.getIn();
message.setBody("Hello there!");
@@ -66,7 +51,31 @@
// now lets sleep for a while
boolean received = latch.await(5, TimeUnit.SECONDS);
assertTrue("Did not receive the message!", received);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ container.setRoutes(createRouteBuilder());
+ container.activateEndpoints();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
container.deactivateEndpoints();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from(uri).process(new Processor<MinaExchange>() {
+ public void onExchange(MinaExchange e) {
+ System.out.println("Received exchange: " + e.getIn());
+ receivedExchange = e;
+ latch.countDown();
+ }
+ });
+ }
+ };
}
}
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaVmTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain