@Override public List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException { return responder.respond(request); }
boolean wasConnected = connection != null && connection.isConnected(); try { Protocol remote = handshake(in, out, connection); out.flush(); if (remote == null) // handshake failed if (rm == null) throw new AvroRuntimeException("No such remote message: "+messageName); Message m = getLocal().getMessages().get(messageName); if (m == null) throw new AvroRuntimeException("No message named "+messageName +" in "+getLocal()); Object request = readRequest(rm.getRequest(), m.getRequest(), in); response = respond(m, request); context.setResponse(response); } catch (Exception e) { writeResponse(m.getResponse(), response, out); else try { writeError(m.getErrors(), error, out); } catch (UnresolvedUnionException e) { // unexpected error throw error; out = EncoderFactory.get().binaryEncoder(bbo, null); out.writeBoolean(true); writeError(Protocol.SYSTEM_ERRORS, new Utf8(e.toString()), out);
/** Starts an Avro server. */ private static HttpServer createServer(boolean withPlugin) throws IOException { Responder r = new IdentityResponder(NULL_PROTOCOL); if (withPlugin) { r.addRPCPlugin(new StatsPlugin()); } // Start Avro server HttpServer server = new HttpServer(r, 0); server.start(); return server; }
RPCContext context = new RPCContext(); try { Protocol remote = handshake(in, out); if (remote == null) // handshake failed return bbo.getBufferList(); Object request = readRequest(m.getRequest(), in); m = getLocal().getMessages().get(messageName); if (m == null) throw new AvroRuntimeException("No message named "+messageName +" in "+getLocal()); Object response = null; try { response = respond(m, request); context.setResponse(response); } catch (Exception e) { out.writeBoolean(error != null); if (error == null) writeResponse(m.getResponse(), response, out); else writeError(m.getErrors(), error, out); META_WRITER.write(context.responseCallMeta(), out); out.writeBoolean(true); writeError(Protocol.SYSTEM_ERRORS, new Utf8(e.toString()), out);
@Before @Override public void testStartServer() throws Exception { if (server != null) return; Responder responder = new TestResponder(); responder.addRPCPlugin(new RPCMetaTestPlugin("key1")); responder.addRPCPlugin(new RPCMetaTestPlugin("key2")); server = new SocketServer(responder, new InetSocketAddress(0)); server.start(); client = new SocketTransceiver(new InetSocketAddress(server.getPort())); requestor = new GenericRequestor(PROTOCOL, client); requestor.addRPCPlugin(new RPCMetaTestPlugin("key1")); requestor.addRPCPlugin(new RPCMetaTestPlugin("key2")); } }
boolean wasConnected = connection != null && connection.isConnected(); try { Protocol remote = handshake(in, out, connection); out.flush(); if (remote == null) // handshake failed if (rm == null) throw new AvroRuntimeException("No such remote message: "+messageName); Message m = getLocal().getMessages().get(messageName); if (m == null) throw new AvroRuntimeException("No message named "+messageName +" in "+getLocal()); Object request = readRequest(rm.getRequest(), m.getRequest(), in); response = respond(m, request); context.setResponse(response); } catch (Exception e) { writeResponse(m.getResponse(), response, out); else try { writeError(m.getErrors(), error, out); } catch (UnresolvedUnionException e) { // unexpected error throw error; out = EncoderFactory.get().binaryEncoder(bbo, null); out.writeBoolean(true); writeError(Protocol.SYSTEM_ERRORS, new Utf8(e.toString()), out);
/** Called by a server to deserialize a request, compute and serialize * a response or error. */ public List<ByteBuffer> respond(List<ByteBuffer> buffers) throws IOException { return respond(buffers, null); }
Responder r = new SleepyResponder(protocol); StatsPlugin p = new StatsPlugin(); r.addRPCPlugin(p);
boolean wasConnected = connection != null && connection.isConnected(); try { Protocol remote = handshake(in, out, connection); if (remote == null) // handshake failed return bbo.getBufferList(); Object request = readRequest(rm.getRequest(), in); Message m = getLocal().getMessages().get(messageName); if (m == null) throw new AvroRuntimeException("No message named "+messageName +" in "+getLocal()); if (m.isOneWay() != rm.isOneWay()) throw new AvroRuntimeException("Not both one-way: "+messageName); response = respond(m, request); context.setResponse(response); } catch (Exception e) { writeResponse(m.getResponse(), response, out); else writeError(m.getErrors(), error, out); } catch (Exception e) { // system error LOG.warn("system error", e); out = new BinaryEncoder(bbo); out.writeBoolean(true); writeError(Protocol.SYSTEM_ERRORS, new Utf8(e.toString()), out);
public void run() { while (true) { try { transceiver.writeBuffers(responder.respond(transceiver.readBuffers())); } catch (ClosedChannelException e) { return; } catch (IOException e) { LOG.warn("unexpected error", e); throw new RuntimeException(e); } } }
@Test public void testFullServerPath() throws IOException { Responder r = new TestResponder(protocol); StatsPlugin statsPlugin = new StatsPlugin(); r.addRPCPlugin(statsPlugin); Transceiver t = new LocalTransceiver(r); for (int i = 0; i < 10; ++i) { makeRequest(t); } String o = generateServletResponse(statsPlugin); assertTrue(o.contains("10 calls")); }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType(HttpTransceiver.CONTENT_TYPE); List<ByteBuffer> requestBufs = HttpTransceiver.readBuffers(request.getInputStream()); try { List<ByteBuffer> responseBufs = responder.respond(requestBufs); response.setContentLength(HttpTransceiver.getLength(responseBufs)); HttpTransceiver.writeBuffers(responseBufs, response.getOutputStream()); } catch (AvroRuntimeException e) { throw new ServletException(e); } } }
@Test public void testPayloadSize() throws IOException { Responder r = new TestResponder(protocol); StatsPlugin statsPlugin = new StatsPlugin(); r.addRPCPlugin(statsPlugin); Transceiver t = new LocalTransceiver(r); makeRequest(t); String resp = generateServletResponse(statsPlugin); assertTrue(resp.contains("Average: 2.0")); }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { try { NettyDataPack dataPack = (NettyDataPack) e.getMessage(); List<ByteBuffer> req = dataPack.getDatas(); List<ByteBuffer> res = responder.respond(req, connectionMetadata); // response will be null for oneway messages. if(res != null) { dataPack.setDatas(res); e.getChannel().write(dataPack); } } catch (IOException ex) { LOG.warn("unexpected error"); } }
public void run() { try { try { this.xc = getTransceiver(channel); while (true) { xc.writeBuffers(responder.respond(xc.readBuffers(), xc)); } } catch (EOFException e) { return; } catch (ClosedChannelException e) { return; } finally { xc.close(); } } catch (IOException e) { LOG.warn("unexpected error", e); } }
@Override public List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException { return responder.respond(request); }
@Override public List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException { return responder.respond(request); }
/** Called by a server to deserialize a request, compute and serialize * a response or error. */ public List<ByteBuffer> respond(List<ByteBuffer> buffers) throws IOException { return respond(buffers, null); }
/** Called by a server to deserialize a request, compute and serialize * a response or error. */ public List<ByteBuffer> respond(List<ByteBuffer> buffers) throws IOException { return respond(buffers, null); }
@Override public List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException { return responder.respond(request); }