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

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

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

Protocol.<init>介绍

[英]Constructs a similar Protocol instance with the same name, doc, and namespace as {code p} has. It also copies all the props.
[中]构造一个与{code p}具有相同名称、doc和命名空间的类似协议实例。它还复制了所有道具。

代码示例

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

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse((JsonNode)Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

代码示例来源: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: org.apache.avro/avro

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse(Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

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

final public Protocol ProtocolDeclaration() throws ParseException {
String name;
Protocol p;
Map<String, JsonNode> props = new LinkedHashMap<String, JsonNode>();
 label_2:
 while (true) {
  switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  case AT:
   ;
   break;
  default:
   jj_la1[4] = jj_gen;
   break label_2;
  }
  SchemaProperty(props);
 }
 if (props.containsKey("namespace"))
  namespace = getTextProp("namespace", props, token);
 jj_consume_token(PROTOCOL);
 name = Identifier();
 p = new Protocol(name, getDoc(), namespace);
 for (String key : props.keySet())
  if ("namespace".equals(key)) {               // already handled: ignore
  } else {                                     // add all other props
   Accessor.addProp(p, key, props.get(key));
  }
 ProtocolBody(p);
 {if (true) return p;}
 throw new Error("Missing return statement in function");
}

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

@Test public void testPropEquals() {
 Protocol p1 = new Protocol("P", null, "foo");
 p1.addProp("a","1");
 Protocol p2 = new Protocol("P", null, "foo");
 p2.addProp("a","2");
 assertFalse(p1.equals(p2));
}

代码示例来源: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

Protocol result = new Protocol(protocol.getName(), protocol.getDoc(), protocol.getNamespace());
final Collection<Schema> types = protocol.getTypes();

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

@Test
 public void testSplitProtocolBuild() {
  Protocol p = new Protocol("P", null, "foo");
  p.addProp("property", "some value");

  String protocolString = p.toString();
  final int mid = protocolString.length() / 2;
  String[] parts = {
   protocolString.substring(0, mid),
   protocolString.substring(mid),
  };

  Protocol parsedStringProtocol = org.apache.avro.Protocol.parse(protocolString);
  Protocol parsedArrayOfStringProtocol =
   org.apache.avro.Protocol.parse(protocolString.substring(0, mid),
                   protocolString.substring(mid));

  assertNotNull(parsedStringProtocol);
  assertNotNull(parsedArrayOfStringProtocol);
  assertEquals(parsedStringProtocol.toString(), parsedArrayOfStringProtocol.toString());
 }
}

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

/** Test that Responder ignores one-way with stateless transport. */
@Test public void testStatelessOneway() throws Exception {
 // a version of the Simple protocol that doesn't declare "ack" one-way
 Protocol protocol = new Protocol("Simple", "org.apache.avro.test");
 Protocol.Message message =
  protocol.createMessage("ack", null,
              Schema.createRecord(new ArrayList<>()),
              Schema.create(Schema.Type.NULL),
              Schema.createUnion(new ArrayList<>()));
 protocol.getMessages().put("ack", message);
 // call a server over a stateless protocol that has a one-way "ack"
 GenericRequestor requestor =
  new GenericRequestor(protocol, createTransceiver());
 requestor.request("ack", new GenericData.Record(message.getRequest()));
 // make the request again, to better test handshakes w/ differing protocols
 requestor.request("ack", new GenericData.Record(message.getRequest()));
}

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

@Test
/** Construct and use a protocol whose "hello" method has an extra
  argument to check that schema is sent to parse request. */
public void testParamVariation() throws Exception {
 Protocol protocol = new Protocol("Simple", "org.apache.avro.test");
 List<Schema.Field> fields = new ArrayList<>();
 fields.add(new Schema.Field("extra", Schema.create(Schema.Type.BOOLEAN),
         null, null));
 fields.add(new Schema.Field("greeting", Schema.create(Schema.Type.STRING),
         null, null));
 Protocol.Message message =
  protocol.createMessage("hello",
              null /* doc */,
              Schema.createRecord(fields),
              Schema.create(Schema.Type.STRING),
              Schema.createUnion(new ArrayList<>()));
 protocol.getMessages().put("hello", message);
 Transceiver t = createTransceiver();
 try {
  GenericRequestor r = new GenericRequestor(protocol, t);
  addRpcPlugins(r);
  GenericRecord params = new GenericData.Record(message.getRequest());
  params.put("extra", Boolean.TRUE);
  params.put("greeting", "bob");
  String response = r.request("hello", params).toString();
  assertEquals("goodbye", response);
 } finally {
  t.close();
 }
}

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

@Test
/** Construct and use a different protocol whose "hello" method has an extra
  argument to check that schema is sent to parse request. */
public void testHandshake() throws IOException {
 Protocol protocol = new Protocol("Simple", "org.apache.avro.test");
 List<Field> fields = new ArrayList<>();
 fields.add(new Schema.Field("extra", Schema.create(Schema.Type.BOOLEAN),
         null, null));
 fields.add(new Schema.Field("greeting", Schema.create(Schema.Type.STRING),
         null, null));
 Protocol.Message message =
  protocol.createMessage("hello",
              null /* doc */,
              Schema.createRecord(fields),
              Schema.create(Schema.Type.STRING),
              Schema.createUnion(new ArrayList<>()));
 protocol.getMessages().put("hello", message);
 Transceiver t
  = new SocketTransceiver(new InetSocketAddress(server.getPort()));
 try {
  GenericRequestor r = new GenericRequestor(protocol, t);
  GenericRecord params = new GenericData.Record(message.getRequest());
  params.put("extra", Boolean.TRUE);
  params.put("greeting", new Utf8("bob"));
  Utf8 response = (Utf8)r.request("hello", params);
  assertEquals(new Utf8("goodbye"), response);
 } finally {
  t.close();
 }
}

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

record.setFields(fields);
Protocol protocol = new Protocol("Simple", "org.apache.avro.test");
List<Field> params = new ArrayList<>();
params.add(new Field("record", record, null, null));

代码示例来源: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: 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.cassandra.deps/avro

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse(Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

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

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse(Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

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

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse(Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

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

private static Protocol parse(JsonParser parser) {
 try {
  Protocol protocol = new Protocol();
  protocol.parse(Schema.MAPPER.readTree(parser));
  return protocol;
 } catch (IOException e) {
  throw new SchemaParseException(e);
 }
}

相关文章