Package org.apache.avro

Examples of org.apache.avro.Protocol


      URLClassLoader projPathLoader = new URLClassLoader
        (runtimeUrls, Thread.currentThread().getContextClassLoader());
        parser = new Idl(new File(sourceDirectory, filename), projPathLoader);
      }

      Protocol p = parser.CompilationUnit();
      String json = p.toString(true);
      Protocol protocol = Protocol.parse(json);
      SpecificCompiler compiler = new SpecificCompiler(protocol);
      compiler.setStringType(GenericData.StringType.valueOf(stringType));
      compiler.setTemplateDir(templateDirectory);
      compiler.setFieldVisibility(getFieldVisibility());
      compiler.setCreateSetters(createSetters);
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

  private SpecificCompiler() {}                        // no public ctor

  /** Returns generated Java interface for a protocol. */
  public static SpecificCompiler compileProtocol(File file) throws IOException {
    SpecificCompiler compiler = new SpecificCompiler();
    Protocol protocol = Protocol.parse(file);
    compiler.compile(protocol);
    return compiler;
  }
View Full Code Here

  /** Create a proxy instance whose methods invoke RPCs. */
  public static Object getClient(Class<?> iface, Transceiver transciever,
                                 SpecificData specificData)
    throws IOException {
    Protocol protocol = specificData.getProtocol(iface);
    return Proxy.newProxyInstance(iface.getClassLoader(),
                                  new Class[] { iface },
                                  new SpecificRequestor(protocol, transciever));
  }
View Full Code Here

      new ByteBufferOutputStream();
    Encoder out = new BinaryEncoder(bbo);
    AvroRemoteException error = null;
    RPCContext context = new RPCContext();
    try {
      Protocol remote = handshake(transceiver, in, out);
      if (remote == null)                        // handshake failed
        return bbo.getBufferList();

      // read request using remote protocol specification
      context.setRequestCallMeta(META_READER.read(null, in));
      String messageName = in.readString(null).toString();
      Message m = remote.getMessages().get(messageName);
      if (m == null)
        throw new AvroRuntimeException("No such remote message: "+messageName);
     
      Object request = readRequest(m.getRequest(), in);
     
View Full Code Here

  @SuppressWarnings("unchecked")
  private Protocol handshake(Transceiver transceiver,
                             Decoder in, Encoder out)
    throws IOException {
    Protocol remote = remotes.get(transceiver);
    if (remote != null) return remote;            // already established
     
    HandshakeRequest request = (HandshakeRequest)handshakeReader.read(null, in);
    remote = protocols.get(request.clientHash);
    if (remote == null && request.clientProtocol != null) {
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. </p>
   */
  public Protocol getProtocol(Class iface) {
    Protocol protocol =
      new Protocol(iface.getSimpleName(), iface.getPackage().getName());
    for (Method method : iface.getDeclaredMethods())
      if ((method.getModifiers() & Modifier.STATIC) == 0)
        protocol.getMessages().put(method.getName(),
                                   getMessage(method, protocol));

    // reverse types, since they were defined in reference order
    List<Map.Entry<String,Schema>> names =
      new ArrayList<Map.Entry<String,Schema>>();
    names.addAll(protocol.getTypes().entrySet());
    Collections.reverse(names);
    protocol.getTypes().clear();
    for (Map.Entry<String,Schema> name : names)
      protocol.getTypes().put(name.getKey(), name.getValue());

    return protocol;
  }
View Full Code Here

  }

  /** Create a proxy instance whose methods invoke RPCs. */
  public static Object getClient(Class<?> iface, Transceiver transciever, ReflectData reflectData)
    throws IOException {
    Protocol protocol = reflectData.getProtocol(iface);
    return Proxy.newProxyInstance(iface.getClassLoader(),
                                  new Class[] { iface },
                                  new ReflectRequestor(protocol, transciever));
  }
View Full Code Here

   * @param src the source Avro protocol file
   * @param dest the directory to place generated files in
   */
  public static void compileProtocol(File src, File dest) throws IOException {
    GoraCompiler compiler = new GoraCompiler(dest);
    Protocol protocol = Protocol.parse(src);
    for (Schema s : protocol.getTypes())          // enqueue types
      compiler.enqueue(s);
    compiler.compileInterface(protocol);          // generate interface
    compiler.compile();                           // generate classes for types
  }
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.