Skip to content
This repository

Wip 1970 camel producer converters #385

Merged
merged 7 commits into from almost 2 years ago

2 participants

Piotr Gabryanczyk Viktor Klang (√)
Piotr Gabryanczyk

Added a ticket for this pull request and renamed the branch as requested by Roland.

akka-camel/src/main/scala/akka/camel/javaapi/UntypedProducerActor.scala
((10 lines not shown))
31 42
 
32  
-  final override def receiveBeforeProduce = {
33  
-    case msg: AnyRef ⇒ onReceiveBeforeProduce(msg)
  43
+  final override def transformResponse(msg: Any) = msg match {
1
Viktor Klang (√) Owner

Add return type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
akka-camel/src/main/scala/akka/camel/javaapi/UntypedProducerActor.scala
((15 lines not shown))
34 45
   }
35 46
 
36  
-  final override def receiveAfterProduce = {
37  
-    case msg: AnyRef ⇒ onReceiveAfterProduce(msg)
  47
+  final override def routeResponse = {
1
Viktor Klang (√) Owner

Add return type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
akka-camel/src/main/scala/akka/camel/javaapi/UntypedProducerActor.scala
@@ -27,14 +34,18 @@ abstract class UntypedProducerActor extends UntypedActor with ProducerSupport {
27 34
    * if <code>oneway</code> is <code>false</code>. If <code>oneway</code> is <code>true</code>, nothing is
28 35
    * done. This method may be overridden by subclasses (e.g. to forward responses to another actor).
29 36
    */
30  
-  def onReceiveAfterProduce(message: AnyRef): Unit = super.receiveAfterProduce(message)
  37
+  def onRouteResponse(message: AnyRef): Unit = super.routeResponse(message)
  38
+
  39
+  final override def transformOutgoingMessage(msg: Any) = msg match {
1
Viktor Klang (√) Owner

Add return type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Viktor Klang (√)
Owner

Hey guys, anything you want me to have a look at?

Piotr Gabryanczyk
akka-camel/src/main/scala/akka/camel/javaapi/UntypedProducerActor.scala
@@ -27,14 +34,18 @@ abstract class UntypedProducerActor extends UntypedActor with ProducerSupport {
27 34
    * if <code>oneway</code> is <code>false</code>. If <code>oneway</code> is <code>true</code>, nothing is
28 35
    * done. This method may be overridden by subclasses (e.g. to forward responses to another actor).
29 36
    */
30  
-  def onReceiveAfterProduce(message: AnyRef): Unit = super.receiveAfterProduce(message)
  37
+  def onRouteResponse(message: AnyRef): Unit = super.routeResponse(message)
  38
+
  39
+  final override def transformOutgoingMessage(msg: Any): AnyRef = msg match {
  40
+    case msg: AnyRef ⇒ onTransformOutgoingMessage(msg)
5
Viktor Klang (√) Owner

So it's impossible to transform the AnyVals? and should be a MatchError?

Piotr Gabryanczyk
piotrga added a note April 14, 2012

I guess so. What's your thinking?

Piotr Gabryanczyk
piotrga added a note April 14, 2012

Is there an elegant solution for this problem or we should drop it on the floor like we do now? Poor java guys...

Viktor Klang (√) Owner

just do: message.asInstanceOf[AnyRef]?

Piotr Gabryanczyk
piotrga added a note April 20, 2012

fair enough - it will just box the primitives. Wouldn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Viktor Klang (√)
Owner
Piotr Gabryanczyk

comments are addressed apart from Any => AnyRef problem in java.
Can we merge it please. I promise I'll fix this issue as a priority.
I care about this pull request because the scala days demo contains references to this code and it will get people confused if it's not there.

akka-camel/src/main/scala/akka/camel/Producer.scala
@@ -114,8 +119,9 @@ trait ProducerSupport { this: Actor ⇒
114 119
    * done. This method may be overridden by subtraits or subclasses (e.g. to forward responses to another
115 120
    * actor).
116 121
    */
117  
-  protected def receiveAfterProduce: Receive = {
118  
-    case msg ⇒ if (!oneway) sender ! msg
  122
+
  123
+  protected def routeResponse(msg: Any): Any = {
3
Viktor Klang (√) Owner

This method only returns Unit, not Any.

Viktor Klang (√) Owner

This still is wrong...

Piotr Gabryanczyk
piotrga added a note April 23, 2012

Sorry for this ping-pong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Viktor Klang (√)
Owner

Just make the 2 changes I proposed and I'll merge.

Thanks

Piotr Gabryanczyk

changes applied

Viktor Klang (√)
Owner

not pushed?

Piotr Gabryanczyk

pushed now... IntelliJ plays tricks on me with git...

Piotr Gabryanczyk

All suggestions eventually applied.

Piotr Gabryanczyk piotrga commented on the diff April 23, 2012
akka-camel/src/main/scala/akka/camel/javaapi/UntypedProducerActor.scala
@@ -27,15 +34,11 @@ abstract class UntypedProducerActor extends UntypedActor with ProducerSupport {
27 34
    * if <code>oneway</code> is <code>false</code>. If <code>oneway</code> is <code>true</code>, nothing is
28 35
    * done. This method may be overridden by subclasses (e.g. to forward responses to another actor).
29 36
    */
30  
-  def onReceiveAfterProduce(message: AnyRef): Unit = super.receiveAfterProduce(message)
31  
-
32  
-  final override def receiveBeforeProduce = {
33  
-    case msg: AnyRef ⇒ onReceiveBeforeProduce(msg)
34  
-  }
  37
+  def onRouteResponse(message: AnyRef): Unit = super.routeResponse(message)
2
Piotr Gabryanczyk
piotrga added a note April 23, 2012

Viktor, do we want to keep it that way or should we just use curly braces instead?

Viktor Klang (√) Owner

I think we can leave it as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Viktor Klang (√) viktorklang commented on the diff April 23, 2012
akka-camel/src/test/scala/akka/camel/ProducerFeatureTest.scala
@@ -277,9 +277,7 @@ object ProducerFeatureTest {
277 277
   class TestForwarder(uri: String, target: ActorRef) extends Actor with Producer {
278 278
     def endpointUri = uri
279 279
 
280  
-    override protected def receiveAfterProduce = {
281  
-      case msg ⇒ target forward msg
282  
-    }
  280
+    override protected def routeResponse(msg: Any): Any = { target forward msg }
1
Viktor Klang (√) Owner

This shouldn't return Any. It's Unit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Viktor Klang (√)
Owner

I'll merge and fix manually. Thanks Piotr!

Viktor Klang (√) viktorklang merged commit b43f011 into from April 23, 2012
Viktor Klang (√) viktorklang closed this April 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
24  akka-camel/src/main/scala/akka/camel/Producer.scala
@@ -88,13 +88,13 @@ trait ProducerSupport { this: Actor ⇒
88 88
    * @see Producer#produce(Any, ExchangePattern)
89 89
    */
90 90
   protected def produce: Receive = {
91  
-    case res: MessageResult ⇒ receiveAfterProduce(res.message)
92  
-    case res: FailureResult ⇒ receiveAfterProduce(res.failure)
  91
+    case res: MessageResult ⇒ routeResponse(res.message)
  92
+    case res: FailureResult ⇒ routeResponse(res.failure)
93 93
     case msg ⇒ {
94 94
       if (oneway)
95  
-        produce(receiveBeforeProduce(msg), ExchangePattern.InOnly)
  95
+        produce(transformOutgoingMessage(msg), ExchangePattern.InOnly)
96 96
       else
97  
-        produce(receiveBeforeProduce(msg), ExchangePattern.InOut)
  97
+        produce(transformOutgoingMessage(msg), ExchangePattern.InOut)
98 98
     }
99 99
   }
100 100
 
@@ -103,9 +103,14 @@ trait ProducerSupport { this: Actor ⇒
103 103
    * message is passed as argument. By default, this method simply returns the argument but may be overridden
104 104
    * by subtraits or subclasses.
105 105
    */
106  
-  protected def receiveBeforeProduce: PartialFunction[Any, Any] = {
107  
-    case msg ⇒ msg
108  
-  }
  106
+  protected def transformOutgoingMessage(msg: Any): Any = msg
  107
+
  108
+  /**
  109
+   * Called before the response message is sent to the original sender. The original
  110
+   * message is passed as argument. By default, this method simply returns the argument but may be overridden
  111
+   * by subtraits or subclasses.
  112
+   */
  113
+  protected def transformResponse(msg: Any): Any = msg
109 114
 
110 115
   /**
111 116
    * Called after a response was received from the endpoint specified by <code>endpointUri</code>. The
@@ -114,8 +119,9 @@ trait ProducerSupport { this: Actor ⇒
114 119
    * done. This method may be overridden by subtraits or subclasses (e.g. to forward responses to another
115 120
    * actor).
116 121
    */
117  
-  protected def receiveAfterProduce: Receive = {
118  
-    case msg ⇒ if (!oneway) sender ! msg
  122
+
  123
+  protected def routeResponse(msg: Any) {
  124
+    if (!oneway) sender ! transformResponse(msg)
119 125
   }
120 126
 
121 127
 }
21  akka-camel/src/main/scala/akka/camel/javaapi/UntypedProducerActor.scala
@@ -19,7 +19,14 @@ abstract class UntypedProducerActor extends UntypedActor with ProducerSupport {
19 19
    * message is passed as argument. By default, this method simply returns the argument but may be overridden
20 20
    * by subclasses.
21 21
    */
22  
-  def onReceiveBeforeProduce(message: AnyRef): AnyRef = message
  22
+  def onTransformOutgoingMessage(message: AnyRef): AnyRef = message
  23
+
  24
+  /**
  25
+   * Called before the response message is sent to original sender. The original
  26
+   * message is passed as argument. By default, this method simply returns the argument but may be overridden
  27
+   * by subclasses.
  28
+   */
  29
+  def onTransformResponse(message: AnyRef): AnyRef = message
23 30
 
24 31
   /**
25 32
    * Called after a response was received from the endpoint specified by <code>endpointUri</code>. The
@@ -27,15 +34,11 @@ abstract class UntypedProducerActor extends UntypedActor with ProducerSupport {
27 34
    * if <code>oneway</code> is <code>false</code>. If <code>oneway</code> is <code>true</code>, nothing is
28 35
    * done. This method may be overridden by subclasses (e.g. to forward responses to another actor).
29 36
    */
30  
-  def onReceiveAfterProduce(message: AnyRef): Unit = super.receiveAfterProduce(message)
31  
-
32  
-  final override def receiveBeforeProduce = {
33  
-    case msg: AnyRef ⇒ onReceiveBeforeProduce(msg)
34  
-  }
  37
+  def onRouteResponse(message: AnyRef): Unit = super.routeResponse(message)
35 38
 
36  
-  final override def receiveAfterProduce = {
37  
-    case msg: AnyRef ⇒ onReceiveAfterProduce(msg)
38  
-  }
  39
+  final override def transformOutgoingMessage(msg: Any): AnyRef = onTransformOutgoingMessage(msg.asInstanceOf[AnyRef])
  40
+  final override def transformResponse(msg: Any): AnyRef = onTransformResponse(msg.asInstanceOf[AnyRef])
  41
+  final override def routeResponse(msg: Any): Any = onRouteResponse(msg.asInstanceOf[AnyRef])
39 42
 
40 43
   final override def endpointUri = getEndpointUri
41 44
 
2  akka-camel/src/test/java/akka/camel/SampleUntypedForwardingProducer.java
@@ -15,7 +15,7 @@ public String getEndpointUri() {
15 15
     }
16 16
 
17 17
     @Override
18  
-    public void onReceiveAfterProduce(Object message) {
  18
+    public void onRouteResponse(Object message) {
19 19
         CamelMessage msg = (CamelMessage)message;
20 20
         String body = msg.getBodyAs(String.class,getCamelContext());
21 21
         getProducerTemplate().sendBody("direct:forward-test-1", body);
6  akka-camel/src/test/scala/akka/camel/ProducerFeatureTest.scala
@@ -266,7 +266,7 @@ object ProducerFeatureTest {
266 266
   class TestProducer(uri: String, upper: Boolean = false) extends Actor with Producer {
267 267
     def endpointUri = uri
268 268
 
269  
-    override protected def receiveBeforeProduce = {
  269
+    override protected def transformOutgoingMessage(msg: Any) = msg match {
270 270
       case msg: CamelMessage ⇒ if (upper) msg.mapBody {
271 271
         body: String ⇒ body.toUpperCase
272 272
       }
@@ -277,9 +277,7 @@ object ProducerFeatureTest {
277 277
   class TestForwarder(uri: String, target: ActorRef) extends Actor with Producer {
278 278
     def endpointUri = uri
279 279
 
280  
-    override protected def receiveAfterProduce = {
281  
-      case msg ⇒ target forward msg
282  
-    }
  280
+    override protected def routeResponse(msg: Any): Any = { target forward msg }
283 281
   }
284 282
 
285 283
   class TestResponder extends Actor {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.