@Override public Object respond(Message message, Object request) throws Exception { int numParams = message.getRequest().getFields().size(); Object[] params = new Object[numParams]; Class[] paramTypes = new Class[numParams]; int i = 0; try { for (Schema.Field param: message.getRequest().getFields()) { params[i] = ((GenericRecord)request).get(param.name()); paramTypes[i] = getSpecificData().getClass(param.schema()); i++; } Method method = impl.getClass().getMethod(message.getName(), paramTypes); method.setAccessible(true); return method.invoke(impl, params); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof Exception) { throw (Exception) e.getTargetException(); } else { throw new Exception(e.getTargetException()); } } catch (NoSuchMethodException e) { throw new AvroRuntimeException(e); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
private RenderableMessage renderMethod(Message message) { RenderableMessage out = new RenderableMessage(message.getName());
@Override public Object respond(Message message, Object request) throws Exception { int numParams = message.getRequest().getFields().size(); Object[] params = new Object[numParams]; Class[] paramTypes = new Class[numParams]; int i = 0; try { for (Schema.Field param: message.getRequest().getFields()) { params[i] = ((GenericRecord)request).get(param.name()); paramTypes[i] = getSpecificData().getClass(param.schema()); i++; } Method method = impl.getClass().getMethod(message.getName(), paramTypes); method.setAccessible(true); return method.invoke(impl, params); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof Exception) { throw (Exception) e.getTargetException(); } else { throw new Exception(e.getTargetException()); } } catch (NoSuchMethodException e) { throw new AvroRuntimeException(e); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
private void writeMethod(Writer w, Message message, FloatHistogram<?> hist) throws IOException { w.append("<h3>").append(message.getName()).append("</h3>"); w.append("<p>Number of calls: "); w.append(Integer.toString(hist.getCount())); w.append("</p><p>Average Duration: "); w.append(formatMillis(hist.getMean())); w.append("</p>"); w.append("</p><p>Std Dev: "); w.append(formatMillis(hist.getUnbiasedStdDev())); w.append("</p>"); w.append("<dl>"); for (Histogram.Entry<?> e : hist.entries()) { w.append("<dt>"); w.append(e.bucket.toString()); w.append("</dt>"); w.append("<dd>").append(Integer.toString(e.count)).append("</dd>"); w.append("</dt>"); } w.append("</dl>"); }
@Override public Object respond(Message message, Object request) throws Exception { Class[] paramTypes = new Class[message.getRequest().getFields().size()]; int i = 0; try { for (Schema.Field param: message.getRequest().getFields()) paramTypes[i++] = data.getClass(param.schema()); Method method = impl.getClass().getMethod(message.getName(), paramTypes); method.setAccessible(true); return method.invoke(impl, (Object[])request); } catch (InvocationTargetException e) { throw (Exception)e.getTargetException(); } catch (NoSuchMethodException e) { throw new AvroRuntimeException(e); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
@Override public Object respond(Message message, Object request) throws Exception { Class[] paramTypes = new Class[message.getRequest().getFields().size()]; int i = 0; try { for (Schema.Field param: message.getRequest().getFields()) paramTypes[i++] = data.getClass(param.schema()); Method method = impl.getClass().getMethod(message.getName(), paramTypes); return method.invoke(impl, (Object[])request); } catch (InvocationTargetException e) { throw (Exception)e.getTargetException(); } catch (NoSuchMethodException e) { throw new AvroRuntimeException(e); } catch (IllegalAccessException e) { throw new AvroRuntimeException(e); } }
private void writeActiveRpc(Writer w, RPCContext rpc, Stopwatch stopwatch) throws IOException { w.append("<li>").append(rpc.getMessage().getName()).append(": "); w.append(formatMillis(StatsPlugin.nanosToMillis(stopwatch.elapsedNanos()))); w.append("</li>"); }
@Override public void serverReceiveRequest(RPCContext context) { if (this.currentSpan.get() != null) { Span current = this.currentSpan.get(); Util.addEvent(current, SpanEvent.SERVER_RECV); current.messageName = new Utf8( context.getMessage().getName()); current.requestPayloadSize = Util.getPayloadSize( context.getRequestPayload()); } }
private String renderActiveRpc(RPCContext rpc, Stopwatch stopwatch) throws IOException { String out = new String(); out += rpc.getMessage().getName() + ": " + formatMillis(StatsPlugin.nanosToMillis(stopwatch.elapsedNanos())); return out; }
@Override public void clientSendRequest(RPCContext context) { if (this.childSpan.get() != null) { Span child = this.childSpan.get(); Util.addEvent(child, SpanEvent.CLIENT_SEND); child.messageName = new Utf8( context.getMessage().getName()); child.requestPayloadSize = Util.getPayloadSize( context.getRequestPayload()); } }
private String renderActiveRpc(RPCContext rpc, Stopwatch stopwatch) throws IOException { String out = new String(); out += rpc.getMessage().getName() + ": " + formatMillis(StatsPlugin.nanosToMillis(stopwatch.elapsedNanos())); return out; }
case TICK: message = MessageDeclaration(p, props); p.getMessages().put(message.getName(), message); break; default:
Object response = client.request(message.getName(), datum); dumpJson(out, message.getResponse(), response); return 0;
if (value.isOneWay()) { Schema replacement = resolve(replacements, value.getRequest(), protocol); nvalue = result.createMessage(value.getName(), value.getDoc(), value, replacement); } else { Schema response = resolve(replacements, value.getResponse(), protocol); Schema errors = resolve(replacements, value.getErrors(), protocol); nvalue = result.createMessage(value.getName(), value.getDoc(), value, request, response, errors);
/** * Gets the request data, generating it first if necessary. * @return the request data. * @throws Exception if an error occurs generating the request data. */ public List<ByteBuffer> getBytes() throws Exception { if (requestBytes == null) { ByteBufferOutputStream bbo = new ByteBufferOutputStream(); BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(bbo, encoder); // use local protocol to write request Message m = getMessage(); context.setMessage(m); writeRequest(m.getRequest(), request, out); // write request payload out.flush(); List<ByteBuffer> payload = bbo.getBufferList(); writeHandshake(out); // prepend handshake if needed context.setRequestPayload(payload); for (RPCPlugin plugin : rpcMetaPlugins) { plugin.clientSendRequest(context); // get meta-data from plugins } META_WRITER.write(context.requestCallMeta(), out); out.writeString(m.getName()); // write message name out.flush(); bbo.append(payload); requestBytes = bbo.getBufferList(); } return requestBytes; } }
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; }
public Object respond(Message message, Object request) throws AvroRemoteException { GenericRecord params = (GenericRecord)request; if ("hello".equals(message.getName())) { LOG.info("hello: "+params.get("greeting")); return new Utf8("goodbye"); } if ("echo".equals(message.getName())) { Object record = params.get("record"); LOG.info("echo: "+record); return record; } if ("echoBytes".equals(message.getName())) { Object data = params.get("data"); LOG.info("echoBytes: "+data); return data; } if ("error".equals(message.getName())) { if (throwUndeclaredError) throw new RuntimeException("foo"); GenericRecord error = new GenericData.Record(PROTOCOL.getType("TestError")); error.put("message", new Utf8("an error")); throw new AvroRemoteException(error); } throw new AvroRuntimeException("unexpected message: "+message.getName()); }
/** Create a two-way message using the {@code name}, {@code doc}, and {@code props} of {@code m}. */ public Message createMessage(Message m, Schema request, Schema response, Schema errors) { return new TwoWayMessage(m.getName(), m.getDoc(), m, request, response, errors); }
private String renderActiveRpc(RPCContext rpc, Stopwatch stopwatch) throws IOException { String out = new String(); out += rpc.getMessage().getName() + ": " + formatMillis(StatsPlugin.nanosToMillis(stopwatch.elapsedNanos())); return out; }