org.apache.avro.Protocol.setTypes()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中org.apache.avro.Protocol.setTypes()方法的一些代码示例,展示了Protocol.setTypes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Protocol.setTypes()方法的具体详情如下:
包路径:org.apache.avro.Protocol
类名称:Protocol
方法名:setTypes

Protocol.setTypes介绍

[英]Set the types of this protocol.
[中]设置此协议的类型。

代码示例

代码示例来源:origin: apache/avro

/**
 * Return the protocol for a Java interface.
 * <p>The correct name of the method parameters needs the <code>-parameters</code>
 * java compiler argument. More info at https://openjdk.java.net/jeps/118
 */
@Override
public Protocol getProtocol(Class iface) {
 Protocol protocol =
  new Protocol(iface.getSimpleName(),
         iface.getPackage()==null?"":iface.getPackage().getName());
 Map<String,Schema> names = new LinkedHashMap<>();
 Map<String,Message> messages = protocol.getMessages();
 for (Method method : iface.getMethods())
  if ((method.getModifiers() & Modifier.STATIC) == 0) {
   String name = method.getName();
   if (messages.containsKey(name))
    throw new AvroTypeException("Two methods with same name: "+name);
   messages.put(name, getMessage(method, protocol, names));
  }
 // reverse types, since they were defined in reference order
 List<Schema> types = new ArrayList<>();
 types.addAll(names.values());
 Collections.reverse(types);
 protocol.setTypes(types);
 return protocol;
}

代码示例来源:origin: org.apache.avro/avro

/** Return the protocol for a Java interface.
 * <p>Note that this requires that <a
 * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled
 * interface declarations, since Java 6 reflection does not provide access to
 * method parameter names.  See Avro's build.xml for an example. */
@Override
public Protocol getProtocol(Class iface) {
 Protocol protocol =
  new Protocol(iface.getSimpleName(),
         iface.getPackage()==null?"":iface.getPackage().getName());
 Map<String,Schema> names = new LinkedHashMap<String,Schema>();
 Map<String,Message> messages = protocol.getMessages();
 for (Method method : iface.getMethods())
  if ((method.getModifiers() & Modifier.STATIC) == 0) {
   String name = method.getName();
   if (messages.containsKey(name))
    throw new AvroTypeException("Two methods with same name: "+name);
   messages.put(name, getMessage(method, protocol, names));
  }
 // reverse types, since they were defined in reference order
 List<Schema> types = new ArrayList<Schema>();
 types.addAll(names.values());
 Collections.reverse(types);
 protocol.setTypes(types);
 return protocol;
}

代码示例来源:origin: apache/avro

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;
}

代码示例来源:origin: apache/avro

newSchemas.add(Schemas.visit(schema, new ResolvingVisitor(schema, replacements, new SymbolTable(protocol))));
result.setTypes(newSchemas); // replace types with resolved ones

代码示例来源:origin: apache/avro

p.setTypes(names.values());

代码示例来源:origin: org.apache.hadoop/avro

/** Return the protocol for a Java interface.
 * <p>Note that this requires that <a
 * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled
 * interface declarations, since Java 6 reflection does not provide access to
 * method parameter names.  See Avro's build.xml for an example. */
@Override
public Protocol getProtocol(Class iface) {
 Protocol protocol =
  new Protocol(iface.getSimpleName(), iface.getPackage().getName()); 
 Map<String,Schema> names = new LinkedHashMap<String,Schema>();
 Map<String,Message> messages = protocol.getMessages();
 for (Method method : iface.getMethods())
  if ((method.getModifiers() & Modifier.STATIC) == 0) {
   String name = method.getName();
   if (messages.containsKey(name))
    throw new AvroTypeException("Two methods with same name: "+name);
   messages.put(name, getMessage(method, protocol, names));
  }
 // reverse types, since they were defined in reference order
 List<Schema> types = new ArrayList<Schema>();
 types.addAll(names.values());
 Collections.reverse(types);
 protocol.setTypes(types);
 return protocol;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.avro

/** Return the protocol for a Java interface.
 * <p>Note that this requires that <a
 * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled
 * interface declarations, since Java 6 reflection does not provide access to
 * method parameter names.  See Avro's build.xml for an example. */
@Override
public Protocol getProtocol(Class iface) {
 Protocol protocol =
  new Protocol(iface.getSimpleName(),
         iface.getPackage()==null?"":iface.getPackage().getName());
 Map<String,Schema> names = new LinkedHashMap<String,Schema>();
 Map<String,Message> messages = protocol.getMessages();
 for (Method method : iface.getMethods())
  if ((method.getModifiers() & Modifier.STATIC) == 0) {
   String name = method.getName();
   if (messages.containsKey(name))
    throw new AvroTypeException("Two methods with same name: "+name);
   messages.put(name, getMessage(method, protocol, names));
  }
 // reverse types, since they were defined in reference order
 List<Schema> types = new ArrayList<Schema>();
 types.addAll(names.values());
 Collections.reverse(types);
 protocol.setTypes(types);
 return protocol;
}

代码示例来源:origin: com.facebook.presto.hive/hive-apache

/** Return the protocol for a Java interface.
 * <p>Note that this requires that <a
 * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled
 * interface declarations, since Java 6 reflection does not provide access to
 * method parameter names.  See Avro's build.xml for an example. */
@Override
public Protocol getProtocol(Class iface) {
 Protocol protocol =
  new Protocol(iface.getSimpleName(),
         iface.getPackage()==null?"":iface.getPackage().getName());
 Map<String,Schema> names = new LinkedHashMap<String,Schema>();
 Map<String,Message> messages = protocol.getMessages();
 for (Method method : iface.getMethods())
  if ((method.getModifiers() & Modifier.STATIC) == 0) {
   String name = method.getName();
   if (messages.containsKey(name))
    throw new AvroTypeException("Two methods with same name: "+name);
   messages.put(name, getMessage(method, protocol, names));
  }
 // reverse types, since they were defined in reference order
 List<Schema> types = new ArrayList<Schema>();
 types.addAll(names.values());
 Collections.reverse(types);
 protocol.setTypes(types);
 return protocol;
}

代码示例来源:origin: org.apache.cassandra.deps/avro

/** Return the protocol for a Java interface.
 * <p>Note that this requires that <a
 * href="http://paranamer.codehaus.org/">Paranamer</a> is run over compiled
 * interface declarations, since Java 6 reflection does not provide access to
 * method parameter names.  See Avro's build.xml for an example. */
@Override
public Protocol getProtocol(Class iface) {
 Protocol protocol =
  new Protocol(iface.getSimpleName(),
         iface.getPackage()==null?"":iface.getPackage().getName());
 Map<String,Schema> names = new LinkedHashMap<String,Schema>();
 Map<String,Message> messages = protocol.getMessages();
 for (Method method : iface.getMethods())
  if ((method.getModifiers() & Modifier.STATIC) == 0) {
   String name = method.getName();
   if (messages.containsKey(name))
    throw new AvroTypeException("Two methods with same name: "+name);
   messages.put(name, getMessage(method, protocol, names));
  }
 // reverse types, since they were defined in reference order
 List<Schema> types = new ArrayList<Schema>();
 types.addAll(names.values());
 Collections.reverse(types);
 protocol.setTypes(types);
 return protocol;
}

代码示例来源:origin: zolyfarkas/spf4j

private void generateClasses(final GenericData.StringType st, final Schema... schemas) {
 String[] namespaces = new String[schemas.length];
 for (int i = 0; i < schemas.length; i++) {
  String namespace = schemas[i].getNamespace();
  if (namespace == null) {
   namespace = "";
  }
  namespaces[i] = namespace;
 }
 String commonPrefix = org.spf4j.base.Strings.commonPrefix(namespaces);
 if (commonPrefix.endsWith(".")) {
  commonPrefix = commonPrefix.substring(0, commonPrefix.length() - 1);
 }
 Protocol proto = new Protocol("generated", commonPrefix);
 proto.setTypes(Arrays.asList(schemas));
 SpecificCompiler sc = new SpecificCompiler(proto);
 sc.setStringType(st);
 // use a custom template that does not contain the builder (janino can't compile builder).
 sc.setTemplateDir("org/spf4j/avro/");
 try {
  sc.compileToDestination(null, tmpDir);
 } catch (IOException ex) {
  throw new UncheckedIOException(ex);
 }
 try {
  Files.walkFileTree(tmpDir.toPath(), new SetFilesReadOnlyVisitor());
 } catch (IOException ex) {
  throw new UncheckedIOException(ex);
 }
}

相关文章