if (value.isOneWay()) { Schema replacement = resolve(replacements, value.getRequest(), protocol); nvalue = result.createMessage(value.getName(), value.getDoc(), value, replacement); } else { Schema response = resolve(replacements, value.getResponse(), protocol); Schema errors = resolve(replacements, value.getErrors(), protocol); nvalue = result.createMessage(value.getName(), value.getDoc(), value, request, response, errors);
@Test public void testParsing() throws IOException { Protocol protocol = getSimpleProtocol(); assertEquals(protocol.getDoc(), "Protocol used for testing."); assertEquals(6, protocol.getMessages().size()); assertEquals("Pretend you're in a cave!", protocol.getMessages().get("echo").getDoc()); }
private OutputFile compileInterface(Protocol protocol) { OutputFile outputFile = new OutputFile(); String mangledName = mangle(protocol.getName()); outputFile.path = makePath(mangledName, protocol.getNamespace()); StringBuilder out = new StringBuilder(); header(out, protocol.getNamespace()); doc(out, 1, protocol.getDoc()); line(out, 0, "public interface " + mangledName + " {"); line(out, 1, "public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse(\"" +esc(protocol)+"\");"); for (Map.Entry<String,Message> e : protocol.getMessages().entrySet()) { String name = e.getKey(); Message message = e.getValue(); Schema request = message.getRequest(); Schema response = message.getResponse(); doc(out, 1, e.getValue().getDoc()); line(out, 1, unbox(response)+" "+ mangle(name)+"("+params(request)+")"); line(out, 2,"throws org.apache.avro.ipc.AvroRemoteException"+errors(message.getErrors())+";"); } line(out, 0, "}"); outputFile.contents = out.toString(); return outputFile; }
private OutputFile compileInterface(Protocol protocol) { OutputFile outputFile = new OutputFile(); String mangledName = mangle(protocol.getName()); outputFile.path = makePath(mangledName, protocol.getNamespace()); StringBuilder out = new StringBuilder(); header(out, protocol.getNamespace()); doc(out, 1, protocol.getDoc()); line(out, 0, "public interface " + mangledName + " {"); line(out, 1, "public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse(\"" +esc(protocol)+"\");"); for (Map.Entry<String,Message> e : protocol.getMessages().entrySet()) { String name = e.getKey(); Message message = e.getValue(); Schema request = message.getRequest(); String response = message.isOneWay() ? "void" : unbox(message.getResponse()); doc(out, 1, e.getValue().getDoc()); line(out, 1, response+" "+ mangle(name)+"("+params(request)+")" + (message.isOneWay() ? "" : (" throws org.apache.avro.ipc.AvroRemoteException" +errors(message.getErrors()))) +";"); } line(out, 0, "}"); outputFile.contents = out.toString(); return outputFile; }
/** Create a two-way message using the {@code name}, {@code doc}, and {@code props} of {@code m}. */ public Message createMessage(Message m, Schema request, Schema response, Schema errors) { return new TwoWayMessage(m.getName(), m.getDoc(), m, request, response, errors); }