public ReflectRequestor(Class<?> iface, Transceiver transceiver, ReflectData data) throws IOException { this(data.getProtocol(iface), transceiver, data); }
public ReflectResponder(Class iface, Object impl, ReflectData data) { this(data.getProtocol(iface), impl, data); }
/** Create a proxy instance whose methods invoke RPCs. */ @SuppressWarnings("unchecked") public static <T> T getClient(Class<T> iface, Transceiver transceiver, ReflectData reflectData) throws IOException { Protocol protocol = reflectData.getProtocol(iface); return (T)Proxy.newProxyInstance (reflectData.getClassLoader(), new Class[] { iface }, new ReflectRequestor(protocol, transceiver, reflectData)); }
System.out.println(ReflectData.get().getProtocol(klass).toString(true)); } else { System.out.println(ReflectData.get().getSchema(klass).toString(true));
public void execute() throws MojoExecutionException { ClassLoader classLoader = getClassLoader(); for(File inputFile : sourceDirectory.listFiles()) { String className = parseClassName(inputFile.getPath()); Class<?> klass = loadClass(classLoader, className); String fileName = outputDirectory.getPath() + "/" + parseFileName(klass); File outputFile = new File(fileName); outputFile.getParentFile().mkdirs(); try { PrintWriter writer = new PrintWriter(fileName, "UTF-8"); if(klass.isInterface()) { writer.println(ReflectData.get().getProtocol(klass).toString(true)); } else { writer.println(ReflectData.get().getSchema(klass).toString(true)); } writer.close(); } catch(Exception e) { e.printStackTrace(); } } }
@Test public void testNoPackageProtocol() throws Exception { ReflectData.get().getProtocol(Class.forName("NoPackage")); }
@Test(expected=AvroTypeException.class) public void testOverloadedMethod() { ReflectData.get().getProtocol(P3.class); }
@Test public void testP4() throws Exception { Protocol p = ReflectData.get().getProtocol(P4.class); Protocol.Message message = p.getMessages().get("foo"); assertEquals(Schema.Type.INT, message.getResponse().getType()); Field field = message.getRequest().getField("x"); assertEquals(Schema.Type.INT, field.schema().getType()); }
@Test public void testP2() throws Exception { Schema e1 = ReflectData.get().getSchema(E1.class); assertEquals(Schema.Type.RECORD, e1.getType()); assertTrue(e1.isError()); Field message = e1.getField("detailMessage"); assertNotNull("field 'detailMessage' should not be null", message); Schema messageSchema = message.schema(); assertEquals(Schema.Type.UNION, messageSchema.getType()); assertEquals(Schema.Type.NULL, messageSchema.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, messageSchema.getTypes().get(1).getType()); Protocol p2 = ReflectData.get().getProtocol(P2.class); Protocol.Message m = p2.getMessages().get("error"); // check error schema is union Schema response = m.getErrors(); assertEquals(Schema.Type.UNION, response.getType()); assertEquals(Schema.Type.STRING, response.getTypes().get(0).getType()); assertEquals(e1, response.getTypes().get(1)); }
@Test public void testP1() throws Exception { Protocol p1 = ReflectData.get().getProtocol(P1.class); Protocol.Message message = p1.getMessages().get("foo"); // check response schema is union Schema response = message.getResponse(); assertEquals(Schema.Type.UNION, response.getType()); assertEquals(Schema.Type.NULL, response.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, response.getTypes().get(1).getType()); // check request schema is union Schema request = message.getRequest(); Field field = request.getField("s"); assertNotNull("field 's' should not be null", field); Schema param = field.schema(); assertEquals(Schema.Type.UNION, param.getType()); assertEquals(Schema.Type.NULL, param.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, param.getTypes().get(1).getType()); // check union erasure assertEquals(String.class, ReflectData.get().getClass(response)); assertEquals(String.class, ReflectData.get().getClass(param)); }
@Test public void testP0() throws Exception { Protocol p0 = ReflectData.get().getProtocol(P0.class); Protocol.Message message = p0.getMessages().get("foo"); // check response schema is union Schema response = message.getResponse(); assertEquals(Schema.Type.UNION, response.getType()); assertEquals(Schema.Type.NULL, response.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, response.getTypes().get(1).getType()); // check request schema is union Schema request = message.getRequest(); Field field = request.getField("s"); assertNotNull("field 's' should not be null", field); Schema param = field.schema(); assertEquals(Schema.Type.UNION, param.getType()); assertEquals(Schema.Type.NULL, param.getTypes().get(0).getType()); assertEquals(Schema.Type.STRING, param.getTypes().get(1).getType()); // check union erasure assertEquals(String.class, ReflectData.get().getClass(response)); assertEquals(String.class, ReflectData.get().getClass(param)); }
@Test public void testForwardReference() { ReflectData data = ReflectData.get(); Protocol reflected = data.getProtocol(C.class); Protocol reparsed = Protocol.parse(reflected.toString()); assertEquals(reflected, reparsed); assert(reparsed.getTypes().contains(data.getSchema(A.class))); assert(reparsed.getTypes().contains(data.getSchema(B1.class))); assert(reparsed.getTypes().contains(data.getSchema(B2.class))); assert(reparsed.getTypes().contains(data.getSchema(X.class))); }
public ReflectResponder(Class iface, Object impl, ReflectData data) { this(data.getProtocol(iface), impl, data); }
public ReflectRequestor(Class<?> iface, Transceiver transceiver, ReflectData data) throws IOException { this(data.getProtocol(iface), transceiver, data); }
public ReflectRequestor(Class<?> iface, Transceiver transceiver) throws IOException { this(ReflectData.get().getProtocol(iface), transceiver); }
/** 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)); }
/** 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)); }
public ReflectRequestor(Class<?> iface, Transceiver transceiver) throws IOException { this(ReflectData.get().getProtocol(iface), transceiver); }
/** 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 (reflectData.getClassLoader(), new Class[] { iface }, new ReflectRequestor(protocol, transciever, reflectData)); }
public ReflectResponder(Class iface, Object impl) { super(ReflectData.get().getProtocol(iface), impl, ReflectData.get()); }