Package org.apache.avro

Examples of org.apache.avro.Protocol$TwoWayMessage


  }

  /** 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) {
View Full Code Here


   * 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;
  }
View Full Code Here

  }

  /** 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) {
View Full Code Here

   * 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;
  }
View Full Code Here

   * @param srcFiles the source Avro protocol files
   * @param dest the directory to place generated files in
   */
  public static void compileProtocol(File[] srcFiles, File dest) throws IOException {
    for (File src : srcFiles) {
      Protocol protocol = Protocol.parse(src);
      SpecificCompiler compiler = new SpecificCompiler(protocol);
      compiler.compileToDestination(src, dest);
    }
  }
View Full Code Here

  // annotate map and string schemas with string type
  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<Schema,Schema>();

    // Copy properties
    for (Map.Entry<String,JsonNode> prop : p.getJsonProps().entrySet())
      newP.addProp(prop.getKey(), prop.getValue());   // copy props

    // annotate types
    Collection<Schema> namedTypes = new LinkedHashSet<Schema>();
    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.getName(), m.getDoc(), m.getJsonProps(),
                                    addStringType(m.getRequest(), types))
               : newP.createMessage(m.getName(), m.getDoc(), m.getJsonProps(),
                                    addStringType(m.getRequest(), types),
                                    addStringType(m.getResponse(), types),
                                    addStringType(m.getErrors(), types)));
    return newP;
  }
View Full Code Here

/**
* The input to Idl is a CompilationUnit, which is currently
* just a single Protocol.
*/
  final public Protocol CompilationUnit() throws ParseException {
  Protocol p;
    p = ProtocolDeclaration();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 65:
      jj_consume_token(65);
      break;
View Full Code Here

    throw new Error("Missing return statement in function");
  }

  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
       p.addProp(key, props.get(key));
     }
    ProtocolBody(p);
   {if (true) return p;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here

  }

  final public void ProtocolBody(Protocol p) throws ParseException {
  Schema schema;
  Message message;
  Protocol importProtocol;
  Map<String, JsonNode> props = new LinkedHashMap<String, JsonNode>();
    jj_consume_token(LBRACE);
    label_4:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case ARRAY:
      case BOOLEAN:
      case DOUBLE:
      case ENUM:
      case ERROR:
      case FIXED:
      case FLOAT:
      case IMPORT:
      case INT:
      case LONG:
      case MAP:
      case BYTES:
      case STRING:
      case NULL:
      case RECORD:
      case UNION:
      case VOID:
      case IDENTIFIER:
      case AT:
      case TICK:
        ;
        break;
      default:
        jj_la1[6] = jj_gen;
        break label_4;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IMPORT:
        jj_consume_token(IMPORT);
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case IDL:
        case PROTOCOL:
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case IDL:
            importProtocol = ImportIdl();
            break;
          case PROTOCOL:
            importProtocol = ImportProtocol();
            break;
          default:
            jj_la1[7] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
          }
       for (Schema s : importProtocol.getTypes())
         names.put(s.getFullName(), s);
       p.getMessages().putAll(importProtocol.getMessages());
          break;
        case SCHEMA:
          schema = ImportSchema();
          break;
        default:
View Full Code Here

/**
* The input to Idl is a CompilationUnit, which is currently
* just a single Protocol.
*/
  final public Protocol CompilationUnit() throws ParseException {
  Protocol p;
    p = ProtocolDeclaration();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 65:
      jj_consume_token(65);
      break;
View Full Code Here

TOP

Related Classes of org.apache.avro.Protocol$TwoWayMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.