You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/11/17 12:02:22 UTC
svn commit: r595934 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/component/seda/
main/java/org/apache/camel/component/vm/
main/java/org/apache/camel/converter/
test/java/org/apache/camel/component/seda/
Author: jstrachan
Date: Sat Nov 17 03:02:20 2007
New Revision: 595934
URL: http://svn.apache.org/viewvc?rev=595934&view=rev
Log:
applied fix and test case for CAMEL-230 to allow SEDA/VM endpoints to be configured via seda:foo?size=2000
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/VmComponent.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java?rev=595934&r1=595933&r2=595934&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java Sat Nov 17 03:02:20 2007
@@ -22,6 +22,7 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
+import org.apache.camel.converter.ObjectConverter;
import org.apache.camel.impl.DefaultComponent;
/**
@@ -30,13 +31,22 @@
*
* @version $Revision: 1.1 $
*/
-public class SedaComponent extends DefaultComponent {
- public BlockingQueue<Exchange> createQueue() {
- return new LinkedBlockingQueue<Exchange>(1000);
+public class SedaComponent extends DefaultComponent<Exchange> {
+
+ public BlockingQueue<Exchange> createQueue(String uri, Map parameters) {
+ int size = 1000;
+ Object value = parameters.remove("size");
+ if (value != null) {
+ Integer i = convertTo(Integer.class, value);
+ if (i != null) {
+ size = i;
+ }
+ }
+ return new LinkedBlockingQueue<Exchange>(size);
}
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
- return new SedaEndpoint(uri, this);
+ return new SedaEndpoint(uri, this, parameters);
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java?rev=595934&r1=595933&r2=595934&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java Sat Nov 17 03:02:20 2007
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.seda;
+import java.util.Map;
import java.util.concurrent.BlockingQueue;
import org.apache.camel.AsyncCallback;
@@ -26,9 +27,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.ExchangePattern;
import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.DefaultProducer;
/**
@@ -61,8 +60,8 @@
this.queue = queue;
}
- public SedaEndpoint(String uri, SedaComponent component) {
- this(uri, component, component.createQueue());
+ public SedaEndpoint(String uri, SedaComponent component, Map parameters) {
+ this(uri, component, component.createQueue(uri, parameters));
}
public Producer createProducer() throws Exception {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/VmComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/VmComponent.java?rev=595934&r1=595933&r2=595934&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/VmComponent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/VmComponent.java Sat Nov 17 03:02:20 2007
@@ -41,15 +41,15 @@
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
- BlockingQueue<Exchange> blockingQueue = getBlockingQueue(uri);
+ BlockingQueue<Exchange> blockingQueue = getBlockingQueue(uri, parameters);
return new SedaEndpoint(uri, this, blockingQueue);
}
- protected BlockingQueue<Exchange> getBlockingQueue(String uri) {
+ protected BlockingQueue<Exchange> getBlockingQueue(String uri, Map parameters) {
synchronized (queues) {
BlockingQueue<Exchange> answer = queues.get(uri);
if (answer == null) {
- answer = createQueue();
+ answer = createQueue(uri, parameters);
queues.put(uri, answer);
}
return answer;
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java?rev=595934&r1=595933&r2=595934&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java Sat Nov 17 03:02:20 2007
@@ -126,4 +126,127 @@
return false;
}
+
+ /**
+ * Returns the converted value, or null if the value is null
+ */
+ @Converter
+ public static Byte toByte(Object value) {
+ if (value instanceof Byte) {
+ return (Byte) value;
+ }
+ else if (value instanceof Number) {
+ Number number = (Number) value;
+ return number.byteValue();
+ }
+ else if (value instanceof String) {
+ return Byte.parseByte((String) value);
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the converted value, or null if the value is null
+ */
+ @Converter
+ public static Short toShort(Object value) {
+ if (value instanceof Short) {
+ return (Short) value;
+ }
+ else if (value instanceof Number) {
+ Number number = (Number) value;
+ return number.shortValue();
+ }
+ else if (value instanceof String) {
+ return Short.parseShort((String) value);
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the converted value, or null if the value is null
+ */
+ @Converter
+ public static Integer toInteger(Object value) {
+ if (value instanceof Integer) {
+ return (Integer) value;
+ }
+ else if (value instanceof Number) {
+ Number number = (Number) value;
+ return number.intValue();
+ }
+ else if (value instanceof String) {
+ return Integer.parseInt((String) value);
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the converted value, or null if the value is null
+ */
+ @Converter
+ public static Long toLong(Object value) {
+ if (value instanceof Long) {
+ return (Long) value;
+ }
+ else if (value instanceof Number) {
+ Number number = (Number) value;
+ return number.longValue();
+ }
+ else if (value instanceof String) {
+ return Long.parseLong((String) value);
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the converted value, or null if the value is null
+ */
+ @Converter
+ public static Float toFloat(Object value) {
+ if (value instanceof Float) {
+ return (Float) value;
+ }
+ else if (value instanceof Number) {
+ Number number = (Number) value;
+ return number.floatValue();
+ }
+ else if (value instanceof String) {
+ return Float.parseFloat((String) value);
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the converted value, or null if the value is null
+ */
+ @Converter
+ public static Double toDouble(Object value) {
+ if (value instanceof Double) {
+ return (Double) value;
+ }
+ else if (value instanceof Number) {
+ Number number = (Number) value;
+ return number.doubleValue();
+ }
+ else if (value instanceof String) {
+ return Double.parseDouble((String) value);
+ }
+ else {
+ return null;
+ }
+ }
+
+
+
}
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java?rev=595934&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java Sat Nov 17 03:02:20 2007
@@ -0,0 +1,37 @@
+/**
+ *
+ * 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.seda;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class SedaConfigureTest extends ContextTestSupport {
+
+ public void testBlockingQueueConfigured() throws Exception {
+ SedaEndpoint endpoint = resolveMandatoryEndpoint("seda:foo?size=2000", SedaEndpoint.class);
+ BlockingQueue<Exchange> queue = endpoint.getQueue();
+ LinkedBlockingQueue blockingQueue = assertIsInstanceOf(LinkedBlockingQueue.class, queue);
+ assertEquals("remainingCapacity", 2000, blockingQueue.remainingCapacity());
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java
------------------------------------------------------------------------------
svn:eol-style = native