Author: cutting
Date: Tue Jan 5 18:55:19 2010
New Revision: 896178
URL: http://svn.apache.org/viewvc?rev=896178&view=rev
Log:
Add a Java local RPC transceiver. Contributed by Philip Zeyliger.
Added:
hadoop/avro/trunk/src/java/org/apache/avro/ipc/LocalTransceiver.java
hadoop/avro/trunk/src/test/java/org/apache/avro/ipc/
hadoop/avro/trunk/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
Modified:
hadoop/avro/trunk/CHANGES.txt
Modified: hadoop/avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=896178&r1=896177&r2=896178&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Jan 5 18:55:19 2010
@@ -48,6 +48,8 @@
AVRO-267. Add two new avroj commands: rpcsend and rpcreceive.
(Philip Zeyliger via cutting)
+ AVRO-271. Add a Java local RPC transceiver. (Philip Zeyliger via cutting)
+
IMPROVEMENTS
AVRO-157. Changes from code review comments for C++. (sbanacho)
Added: hadoop/avro/trunk/src/java/org/apache/avro/ipc/LocalTransceiver.java
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/ipc/LocalTransceiver.java?rev=896178&view=auto
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/ipc/LocalTransceiver.java (added)
+++ hadoop/avro/trunk/src/java/org/apache/avro/ipc/LocalTransceiver.java Tue
Jan 5 18:55:19 2010
@@ -0,0 +1,52 @@
+/**
+ * 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.avro.ipc;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+/** Implementation of IPC that remains in process. */
+public class LocalTransceiver extends Transceiver {
+ private Responder responder;
+
+ public LocalTransceiver(Responder responder) {
+ this.responder = responder;
+ }
+
+ @Override
+ public String getRemoteName() {
+ return "local";
+ }
+
+ @Override
+ public List<ByteBuffer> transceive(List<ByteBuffer> request)
+ throws IOException {
+ return responder.respond(request);
+ }
+
+ @Override
+ public List<ByteBuffer> readBuffers() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void writeBuffers(List<ByteBuffer> buffers) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
hadoop/avro/trunk/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java?rev=896178&view=auto
==============================================================================
---
hadoop/avro/trunk/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
(added)
+++
hadoop/avro/trunk/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
Tue Jan 5 18:55:19 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.avro.ipc;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.avro.Protocol;
+import org.apache.avro.Protocol.Message;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.GenericRequestor;
+import org.apache.avro.generic.GenericResponder;
+import org.apache.avro.util.Utf8;
+import org.junit.Test;
+
+public class TestLocalTransceiver {
+
+ Protocol protocol = Protocol.parse("" + "{\"protocol\": \"Minimal\", "
+ + "\"messages\": { \"m\": {"
+ + " \"request\": [{\"name\": \"x\", \"type\": \"string\"}], "
+ + " \"response\": \"string\"} } }");
+
+ static class TestResponder extends GenericResponder {
+ public TestResponder(Protocol local) {
+ super(local);
+ }
+
+ @Override
+ public Object respond(Message message, Object request)
+ throws AvroRemoteException {
+ assertEquals(new Utf8("hello"), ((GenericRecord) request).get("x"));
+ return new Utf8("there");
+ }
+
+ }
+
+ @Test
+ public void testSingleRpc() throws IOException {
+ Transceiver t = new LocalTransceiver(new TestResponder(protocol));
+ GenericRecord params = new GenericData.Record(protocol.getMessages().get(
+ "m").getRequest());
+ params.put("x", new Utf8("hello"));
+ GenericRequestor r = new GenericRequestor(protocol, t);
+ assertEquals(new Utf8("there"), r.request("m", params));
+ }
+
+}