ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject [1/3] git commit: ChannelRef now supports three kinds of endpoints: - CHANNEL (which is an identifyable abstract endpoint), - MESSAGE_LISTENER (which is a concrete message listener implementation), and - JACOB_OBJECT (which is an OO implementation.
Date Thu, 15 Aug 2013 14:35:26 GMT
Updated Branches:
  refs/heads/master 32d230509 -> 212b3ce36


ChannelRef now supports three kinds of endpoints:
 - CHANNEL (which is an identifyable abstract endpoint),
 - MESSAGE_LISTENER (which is a concrete message listener implementation), and
 - JACOB_OBJECT (which is an OO implementation.


Project: http://git-wip-us.apache.org/repos/asf/ode-jacob/repo
Commit: http://git-wip-us.apache.org/repos/asf/ode-jacob/commit/20523412
Tree: http://git-wip-us.apache.org/repos/asf/ode-jacob/tree/20523412
Diff: http://git-wip-us.apache.org/repos/asf/ode-jacob/diff/20523412

Branch: refs/heads/master
Commit: 205234127516ff434afda7159850bf7c4730898e
Parents: 32d2305
Author: Tammo van Lessen <vanto@apache.org>
Authored: Thu Aug 15 16:31:38 2013 +0200
Committer: Tammo van Lessen <vanto@apache.org>
Committed: Thu Aug 15 16:31:38 2013 +0200

----------------------------------------------------------------------
 .../java/org/apache/ode/jacob/ChannelRef.java   | 16 ++++++++++++--
 .../soup/jackson/ChannelRefSerializer.java      | 11 ++++++++--
 .../java/org/apache/ode/jacob/vpu/JacobVPU.java | 23 +++++++++++++++-----
 3 files changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/20523412/src/main/java/org/apache/ode/jacob/ChannelRef.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/ode/jacob/ChannelRef.java b/src/main/java/org/apache/ode/jacob/ChannelRef.java
index d741b47..70b6a1f 100644
--- a/src/main/java/org/apache/ode/jacob/ChannelRef.java
+++ b/src/main/java/org/apache/ode/jacob/ChannelRef.java
@@ -29,7 +29,7 @@ import org.apache.ode.jacob.soup.CommChannel;
  */
 
 public class ChannelRef implements Serializable {
-    public enum Type { JACOB_OBJECT, CHANNEL }
+    public enum Type { JACOB_OBJECT, CHANNEL, MESSAGE_LISTENER }
     
     private static final long serialVersionUID = 1L;
 
@@ -37,7 +37,17 @@ public class ChannelRef implements Serializable {
     private final Object target;
     
     public ChannelRef(Object target) {
-        type = target instanceof CommChannel ? Type.CHANNEL : Type.JACOB_OBJECT;
+        assert target != null;
+        if (target instanceof CommChannel) {
+            type = Type.CHANNEL;
+        } else if (target instanceof JacobObject) {
+            type = Type.JACOB_OBJECT;
+        } else if (target instanceof MessageListener) {
+            type = Type.MESSAGE_LISTENER;
+        } else {
+            throw new IllegalArgumentException("Unsupported endpoint reference");
+        }
+        
         this.target = target;
     }
     
@@ -51,6 +61,8 @@ public class ChannelRef implements Serializable {
             return (T)target;
         } else if (type.equals(Type.CHANNEL) && CommChannel.class.isAssignableFrom(clazz))
{
             return (T)target;
+        } else if (type.equals(Type.MESSAGE_LISTENER) && MessageListener.class.isAssignableFrom(clazz))
{
+            return (T)target;
         }
         
         return null;

http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/20523412/src/main/java/org/apache/ode/jacob/soup/jackson/ChannelRefSerializer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/ode/jacob/soup/jackson/ChannelRefSerializer.java b/src/main/java/org/apache/ode/jacob/soup/jackson/ChannelRefSerializer.java
index c50bb00..4e226f1 100644
--- a/src/main/java/org/apache/ode/jacob/soup/jackson/ChannelRefSerializer.java
+++ b/src/main/java/org/apache/ode/jacob/soup/jackson/ChannelRefSerializer.java
@@ -19,6 +19,7 @@
 package org.apache.ode.jacob.soup.jackson;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
 
 import org.apache.ode.jacob.ChannelRef;
 import org.apache.ode.jacob.JacobObject;
@@ -66,7 +67,13 @@ public class ChannelRefSerializer extends StdSerializer<ChannelRef>
{
     private void serializeContents(ChannelRef value, JsonGenerator jgen,
             SerializerProvider provider) throws JsonGenerationException, IOException {
         
-        jgen.writeObjectField("target", value.getEndpoint(value.getType() == ChannelRef.Type.CHANNEL

-                ? CommChannel.class : JacobObject.class));
+        try {
+            Field targetField = ChannelRef.class.getDeclaredField("target");
+            targetField.setAccessible(true);
+            jgen.writeObjectField("target", targetField.get(value));
+            
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/20523412/src/main/java/org/apache/ode/jacob/vpu/JacobVPU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/ode/jacob/vpu/JacobVPU.java b/src/main/java/org/apache/ode/jacob/vpu/JacobVPU.java
index cf47558..b70e5ab 100644
--- a/src/main/java/org/apache/ode/jacob/vpu/JacobVPU.java
+++ b/src/main/java/org/apache/ode/jacob/vpu/JacobVPU.java
@@ -466,12 +466,23 @@ public final class JacobVPU {
 
             long ctime = System.currentTimeMillis();
             try {
-            	JacobObject target = message.getTo().getEndpoint(JacobObject.class);
-            	if (target instanceof ReceiveProcess) {
-            		((ReceiveProcess)target).onMessage(message);
-            	} else {
-            		((Runnable)target).run();
-            	}
+                switch (message.getTo().getType()) {
+                    case CHANNEL:
+                        throw new UnsupportedOperationException();
+                    case JACOB_OBJECT:
+                        JacobObject target = message.getTo().getEndpoint(JacobObject.class);
+                        if (target instanceof ReceiveProcess) {
+                            ((ReceiveProcess)target).onMessage(message);
+                        } else {
+                            ((Runnable)target).run();
+                        }
+                        break;
+                    case MESSAGE_LISTENER:
+                        MessageListener ml = message.getTo().getEndpoint(MessageListener.class);
+                        ml.onMessage(message);
+                        break;
+                }
+                
                 if (replyTo != null) {
                     sendMessage(ClassUtil.createMessage(replyTo, ClassUtil.SYNCH_RET_METHOD_ACTION,
null, null));
                 }


Mime
View raw message