Package org.apache.avro

Examples of org.apache.avro.Protocol


  /** Create a proxy instance whose methods invoke RPCs. */
  @SuppressWarnings("unchecked")
  public static <T> T getClient(Class<T> iface, Transceiver transciever,
                                ReflectData reflectData) throws IOException {
    Protocol protocol = reflectData.getProtocol(iface);
    return (T)Proxy.newProxyInstance(iface.getClassLoader(),
                                  new Class[] { iface },
                                  new ReflectRequestor(protocol, transciever));
  }
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

      this.expectedOut = expectedOut;
    }

    private String generate() throws Exception {
      Idl parser = new Idl(in);
      Protocol p = parser.CompilationUnit();
      return p.toString(true);
    }
View Full Code Here

   */
  public static void main(String[] args) throws Exception {
    if (args.length == 0) {
      args = new String[] { "7002", "7003" };
    }
    Protocol protocol = Protocol.parse("{\"protocol\": \"sleepy\", "
        + "\"messages\": { \"sleep\": {"
        + "   \"request\": [{\"name\": \"millis\", \"type\": \"long\"}," +
          "{\"name\": \"data\", \"type\": \"bytes\"}], "
        + "   \"response\": \"null\"} } }");
    Log.info("Using protocol: " + protocol.toString());
    Responder r = new SleepyResponder(protocol);
    StatsPlugin p = new StatsPlugin();
    r.addRPCPlugin(p);

    // Start Avro server
    HttpServer avroServer = new HttpServer(r, Integer.parseInt(args[0]));
    avroServer.start();

    StatsServer ss = new StatsServer(p, 8080);
   
    HttpTransceiver trans = new HttpTransceiver(
        new URL("http://localhost:" + Integer.parseInt(args[0])));
    GenericRequestor req = new GenericRequestor(protocol, trans);

    while(true) {
      Thread.sleep(1000);
      GenericRecord params = new GenericData.Record(protocol.getMessages().get(
        "sleep").getRequest());
      Random rand = new Random();
      params.put("millis", Math.abs(rand.nextLong()) % 1000);
      int payloadSize = Math.abs(rand.nextInt()) % 10000;
      byte[] payload = new byte[payloadSize];
View Full Code Here

  @Override
  protected void doCompile(String filename, File sourceDirectory, File outputDirectory) throws IOException {
    Idl parser = new Idl(new File(sourceDirectory, filename));
    try {
      Protocol p = parser.CompilationUnit();
      String json = p.toString(true);
      Protocol protocol = Protocol.parse(json);
      SpecificCompiler compiler = new SpecificCompiler(protocol);
      compiler.compileToDestination(null, outputDirectory);
    } catch (ParseException e) {
      throw new IOException(e);
    }
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 if (props.get(key).isTextual()) {     // ignore other non-textual
       p.addProp(key, getTextProp(key, props, token));
     }
    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

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

TOP

Related Classes of org.apache.avro.Protocol

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.