Return-Path: X-Original-To: apmail-ode-commits-archive@www.apache.org Delivered-To: apmail-ode-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C5265FD31 for ; Tue, 13 Aug 2013 14:00:14 +0000 (UTC) Received: (qmail 85131 invoked by uid 500); 13 Aug 2013 14:00:14 -0000 Delivered-To: apmail-ode-commits-archive@ode.apache.org Received: (qmail 85049 invoked by uid 500); 13 Aug 2013 14:00:12 -0000 Mailing-List: contact commits-help@ode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ode.apache.org Delivered-To: mailing list commits@ode.apache.org Received: (qmail 84692 invoked by uid 99); 13 Aug 2013 14:00:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Aug 2013 14:00:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 932C38BDA10; Tue, 13 Aug 2013 14:00:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vanto@apache.org To: commits@ode.apache.org Date: Tue, 13 Aug 2013 14:00:08 -0000 Message-Id: <1cc54436c91446c198189d6e67baa6d4@git.apache.org> In-Reply-To: <0d3401767b664236b0c4cb78296ae287@git.apache.org> References: <0d3401767b664236b0c4cb78296ae287@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/6] git commit: Incremental refactoring of Continuation to have it replaced eventually by Message Incremental refactoring of Continuation to have it replaced eventually by Message Project: http://git-wip-us.apache.org/repos/asf/ode-jacob/repo Commit: http://git-wip-us.apache.org/repos/asf/ode-jacob/commit/e27490ac Tree: http://git-wip-us.apache.org/repos/asf/ode-jacob/tree/e27490ac Diff: http://git-wip-us.apache.org/repos/asf/ode-jacob/diff/e27490ac Branch: refs/heads/master Commit: e27490ac887bd77f5986795475327f3fb33c5e43 Parents: ba74ea2 Author: Hadrian Zbarcea Authored: Mon Aug 5 20:18:06 2013 -0400 Committer: Hadrian Zbarcea Committed: Mon Aug 5 20:18:06 2013 -0400 ---------------------------------------------------------------------- .../org/apache/ode/jacob/soup/CommRecv.java | 12 +-- .../org/apache/ode/jacob/soup/Continuation.java | 3 - .../soup/jackson/ContinuationDeserializer.java | 86 -------------------- .../soup/jackson/ContinuationSerializer.java | 71 ---------------- .../ode/jacob/soup/jackson/JacobModule.java | 4 +- .../jacob/soup/jackson/MessageDeserializer.java | 86 ++++++++++++++++++++ .../jacob/soup/jackson/MessageSerializer.java | 71 ++++++++++++++++ .../ode/jacob/vpu/ExecutionQueueImpl.java | 2 +- 8 files changed, 166 insertions(+), 169 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/soup/CommRecv.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/soup/CommRecv.java b/src/main/java/org/apache/ode/jacob/soup/CommRecv.java index c8b5ac7..830f376 100644 --- a/src/main/java/org/apache/ode/jacob/soup/CommRecv.java +++ b/src/main/java/org/apache/ode/jacob/soup/CommRecv.java @@ -29,14 +29,14 @@ import org.apache.ode.jacob.oo.ChannelListener; * replicated variety. */ public class CommRecv extends Comm { - private ChannelListener _continuation; + private ChannelListener listener; protected CommRecv() { } - public CommRecv(CommChannel chnl, ChannelListener continuation) { + public CommRecv(CommChannel chnl, ChannelListener listener) { super(null, chnl); - _continuation = continuation; + this.listener = listener; } /** @@ -48,13 +48,13 @@ public class CommRecv extends Comm { * * @return byte array representing the serialized form of the continuation */ - public ChannelListener getContinuation() { - return _continuation; + public ChannelListener getListener() { + return listener; } public String toString() { StringBuffer buf = new StringBuffer(getChannel().toString()); - buf.append(" ? ").append(_continuation.toString()); + buf.append(" ? ").append(listener.toString()); return buf.toString(); } } http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/soup/Continuation.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/soup/Continuation.java b/src/main/java/org/apache/ode/jacob/soup/Continuation.java index eca46fb..b325b78 100644 --- a/src/main/java/org/apache/ode/jacob/soup/Continuation.java +++ b/src/main/java/org/apache/ode/jacob/soup/Continuation.java @@ -32,10 +32,8 @@ import org.apache.ode.jacob.oo.ClassUtil; */ public class Continuation extends ExecutionQueueObject { private final Message message; - private JacobObject closure; public Continuation(JacobObject target, String action, Object[] args, Channel replyTo) { - closure = target; message = ClassUtil.createMessage(target, action, args, replyTo); } @@ -46,7 +44,6 @@ public class Continuation extends ExecutionQueueObject { public String toString () { return new StringBuilder("{") .append(this.getClass().getSimpleName()) - .append(" closure=").append(closure) .append(", method=").append(message.getAction()) .append("}").toString(); } http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationDeserializer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationDeserializer.java b/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationDeserializer.java deleted file mode 100644 index 684c5fa..0000000 --- a/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationDeserializer.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.ode.jacob.soup.jackson; - -import java.io.IOException; - -import org.apache.ode.jacob.JacobObject; -import org.apache.ode.jacob.oo.Channel; -import org.apache.ode.jacob.soup.Continuation; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; - -/** - * Jackson deserializer for Continuation objects. - * - * @author Tammo van Lessen - * - */ -public class ContinuationDeserializer extends StdDeserializer { - - private static final long serialVersionUID = 1L; - - protected ContinuationDeserializer() { - super(Continuation.class); - } - - @Override - public Continuation deserialize(JsonParser jp, - DeserializationContext ctxt) throws IOException, - JsonProcessingException { - - JacobObject target = null; - String action = null; - Object[] args = null; - Channel replyTo = null; - - while (jp.nextToken() != JsonToken.END_OBJECT) { - String fieldname = jp.getCurrentName(); - if (jp.getCurrentToken() == JsonToken.FIELD_NAME) { - // if we're not already on the field, advance by one. - jp.nextToken(); - } - - if ("target".equals(fieldname)) { - target = jp.readValueAs(JacobObject.class); - } else if ("method".equals(fieldname)) { - action = jp.getText(); - } else if ("args".equals(fieldname)) { - args = jp.readValueAs(Object[].class); - } else if ("replyTo".equals(fieldname)) { - replyTo = jp.readValueAs(Channel.class); - } - } - - if (target == null) { - throw ctxt.mappingException(Continuation.class); - } - - if (action == null) { - throw ctxt.mappingException(Continuation.class); - } - - // TODO: pass the replyTo channel to the Continuation - return new Continuation(target, action, args, replyTo); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationSerializer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationSerializer.java b/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationSerializer.java deleted file mode 100644 index 456a40d..0000000 --- a/src/main/java/org/apache/ode/jacob/soup/jackson/ContinuationSerializer.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.ode.jacob.soup.jackson; - -import java.io.IOException; - -import org.apache.ode.jacob.oo.ClassUtil; -import org.apache.ode.jacob.soup.Continuation; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; - -/** - * Jackson serializer for Continuation objects. - * - * @author Tammo van Lessen - * - */ -public class ContinuationSerializer extends StdSerializer { - - public ContinuationSerializer() { - super(Continuation.class); - } - - @Override - public void serialize(Continuation value, JsonGenerator jgen, - SerializerProvider provider) throws IOException, - JsonGenerationException { - jgen.writeStartObject(); - serializeContents(value, jgen, provider); - jgen.writeEndObject(); - } - - - @Override - public void serializeWithType(Continuation value, JsonGenerator jgen, - SerializerProvider provider, TypeSerializer typeSer) - throws IOException, JsonProcessingException { - typeSer.writeTypePrefixForObject(value, jgen); - serializeContents(value, jgen, provider); - typeSer.writeTypeSuffixForObject(value, jgen); - } - - private void serializeContents(Continuation value, JsonGenerator jgen, - SerializerProvider provider) throws JsonGenerationException, IOException { - - jgen.writeObjectField("target", ClassUtil.getMessageClosure(value.getMessage())); - jgen.writeStringField("method", value.getMessage().getAction()); - jgen.writeObjectField("args", value.getMessage().getBody()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/soup/jackson/JacobModule.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/soup/jackson/JacobModule.java b/src/main/java/org/apache/ode/jacob/soup/jackson/JacobModule.java index 8ddf203..f42b4fe 100644 --- a/src/main/java/org/apache/ode/jacob/soup/jackson/JacobModule.java +++ b/src/main/java/org/apache/ode/jacob/soup/jackson/JacobModule.java @@ -47,10 +47,10 @@ public class JacobModule extends SimpleModule { final ChannelProxySerializer cps = new ChannelProxySerializer(); addSerializer(ChannelProxy.class, cps); - addSerializer(Continuation.class, new ContinuationSerializer()); + addSerializer(Continuation.class, new MessageSerializer()); addSerializer(JacksonExecutionQueueImpl.class, new ExecutionQueueImplSerializer(cps)); addDeserializer(JacksonExecutionQueueImpl.class, new ExecutionQueueImplDeserializer()); - addDeserializer(Continuation.class, new ContinuationDeserializer()); + addDeserializer(Continuation.class, new MessageDeserializer()); addDeserializer(Channel.class, new ChannelProxyDeserializer()); setDeserializerModifier(new BeanDeserializerModifier() { http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/soup/jackson/MessageDeserializer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/soup/jackson/MessageDeserializer.java b/src/main/java/org/apache/ode/jacob/soup/jackson/MessageDeserializer.java new file mode 100644 index 0000000..28e71c1 --- /dev/null +++ b/src/main/java/org/apache/ode/jacob/soup/jackson/MessageDeserializer.java @@ -0,0 +1,86 @@ +/* + * 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.ode.jacob.soup.jackson; + +import java.io.IOException; + +import org.apache.ode.jacob.JacobObject; +import org.apache.ode.jacob.oo.Channel; +import org.apache.ode.jacob.soup.Continuation; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +/** + * Jackson deserializer for Continuation objects. + * + * @author Tammo van Lessen + * + */ +public class MessageDeserializer extends StdDeserializer { + + private static final long serialVersionUID = 1L; + + protected MessageDeserializer() { + super(Continuation.class); + } + + @Override + public Continuation deserialize(JsonParser jp, + DeserializationContext ctxt) throws IOException, + JsonProcessingException { + + JacobObject target = null; + String action = null; + Object[] args = null; + Channel replyTo = null; + + while (jp.nextToken() != JsonToken.END_OBJECT) { + String fieldname = jp.getCurrentName(); + if (jp.getCurrentToken() == JsonToken.FIELD_NAME) { + // if we're not already on the field, advance by one. + jp.nextToken(); + } + + if ("target".equals(fieldname)) { + target = jp.readValueAs(JacobObject.class); + } else if ("method".equals(fieldname)) { + action = jp.getText(); + } else if ("args".equals(fieldname)) { + args = jp.readValueAs(Object[].class); + } else if ("replyTo".equals(fieldname)) { + replyTo = jp.readValueAs(Channel.class); + } + } + + if (target == null) { + throw ctxt.mappingException(Continuation.class); + } + + if (action == null) { + throw ctxt.mappingException(Continuation.class); + } + + // TODO: pass the replyTo channel to the Continuation + return new Continuation(target, action, args, replyTo); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/soup/jackson/MessageSerializer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/soup/jackson/MessageSerializer.java b/src/main/java/org/apache/ode/jacob/soup/jackson/MessageSerializer.java new file mode 100644 index 0000000..81525c8 --- /dev/null +++ b/src/main/java/org/apache/ode/jacob/soup/jackson/MessageSerializer.java @@ -0,0 +1,71 @@ +/* + * 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.ode.jacob.soup.jackson; + +import java.io.IOException; + +import org.apache.ode.jacob.oo.ClassUtil; +import org.apache.ode.jacob.soup.Continuation; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +/** + * Jackson serializer for Continuation objects. + * + * @author Tammo van Lessen + * + */ +public class MessageSerializer extends StdSerializer { + + public MessageSerializer() { + super(Continuation.class); + } + + @Override + public void serialize(Continuation value, JsonGenerator jgen, + SerializerProvider provider) throws IOException, + JsonGenerationException { + jgen.writeStartObject(); + serializeContents(value, jgen, provider); + jgen.writeEndObject(); + } + + + @Override + public void serializeWithType(Continuation value, JsonGenerator jgen, + SerializerProvider provider, TypeSerializer typeSer) + throws IOException, JsonProcessingException { + typeSer.writeTypePrefixForObject(value, jgen); + serializeContents(value, jgen, provider); + typeSer.writeTypeSuffixForObject(value, jgen); + } + + private void serializeContents(Continuation value, JsonGenerator jgen, + SerializerProvider provider) throws JsonGenerationException, IOException { + + jgen.writeObjectField("target", ClassUtil.getMessageClosure(value.getMessage())); + jgen.writeStringField("method", value.getMessage().getAction()); + jgen.writeObjectField("args", value.getMessage().getBody()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/e27490ac/src/main/java/org/apache/ode/jacob/vpu/ExecutionQueueImpl.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/vpu/ExecutionQueueImpl.java b/src/main/java/org/apache/ode/jacob/vpu/ExecutionQueueImpl.java index 7240377..80a2e82 100644 --- a/src/main/java/org/apache/ode/jacob/vpu/ExecutionQueueImpl.java +++ b/src/main/java/org/apache/ode/jacob/vpu/ExecutionQueueImpl.java @@ -176,7 +176,7 @@ public class ExecutionQueueImpl implements ExecutionQueue { if (group.isReplicated()) chnlFrame.replicatedRecv = true; CommRecv commRecv = (CommRecv) comm; - ObjectFrame oframe = new ObjectFrame(commGroupFrame, chnlFrame, commRecv.getContinuation()); + ObjectFrame oframe = new ObjectFrame(commGroupFrame, chnlFrame, commRecv.getListener()); commGroupFrame.commFrames.add(oframe); chnlFrame.objFrames.add(oframe); }