/** Return the protocol for a Java interface. */ public Protocol getProtocol(Class iface) { try { Protocol p = (Protocol)(iface.getDeclaredField("PROTOCOL").get(null)); if (!p.getNamespace().equals(iface.getPackage().getName())) // HACK: protocol mismatches iface. maven shade plugin? try replacing. p = Protocol.parse(p.toString().replace(p.getNamespace(), iface.getPackage().getName())); return p; } catch (NoSuchFieldException e) { throw new AvroRuntimeException("Not a Specific protocol: "+iface); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
/** Return the protocol for a Java interface. */ public Protocol getProtocol(Class iface) { try { Protocol p = (Protocol)(iface.getDeclaredField("PROTOCOL").get(null)); if (!p.getNamespace().equals(iface.getPackage().getName())) // HACK: protocol mismatches iface. maven shade plugin? try replacing. p = Protocol.parse(p.toString().replace(p.getNamespace(), iface.getPackage().getName())); return p; } catch (NoSuchFieldException e) { throw new AvroRuntimeException("Not a Specific protocol: "+iface); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
/** * Provides a a unique gRPC service name for Avro RPC interface or its subclass Callback * Interface. * * @param iface Avro RPC interface. * @return unique service name for gRPC. */ public static String getServiceName(Class iface) { Protocol protocol = getProtocol(iface); return protocol.getNamespace() + "." + protocol.getName(); }
/** * Constructs a similar Protocol instance with the same {@code name}, {@code doc}, and {@code namespace} as {code p} * has. It also copies all the {@code props}. */ public Protocol(Protocol p) { this(p.getName(), p.getDoc(), p.getNamespace()); putAll(p); }
OutputFile compileInterface(Protocol protocol) { protocol = addStringType(protocol); // annotate protocol as needed VelocityContext context = new VelocityContext(); context.put("protocol", protocol); context.put("this", this); String out = renderTemplate(templateDir+"protocol.vm", context); OutputFile outputFile = new OutputFile(); String mangledName = mangle(protocol.getName()); outputFile.path = makePath(mangledName, protocol.getNamespace()); outputFile.contents = out; outputFile.outputCharacterEncoding = outputCharacterEncoding; return outputFile; }
private Protocol addStringType(Protocol p) { if (stringType != StringType.String) return p; Protocol newP = new Protocol(p.getName(), p.getDoc(), p.getNamespace()); Map<Schema,Schema> types = new LinkedHashMap<>(); for (Map.Entry<String, Object> a : p.getObjectProps().entrySet()) { newP.addProp(a.getKey(), a.getValue()); } // annotate types Collection<Schema> namedTypes = new LinkedHashSet<>(); for (Schema s : p.getTypes()) namedTypes.add(addStringType(s, types)); newP.setTypes(namedTypes); // annotate messages Map<String,Message> newM = newP.getMessages(); for (Message m : p.getMessages().values()) newM.put(m.getName(), m.isOneWay() ? newP.createMessage(m, addStringType(m.getRequest(), types)) : newP.createMessage(m, addStringType(m.getRequest(), types), addStringType(m.getResponse(), types), addStringType(m.getErrors(), types))); return newP; }
Protocol result = new Protocol(protocol.getName(), protocol.getDoc(), protocol.getNamespace()); final Collection<Schema> types = protocol.getTypes();
/** Return the protocol for a Java interface. */ public Protocol getProtocol(Class iface) { try { Protocol p = (Protocol)(iface.getDeclaredField("PROTOCOL").get(null)); if (!p.getNamespace().equals(iface.getPackage().getName())) // HACK: protocol mismatches iface. maven shade plugin? try replacing. p = Protocol.parse(p.toString().replace(p.getNamespace(), iface.getPackage().getName())); return p; } catch (NoSuchFieldException e) { throw new AvroRuntimeException("Not a Specific protocol: "+iface); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
/** Return the protocol for a Java interface. */ public Protocol getProtocol(Class iface) { try { Protocol p = (Protocol)(iface.getDeclaredField("PROTOCOL").get(null)); if (!p.getNamespace().equals(iface.getPackage().getName())) // HACK: protocol mismatches iface. maven shade plugin? try replacing. p = Protocol.parse(p.toString().replace(p.getNamespace(), iface.getPackage().getName())); return p; } catch (NoSuchFieldException e) { throw new AvroRuntimeException("Not a Specific protocol: "+iface); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
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; }